uniqc.simulator.error_model module

Quantum error models for noisy simulation.

This module defines various quantum noise models that can be applied to circuit simulations, including bit-flip, phase-flip, depolarizing, amplitude damping, and Kraus operator errors.

Key exports:
  • ErrorModel: Base class for all error models.

  • BitFlip: Bit-flip (X) error model.

  • PhaseFlip: Phase-flip (Z) error model.

  • Depolarizing: Single-qubit depolarizing channel.

  • TwoQubitDepolarizing: Two-qubit depolarizing channel.

  • AmplitudeDamping: Amplitude damping (T1) error model.

  • PauliError1Q: Single-qubit Pauli error model.

  • PauliError2Q: Two-qubit Pauli error model.

  • Kraus1Q: Single-qubit Kraus operator error model.

  • ThermalRelaxation: T1/T2 thermal relaxation error model.

  • ErrorLoader: Base error loader interface.

  • ErrorLoader_GenericError: Generic error loader.

  • ErrorLoader_GateTypeError: Gate-type specific error loader.

  • ErrorLoader_GateSpecificError: Gate-specific error loader.

class uniqc.simulator.error_model.AmplitudeDamping(gamma)[source]

Bases: ErrorModel

Amplitude damping error model.

Parameters:

gamma – Damping rate (0 to 1).

gamma
generate_error_opcode(qubits)[source]

Generate AmplitudeDamping error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

class uniqc.simulator.error_model.BitFlip(p)[source]

Bases: ErrorModel

Bit-flip error model.

Parameters:

p – Bit-flip probability.

generate_error_opcode(qubits)[source]

Generate BitFlip error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

p
class uniqc.simulator.error_model.Depolarizing(p)[source]

Bases: ErrorModel

Depolarizing error model for single qubits.

Parameters:

p – Depolarizing probability.

generate_error_opcode(qubits)[source]

Generate Depolarizing error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

p
class uniqc.simulator.error_model.ErrorLoader[source]

Bases: object

Load opcodes into the simulator with noise models.

Base class that inserts error opcodes into the program.

insert_error(opcode)[source]

Insert error opcodes for the given opcode. Override in subclasses.

insert_opcode(opcode)[source]

Append the original opcode and insert associated errors.

opcodes
process_opcodes(opcodes)[source]

Process a list of opcodes, inserting errors for each.

class uniqc.simulator.error_model.ErrorLoader_GateSpecificError(generic_error, gatetype_error, gate_specific_error)[source]

Bases: ErrorLoader_GateTypeError

Load opcodes with gate-specific noise (including per qubit-pair).

Supports generic errors, per-gate-type errors, and per-gate-instance errors (keyed by gate name and specific qubit(s)).

gate_specific_error
insert_error(opcode)[source]

Insert generic, gate-type, and gate-specific errors for the given opcode.

class uniqc.simulator.error_model.ErrorLoader_GateTypeError(generic_error, gatetype_error)[source]

Bases: ErrorLoader_GenericError

Load opcodes with gate-dependent noise.

Supports both generic errors (applied to all gates) and per-gate-type errors (applied only to specific gate types).

gatetype_error
insert_error(opcode)[source]

Insert generic and gate-type-specific errors for the given opcode.

class uniqc.simulator.error_model.ErrorLoader_GenericError(generic_error)[source]

Bases: ErrorLoader

Load opcodes with generic (gate-independent) noise.

Applies the same set of error models to every gate.

generic_error
insert_error(opcode)[source]

Insert generic errors for the given opcode.

class uniqc.simulator.error_model.ErrorModel[source]

Bases: object

Base class for quantum error models.

generate_error_opcode(qubits)[source]

Generate error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

class uniqc.simulator.error_model.Kraus1Q(kraus_ops)[source]

Bases: ErrorModel

Single-qubit Kraus operator error model.

Parameters:

kraus_ops – List of Kraus operators (2x2 matrices).

generate_error_opcode(qubits)[source]

Generate Kraus1Q error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

kraus_ops
class uniqc.simulator.error_model.PauliError1Q(p_x, p_y, p_z)[source]

Bases: ErrorModel

Single-qubit Pauli error model with independent X, Y, Z probabilities.

Parameters:
  • p_x – Probability of X error.

  • p_y – Probability of Y error.

  • p_z – Probability of Z error.

generate_error_opcode(qubits)[source]

Generate PauliError1Q opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

p_x
p_y
p_z
class uniqc.simulator.error_model.PauliError2Q(ps)[source]

Bases: ErrorModel

Two-qubit Pauli error model with 15 independent probabilities.

Parameters:

ps – List of 15 Pauli error probabilities.

generate_error_opcode(qubits)[source]

Generate PauliError2Q opcodes for the given qubit pair.

Parameters:

qubits – List of exactly two qubits.

Returns:

List of error opcodes.

Raises:

ValueError – If not exactly two qubits are provided.

ps
class uniqc.simulator.error_model.PhaseFlip(p)[source]

Bases: ErrorModel

Phase-flip (Z) error model.

Parameters:

p – Phase-flip probability.

generate_error_opcode(qubits)[source]

Generate PhaseFlip error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes.

p
class uniqc.simulator.error_model.ThermalRelaxation(t1_ns, t2_ns=None, gate_time_ns=0.0)[source]

Bases: ErrorModel

Thermal relaxation (T1/T2) error model for a gate of fixed duration.

Emits per-qubit amplitude-damping (T1) and phase-flip (pure dephasing, T2) opcodes whose rates are derived from the gate duration t:

  • gamma = 1 - exp(-t / T1) (amplitude damping, only when T1 is set)

  • p_phi = 0.5 * (1 - exp(-t * (1/T2 - 1/(2*T1)))) when both T1 and T2 are set, or p_phi = 0.5 * (1 - exp(-t / T2)) (pure dephasing) when only T2 is set.

Parameters:
  • t1_ns – T1 time in nanoseconds. Either a single value applied to every qubit, or a per-qubit mapping. None disables amplitude damping.

  • t2_ns – T2 time in nanoseconds, same shape as t1_ns. None disables pure dephasing.

  • gate_time_ns – Duration of the gate in nanoseconds. Must be positive.

Raises:

ValueError – If both t1_ns and t2_ns are None, if any time is non-positive, or if T2 > 2 * T1 for a qubit (which would make the dephasing probability negative).

generate_error_opcode(qubits)[source]

Generate thermal relaxation error opcodes for the given qubits.

Parameters:

qubits – Qubit or list of qubits to apply error to.

Returns:

List of error opcodes (AmplitudeDamping and/or PhaseFlip).

static relaxation_rates(t1, t2, t)[source]

Return (gamma, p_phi) for a qubit with the given T1/T2 and gate time t.

class uniqc.simulator.error_model.TwoQubitDepolarizing(p)[source]

Bases: ErrorModel

Two-qubit depolarizing error model.

Parameters:

p – Depolarizing probability.

generate_error_opcode(qubits)[source]

Generate TwoQubitDepolarizing error opcodes for the given qubit pair.

Parameters:

qubits – List of exactly two qubits.

Returns:

List of error opcodes.

Raises:

ValueError – If not exactly two qubits are provided.

p