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:
  • DensityOperatorSimulatorQutip: Density-matrix simulator backed by QuTiP.

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:
  • qubit – Target qubit index.

  • gamma – Damping rate (0 to 1).

bitflip(qubit, p)[source]

Apply bit-flip (X) noise.

Parameters:
  • qubit – Target qubit index.

  • p – Bit-flip probability.

cnot(control_qubit, target_qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the CNOT (controlled-NOT) gate.

Parameters:
  • control_qubit – Control qubit index.

  • target_qubit – Target qubit index.

  • control_qubits_set – Additional control qubits.

  • is_dagger – Whether to apply the dagger version.

cswap(control_qubit, q1, q2, control_qubits_set=None, is_dagger=False)[source]

Apply the CSWAP (Fredkin) gate.

Parameters:
  • control_qubit – Control qubit index.

  • q1 – First target qubit index.

  • q2 – Second target qubit index.

  • control_qubits_set – Additional control qubits.

  • is_dagger – Whether to apply the dagger version.

cz(qubit1, qubit2, control_qubits_set=None, is_dagger=False)[source]

Apply the CZ (controlled-Z) gate.

Parameters:
  • qubit1 – First qubit index.

  • qubit2 – Second qubit index.

  • control_qubits_set – Additional control qubits.

  • is_dagger – Whether to apply the dagger version.

density_matrix
depolarizing(qubit, p)[source]

Apply depolarizing noise to a single qubit.

Parameters:
  • qubit – Target qubit index.

  • p – Depolarizing probability.

hadamard(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the Hadamard gate.

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

init_n_qubit(n)[source]

Initialize the simulator with n qubits in the |0...0> state.

iswap(q1, q2, control_qubits_set=None, is_dagger=False)[source]

Apply the iSWAP gate.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

kraus1q(qubit, parameters)[source]

Apply single-qubit Kraus noise.

Parameters:
  • qubit – Target qubit index.

  • parameters – List of Kraus operator matrix elements (flattened 2x2).

kraus2q(q1, q2, parameters)[source]

Apply two-qubit Kraus noise.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • parameters – List of Kraus operator matrix elements (flattened 4x4).

n_qubits
pauli_error_1q(qubit, px, py, pz)[source]

Apply single-qubit Pauli error.

Parameters:
  • qubit – Target qubit index.

  • px – Probability of X error.

  • py – Probability of Y error.

  • pz – Probability of Z error.

pauli_error_2q(q1, q2, parameters)[source]

Two-qubit Pauli error with 15 independent probabilities.

Parameters:
  • q1 – qubit 1 index

  • q2 – qubit 2 index

  • parameters – list of 15 probabilities

phase2q(q1, q2, theta1, theta2, theta3, control_qubits_set=None, is_dagger=False)[source]

Apply the canonical diagonal PHASE2Q unitary.

phaseflip(qubit, prob)[source]

Apply phase-flip (Z) noise.

Parameters:
  • qubit – Target qubit index.

  • prob – Phase-flip probability.

pmeasure(measure_qubits)[source]

Compute measurement probabilities for the given qubits.

rphi(qubit, theta, phi, control_qubits_set=None, is_dagger=False)[source]

Apply the RPhi gate (rotation around axis in XY plane).

Parameters:
  • qubit – Target qubit index.

  • theta – Polar angle in radians.

  • phi – Azimuthal angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

rphi180(qubit, phi, control_qubits_set=None, is_dagger=False)[source]

Apply the RPhi180 gate (π rotation around axis in XY plane).

Parameters:
  • qubit – Target qubit index.

  • phi – Azimuthal angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

rphi90(qubit, phi, control_qubits_set=None, is_dagger=False)[source]

Apply the RPhi90 gate (π/2 rotation around axis in XY plane).

Parameters:
  • qubit – Target qubit index.

  • phi – Azimuthal angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

rx(qubit, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the RX gate.

Parameters:
  • qubit – Target qubit index.

  • theta – Rotation angle in radians.

  • control_qubits_set – Control qubits for controlled rotation.

  • is_dagger – Whether to apply the dagger version.

ry(qubit, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the RY gate.

Parameters:
  • qubit – Target qubit index.

  • theta – Rotation angle in radians.

  • control_qubits_set – Control qubits for controlled rotation.

  • is_dagger – Whether to apply the dagger version.

rz(qubit, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the RZ gate.

Parameters:
  • qubit – Target qubit index.

  • theta – Rotation angle in radians.

  • control_qubits_set – Control qubits for controlled rotation.

  • is_dagger – Whether to apply the dagger version.

s(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the S gate (phase gate, π/2).

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

property state

Return the density matrix as a NumPy array.

stateprob()[source]

Return the diagonal of the density matrix (state probabilities).

swap(qubit1, qubit2, control_qubits_set=None, is_dagger=False)[source]

Apply the SWAP gate.

Parameters:
  • qubit1 – First qubit index.

  • qubit2 – Second qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

sx(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the SX (square-root of X) gate.

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

t(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the T gate (π/4 phase gate).

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

toffoli(c1, c2, target, control_qubits_set=None, is_dagger=False)[source]

Apply the Toffoli (CCNOT) gate.

Parameters:
  • c1 – First control qubit index.

  • c2 – Second control qubit index.

  • target – Target qubit index.

  • control_qubits_set – Additional control qubits.

  • is_dagger – Whether to apply the dagger version.

twoqubit_depolarizing(q1, q2, p)[source]

Apply two-qubit depolarizing noise.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • p – Depolarizing probability.

u1(qubit, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the U1 gate.

Parameters:
  • qubit – Target qubit index.

  • theta – Phase angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

u2(qubit, phi, lam, control_qubits_set=None, is_dagger=False)[source]

Apply the U2 gate.

Parameters:
  • qubit – Target qubit index.

  • phi – First phase angle in radians.

  • lam – Second phase angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

u3(qubit, theta, phi, lam, control_qubits_set=None, is_dagger=False)[source]

Apply the U3 gate.

Parameters:
  • qubit – Target qubit index.

  • theta – Polar angle in radians.

  • phi – First phase angle in radians.

  • lam – Second phase angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

uu15(q1, q2, params, control_qubits_set=None, is_dagger=False)[source]

U15 gate using KAK decomposition.

Parameters:
  • q1 – qubit 1 index

  • q2 – qubit 2 index

  • params – list of 15 parameters

  • control_qubits_set – list of control qubits

  • is_dagger – whether to apply daggered gate

x(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the X (NOT) gate.

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

xx(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the XX interaction gate.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • theta – Interaction angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

xy(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the XY interaction gate.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • theta – Interaction angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

y(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the Y gate.

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

yy(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the YY interaction gate.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • theta – Interaction angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

z(qubit, control_qubits_set=None, is_dagger=False)[source]

Apply the Z gate.

Parameters:
  • qubit – Target qubit index.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.

zz(q1, q2, theta, control_qubits_set=None, is_dagger=False)[source]

Apply the ZZ interaction gate.

Parameters:
  • q1 – First qubit index.

  • q2 – Second qubit index.

  • theta – Interaction angle in radians.

  • control_qubits_set – Control qubits.

  • is_dagger – Whether to apply the dagger version.