Skip to content

Unitary

A unitary operator extracted from a quantum circuit. The resulting matrix U satisfies UU=I and represents the full unitary transformation implemented by the circuit.

Signature

python
Unitary(
    qcircuit: QCircuit,
    system_type: StateSystemType = StateSystemType.Q2Q1Q0,
)

Parameters

ParameterTypeDescription
qcircuitQCircuitThe quantum circuit whose unitary matrix is computed.
system_typeStateSystemTypeThe 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.ndarray

Return the unitary matrix as a 2-D numpy.ndarray.

Operators

Equality

python
u_a == u_b -> bool

Return 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]]

See Also

Released under the MIT License.