Unitary
A unitary operator extracted from a quantum circuit. The resulting matrix
Signature
python
Unitary(
qcircuit: QCircuit,
system_type: StateSystemType = StateSystemType.Q2Q1Q0,
)Parameters
| Parameter | Type | Description |
|---|---|---|
| qcircuit | QCircuit | The quantum circuit whose unitary matrix is computed. |
| system_type | StateSystemType | The qubit ordering convention. Q2Q1Q0 means that for the binary state 10, qubit 1 is 1 and qubit 0 is 0. Defaults to Q2Q1Q0. |
Methods
ndarray
python
ndarray() -> numpy.ndarrayReturn the unitary matrix as a 2-D numpy.ndarray.
Operators
Equality
python
u_a == u_b -> boolReturn True if the two Unitary objects have identical internal data.
Examples
python
from pyqpanda3.core import QCircuit, H, CNOT
from pyqpanda3.quantum_info import Unitary
# Build a Bell circuit
qc = QCircuit()
qc << H(0)
qc << CNOT(0, 1)
# Extract the unitary matrix
u = Unitary(qc)
print(u.ndarray())
# [[ 0.707+0.j, 0.707+0.j, 0+0.j, 0+0.j],
# [ 0+0.j, 0+0.j, 0.707+0.j, -0.707+0.j],
# [ 0+0.j, 0+0.j, 0.707+0.j, 0.707+0.j],
# [ 0.707+0.j, -0.707+0.j, 0+0.j, 0+0.j]]