uniqc.simulator.qutip_sim_impl module
QuTiP-backed density matrix simulator implementation.
This module provides a density-matrix quantum simulator implementation using
QuTiP, supporting unitary operations, Kraus channels, and measurement for
noisy quantum simulation.
- Key exports:
-
-
class uniqc.simulator.qutip_sim_impl.DensityOperatorSimulatorQutip[source]
Bases: object
Density-matrix simulator backed by QuTiP.
-
amplitude_damping(qubit, gamma)[source]
Apply amplitude damping noise.
- Parameters:
-
- Return type:
None
-
bitflip(qubit, p)[source]
Apply bit-flip (X) noise.
- Parameters:
-
- Return type:
None
-
cnot(control_qubit, target_qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the CNOT (controlled-NOT) gate.
- Parameters:
control_qubit (int) – Control qubit index.
target_qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Additional control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
cswap(control_qubit, q1, q2, control_qubits_set=None, is_dagger=False)[source]
Apply the CSWAP (Fredkin) gate.
- Parameters:
control_qubit (int) – Control qubit index.
q1 (int) – First target qubit index.
q2 (int) – Second target qubit index.
control_qubits_set (list[int] | None) – Additional control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
cz(qubit1, qubit2, control_qubits_set=None, is_dagger=False)[source]
Apply the CZ (controlled-Z) gate.
- Parameters:
qubit1 (int) – First qubit index.
qubit2 (int) – Second qubit index.
control_qubits_set (list[int] | None) – Additional control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
density_matrix: Qobj | None
-
depolarizing(qubit, p)[source]
Apply depolarizing noise to a single qubit.
- Parameters:
-
- Return type:
None
-
hadamard(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the Hadamard gate.
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
init_n_qubit(n)[source]
Initialize the simulator with n qubits in the |0...0> state.
- Parameters:
n (int)
- Return type:
None
-
iswap(q1, q2, control_qubits_set=None, is_dagger=False)[source]
Apply the iSWAP gate.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
kraus1q(qubit, parameters)[source]
Apply single-qubit Kraus noise.
- Parameters:
-
- Return type:
None
-
kraus2q(q1, q2, parameters)[source]
Apply two-qubit Kraus noise.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
parameters (list[list[float]]) – List of Kraus operator matrix elements (flattened 4x4).
- Return type:
None
-
n_qubits: int
-
pauli_error_1q(qubit, px, py, pz)[source]
Apply single-qubit Pauli error.
- Parameters:
qubit (int) – Target qubit index.
px (float) – Probability of X error.
py (float) – Probability of Y error.
pz (float) – Probability of Z error.
- Return type:
None
-
pauli_error_2q(q1, q2, parameters)[source]
Two-qubit Pauli error with 15 independent probabilities.
- Parameters:
-
- Return type:
None
-
phase2q(q1, q2, theta1, theta2, theta3, control_qubits_set=None, is_dagger=False)[source]
Phase2Q gate: u1(q1, theta1), u1(q2, theta2), zz(q1, q2, theta3).
- Parameters:
-
- Return type:
None
-
phaseflip(qubit, prob)[source]
Apply phase-flip (Z) noise.
- Parameters:
-
- Return type:
None
-
pmeasure(measure_qubits)[source]
Compute measurement probabilities for the given qubits.
- Parameters:
measure_qubits (list[int])
- Return type:
list[float]
-
rphi(qubit, theta, phi, control_qubits_set=None, is_dagger=False)[source]
Apply the RPhi gate (rotation around axis in XY plane).
- Parameters:
qubit (int) – Target qubit index.
theta (float) – Polar angle in radians.
phi (float) – Azimuthal angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
rphi180(qubit, phi, control_qubits_set=None, is_dagger=False)[source]
Apply the RPhi180 gate (π rotation around axis in XY plane).
- Parameters:
qubit (int) – Target qubit index.
phi (float) – Azimuthal angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
rphi90(qubit, phi, control_qubits_set=None, is_dagger=False)[source]
Apply the RPhi90 gate (π/2 rotation around axis in XY plane).
- Parameters:
qubit (int) – Target qubit index.
phi (float) – Azimuthal angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
rx(qubit, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the RX gate.
- Parameters:
qubit (int) – Target qubit index.
theta (float) – Rotation angle in radians.
control_qubits_set (list[int] | None) – Control qubits for controlled rotation.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
ry(qubit, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the RY gate.
- Parameters:
qubit (int) – Target qubit index.
theta (float) – Rotation angle in radians.
control_qubits_set (list[int] | None) – Control qubits for controlled rotation.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
rz(qubit, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the RZ gate.
- Parameters:
qubit (int) – Target qubit index.
theta (float) – Rotation angle in radians.
control_qubits_set (list[int] | None) – Control qubits for controlled rotation.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
s(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the S gate (phase gate, π/2).
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
property state: ndarray
Return the density matrix as a NumPy array.
-
stateprob()[source]
Return the diagonal of the density matrix (state probabilities).
- Return type:
ndarray
-
swap(qubit1, qubit2, control_qubits_set=None, is_dagger=False)[source]
Apply the SWAP gate.
- Parameters:
qubit1 (int) – First qubit index.
qubit2 (int) – Second qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
sx(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the SX (square-root of X) gate.
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
t(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the T gate (π/4 phase gate).
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
toffoli(c1, c2, target, control_qubits_set=None, is_dagger=False)[source]
Apply the Toffoli (CCNOT) gate.
- Parameters:
c1 (int) – First control qubit index.
c2 (int) – Second control qubit index.
target (int) – Target qubit index.
control_qubits_set (list[int] | None) – Additional control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
twoqubit_depolarizing(q1, q2, p)[source]
Apply two-qubit depolarizing noise.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
p (float) – Depolarizing probability.
- Return type:
None
-
u1(qubit, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the U1 gate.
- Parameters:
qubit (int) – Target qubit index.
theta (float) – Phase angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
u2(qubit, phi, lam, control_qubits_set=None, is_dagger=False)[source]
Apply the U2 gate.
- Parameters:
qubit (int) – Target qubit index.
phi (float) – First phase angle in radians.
lam (float) – Second phase angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
u3(qubit, theta, phi, lam, control_qubits_set=None, is_dagger=False)[source]
Apply the U3 gate.
- Parameters:
qubit (int) – Target qubit index.
theta (float) – Polar angle in radians.
phi (float) – First phase angle in radians.
lam (float) – Second phase angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
uu15(q1, q2, params, control_qubits_set=None, is_dagger=False)[source]
U15 gate using KAK decomposition.
- Parameters:
q1 (int) – qubit 1 index
q2 (int) – qubit 2 index
params (list[float]) – list of 15 parameters
control_qubits_set (list[int] | None) – list of control qubits
is_dagger (bool) – whether to apply daggered gate
- Return type:
None
-
x(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the X (NOT) gate.
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
xx(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the XX interaction gate.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
theta (float) – Interaction angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
xy(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the XY interaction gate.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
theta (float) – Interaction angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
y(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the Y gate.
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
yy(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the YY interaction gate.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
theta (float) – Interaction angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
z(qubit, control_qubits_set=None, is_dagger=False)[source]
Apply the Z gate.
- Parameters:
qubit (int) – Target qubit index.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None
-
zz(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]
Apply the ZZ interaction gate.
- Parameters:
q1 (int) – First qubit index.
q2 (int) – Second qubit index.
theta (float) – Interaction angle in radians.
control_qubits_set (list[int] | None) – Control qubits.
is_dagger (bool) – Whether to apply the dagger version.
- Return type:
None