PauliWithQbit
PauliWithQbit represents a single Pauli matrix (PauliTerm is composed of a collection of PauliWithQbit instances, one per qubit.
Methods
qbit
PauliWithQbit.qbit() -> intReturns the qubit index that this Pauli matrix acts on.
Returns: An integer qubit index.
is_I
PauliWithQbit.is_I() -> boolReturns True if this Pauli is the identity matrix
Returns: A boolean.
is_X
PauliWithQbit.is_X() -> boolReturns True if this Pauli is the
Returns: A boolean.
is_Y
PauliWithQbit.is_Y() -> boolReturns True if this Pauli is the
Returns: A boolean.
is_Z
PauliWithQbit.is_Z() -> boolReturns True if this Pauli is the
Returns: A boolean.
to_qgate
PauliWithQbit.to_qgate() -> QGateConverts this Pauli into the corresponding quantum gate object. The mapping is:
| Pauli | Gate |
|---|---|
| Identity (no-op) | |
| X gate | |
| Y gate | |
| Z gate |
Returns: A QGate applied to the qubit at index qbit().
pauli_char
PauliWithQbit.pauli_char() -> strReturns a single-character string identifying the Pauli type: "I", "X", "Y", or "Z".
Returns: A one-character string.
Examples
Inspect Paulis in a term
from pyqpanda3.hamiltonian import PauliOperator
h = PauliOperator({"X0 Y1 Z2": 1.0})
term = h.terms()[0]
for pwq in term.paulis():
print(f"Qubit {pwq.qbit()}: {pwq.pauli_char()}")
print(f" is_X: {pwq.is_X()}, is_Y: {pwq.is_Y()}, is_Z: {pwq.is_Z()}, is_I: {pwq.is_I()}")Convert a Pauli to a quantum gate
from pyqpanda3.hamiltonian import PauliOperator
h = PauliOperator({"X0 Z1": 1.0})
term = h.terms()[0]
for pwq in term.paulis():
if not pwq.is_I():
gate = pwq.to_qgate()
print(f"Gate on qubit {pwq.qbit()}: {gate}")See Also
- PauliTerm -- A collection of PauliWithQbit instances forming a single term
- PauliOperator -- Multi-term Pauli operator containing PauliTerms
- Hamiltonian -- Higher-level Hamiltonian wrapper