Unitary of qlasskit function

In qlasskit, we can exploit external low-level frameworks to perform operations on the resulting quantum circuit. In this example, we use qiskit in order to obtain the unitary matrix of our QlassF function.

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit.visualization import array_to_latex
from qlasskit import qlassf


@qlassf
def f(a: bool, b: bool) -> bool:
    return a ^ (not b)


print(f"\n{f}\n")

qc = QuantumCircuit(f.num_qubits, f.num_qubits)
qc.append(f.gate(), f.qubits)

qc.save_state()
qc.decompose().draw("mpl")
QlassF<f>(a:bool, b:bool) -> bool:
	_ret = a ^ ~b
_images/c7d04b10d56938794e94628eaa66357bee167db80983c3bb53291d7d04661f70.png
simulator = AerSimulator(method="unitary")
circ = transpile(qc, simulator)
result = simulator.run(circ).result()
array_to_latex(result.get_unitary(circ, 3), max_size=16)
\[\begin{split}\begin{bmatrix} 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ \end{bmatrix} \end{split}\]