qpandalite.simulator package#
Submodules#
qpandalite.simulator.base_simulator module#
Base simulator classes for QPanda-lite.
This module provides abstract base classes for quantum circuit simulators, defining common behaviors and interfaces for statevector and density matrix simulations. It also includes topology validation and qubit mapping utilities.
- Key exports:
TopologyError: Exception for invalid qubit/topology configurations.
BaseSimulator: Abstract base for ideal circuit simulators.
BaseNoisySimulator: Abstract base for noisy circuit simulators.
- class qpandalite.simulator.base_simulator.BaseNoisySimulator(backend_type='statevector', available_qubits=None, available_topology=None, error_loader=None, readout_error={})[源代码]
基类:
BaseSimulatorNoisy simulator base class supporting error models and readout errors.
Extends BaseSimulator with noise simulation capabilities including gate errors (via ErrorLoader) and measurement readout errors.
- 参数:
available_qubits (List[int])
available_topology (List[List[int]])
error_loader (ErrorLoader)
readout_error (Dict[int, List[float]])
- simulate_density_matrix(originir)[源代码]
Compute the density matrix with noise effects applied.
- 参数:
originir -- Quantum program in the simulator's input format.
- 返回:
Density matrix as a 2D numpy array.
- 抛出:
NotImplementedError -- If readout_error is set.
ValueError -- If backend is not density_operator type.
- simulate_pmeasure(originir)[源代码]
Compute measurement probabilities with noise effects.
- 参数:
originir -- Quantum program in the simulator's input format.
- 返回:
List of probabilities for each measurement outcome.
- 抛出:
ValueError -- If backend is not density_operator type.
- simulate_preprocess(originir)[源代码]
Parse, preprocess, and inject errors into the quantum program.
- 参数:
originir -- Quantum program in the simulator's input format.
- 返回:
Tuple containing the error-injected program body and measurement qubits.
- simulate_shots(quantum_code, shots)[源代码]
Execute the noisy circuit multiple times and return measurement counts.
- 参数:
quantum_code -- Quantum program code.
shots -- Number of measurement shots to perform.
- 返回:
Dictionary mapping outcome bitstrings (int) to their count.
- simulate_single_shot(originir)[源代码]
Execute the noisy circuit and return a single measurement sample.
- 参数:
originir -- OriginIR quantum program.
- 返回:
Integer representing the measured bitstring (decimal).
- simulate_statevector(originir)[源代码]
Not supported for noisy simulators.
- 抛出:
NotImplementedError -- Noisy simulators do not support statevector simulation.
- class qpandalite.simulator.base_simulator.BaseSimulator(backend_type='statevector', available_qubits=None, available_topology=None, **extra_kwargs)[源代码]
基类:
objectAbstract base class for quantum circuit simulators.
This class describes common behaviors of simulators. It is not designed to be used directly; instead, it should be subclassed by specific simulators (e.g., OriginIR_Simulator, QASM_Simulator).
- 参数:
available_qubits (List[int])
available_topology (List[List[int]])
- simulate_density_matrix(quantum_code)[源代码]
Compute the density matrix representation of the final state.
- 参数:
quantum_code -- Quantum program code.
- 返回:
Density matrix as a 2D numpy array.
- simulate_pmeasure(quantum_code)[源代码]
Compute measurement probabilities for all qubits.
- 参数:
quantum_code -- Quantum program code.
- 返回:
List of probabilities for each measurement outcome.
- simulate_preprocess(originir)[源代码]
Parse and preprocess the quantum program.
Extracts the actual used qubits, builds qubit mapping (e.g., q45 -> 0), checks topology constraints, and returns processed program body and measurement qubits.
- 参数:
originir -- Quantum program in the simulator's input format.
- 返回:
Tuple containing the processed program body and measurement qubits.
- simulate_shots(quantum_code, shots)[源代码]
Execute the circuit multiple times and return measurement counts.
- 参数:
quantum_code -- Quantum program code.
shots -- Number of measurement shots to perform.
- 返回:
Dictionary mapping outcome bitstrings (int) to their count.
- simulate_single_shot(quantum_code)[源代码]
Execute the circuit and return a single measurement sample.
- 参数:
quantum_code -- Quantum program code.
- 返回:
Integer representing the measured bitstring (decimal).
- simulate_stateprob(quantum_code)[源代码]
Compute state probabilities
(|amplitude|^2)for all basis states.- 参数:
quantum_code -- Quantum program code.
- 返回:
Array of probabilities for each basis state.
- simulate_statevector(quantum_code)[源代码]
Compute the final statevector after executing the circuit.
- 参数:
quantum_code -- Quantum program code.
- 返回:
Statevector as a complex numpy array.
- property simulator
Return the underlying simulator instance.
- property state
Return the current state of the simulator (statevector or density matrix).
- exception qpandalite.simulator.base_simulator.TopologyError[源代码]
基类:
ExceptionException raised when an invalid qubit or topology is used.
qpandalite.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.
ErrorLoader: Base error loader interface.
ErrorLoader_GenericError: Generic error loader.
ErrorLoader_GateTypeError: Gate-type specific error loader.
ErrorLoader_GateSpecificError: Gate-specific error loader.
- class qpandalite.simulator.error_model.AmplitudeDamping(gamma)[源代码]
基类:
ErrorModelAmplitude damping error model.
- 参数:
gamma (float) -- Damping rate (0 to 1).
- gamma: float
- generate_error_opcode(qubits)[源代码]
Generate AmplitudeDamping error opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- class qpandalite.simulator.error_model.BitFlip(p)[源代码]
基类:
ErrorModelBit-flip error model.
- 参数:
p (float) -- Bit-flip probability.
- generate_error_opcode(qubits)[源代码]
Generate BitFlip error opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- p: float
- class qpandalite.simulator.error_model.Depolarizing(p)[源代码]
基类:
ErrorModelDepolarizing error model for single qubits.
- 参数:
p (float) -- Depolarizing probability.
- generate_error_opcode(qubits)[源代码]
Generate Depolarizing error opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- p: float
- class qpandalite.simulator.error_model.ErrorLoader[源代码]
基类:
objectLoad opcodes into the simulator with noise models.
Base class that inserts error opcodes into the program.
- insert_error(opcode)[源代码]
Insert error opcodes for the given opcode. Override in subclasses.
- 参数:
opcode (tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None])
- 返回类型:
None
- insert_opcode(opcode)[源代码]
Append the original opcode and insert associated errors.
- 参数:
opcode (tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None])
- 返回类型:
None
- opcodes: list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- process_opcodes(opcodes)[源代码]
Process a list of opcodes, inserting errors for each.
- 参数:
opcodes (list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]])
- 返回类型:
None
- class qpandalite.simulator.error_model.ErrorLoader_GateSpecificError(generic_error, gatetype_error, gate_specific_error)[源代码]
基类:
ErrorLoader_GateTypeErrorLoad 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)).
- 参数:
generic_error (list[ErrorModel])
gatetype_error (dict[str, list[ErrorModel]])
gate_specific_error (dict[tuple[str, tuple[int, int]], list[ErrorModel]])
- gate_specific_error: dict[tuple[str, tuple[int, int]], list[ErrorModel]]
- insert_error(opcode)[源代码]
Insert generic, gate-type, and gate-specific errors for the given opcode.
- 参数:
opcode (tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None])
- 返回类型:
None
- class qpandalite.simulator.error_model.ErrorLoader_GateTypeError(generic_error, gatetype_error)[源代码]
基类:
ErrorLoader_GenericErrorLoad opcodes with gate-dependent noise.
Supports both generic errors (applied to all gates) and per-gate-type errors (applied only to specific gate types).
- 参数:
generic_error (list[ErrorModel])
gatetype_error (dict[str, list[ErrorModel]])
- gatetype_error: dict[str, list[ErrorModel]]
- insert_error(opcode)[源代码]
Insert generic and gate-type-specific errors for the given opcode.
- 参数:
opcode (tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None])
- 返回类型:
None
- class qpandalite.simulator.error_model.ErrorLoader_GenericError(generic_error)[源代码]
基类:
ErrorLoaderLoad opcodes with generic (gate-independent) noise.
Applies the same set of error models to every gate.
- 参数:
generic_error (list[ErrorModel])
- generic_error: list[ErrorModel]
- insert_error(opcode)[源代码]
Insert generic errors for the given opcode.
- 参数:
opcode (tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None])
- 返回类型:
None
- class qpandalite.simulator.error_model.ErrorModel[源代码]
基类:
objectBase class for quantum error models.
- generate_error_opcode(qubits)[源代码]
Generate error opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- class qpandalite.simulator.error_model.Kraus1Q(kraus_ops)[源代码]
基类:
ErrorModelSingle-qubit Kraus operator error model.
- 参数:
kraus_ops (list[list[complex]]) -- List of Kraus operators (2x2 matrices).
- generate_error_opcode(qubits)[源代码]
Generate Kraus1Q error opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- kraus_ops: list[list[complex]]
- class qpandalite.simulator.error_model.PauliError1Q(p_x, p_y, p_z)[源代码]
基类:
ErrorModelSingle-qubit Pauli error model with independent X, Y, Z probabilities.
- 参数:
p_x (float) -- Probability of X error.
p_y (float) -- Probability of Y error.
p_z (float) -- Probability of Z error.
- generate_error_opcode(qubits)[源代码]
Generate PauliError1Q opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- p_x: float
- p_y: float
- p_z: float
- class qpandalite.simulator.error_model.PauliError2Q(ps)[源代码]
基类:
ErrorModelTwo-qubit Pauli error model with 15 independent probabilities.
- 参数:
ps (list[float]) -- List of 15 Pauli error probabilities.
- generate_error_opcode(qubits)[源代码]
Generate PauliError2Q opcodes for the given qubit pair.
- 参数:
qubits (int | list[int]) -- List of exactly two qubits.
- 返回:
List of error opcodes.
- 抛出:
ValueError -- If not exactly two qubits are provided.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- ps: list[float]
- class qpandalite.simulator.error_model.PhaseFlip(p)[源代码]
基类:
ErrorModelPhase-flip (Z) error model.
- 参数:
p (float) -- Phase-flip probability.
- generate_error_opcode(qubits)[源代码]
Generate PhaseFlip error opcodes for the given qubits.
- 参数:
qubits (int | list[int]) -- Qubit or list of qubits to apply error to.
- 返回:
List of error opcodes.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- p: float
- class qpandalite.simulator.error_model.TwoQubitDepolarizing(p)[源代码]
基类:
ErrorModelTwo-qubit depolarizing error model.
- 参数:
p (float) -- Depolarizing probability.
- generate_error_opcode(qubits)[源代码]
Generate TwoQubitDepolarizing error opcodes for the given qubit pair.
- 参数:
qubits (int | list[int]) -- List of exactly two qubits.
- 返回:
List of error opcodes.
- 抛出:
ValueError -- If not exactly two qubits are provided.
- 返回类型:
list[tuple[str, int | list[int], Any, float | tuple[float, float, float] | list[complex] | None, None, None]]
- p: float
qpandalite.simulator.get_backend module#
Simulator backend factory for QPanda-lite.
This module provides a factory function to obtain appropriate simulator instances based on the quantum program type (OriginIR or QASM).
- Key exports:
get_backend: Factory function to create simulator backends.
- qpandalite.simulator.get_backend.get_backend(program_type='originir', backend_type='statevector', **kwargs)[源代码]
Get a simulator backend for the specified program type.
- 参数:
program_type (str) -- Type of quantum program ("originir" or "qasm").
backend_type (str) -- Backend simulation type ("statevector" or "density_matrix").
**kwargs -- Additional arguments passed to the simulator constructor.
- 返回:
A BaseSimulator instance for the given program type.
- 抛出:
ValueError -- If program_type is not supported.
- 返回类型:
BaseSimulator
qpandalite.simulator.opcode_simulator module#
Opcode simulator, a fundamental simulator for QPanda-lite. It simulates from a basic opcode
- class qpandalite.simulator.opcode_simulator.OpcodeSimulator(backend_type='statevector')[源代码]
基类:
objectA quantum circuit simulator based on C++ that runs locally.
- 参数:
backend_type -- Backend type for simulation. Supported: 'statevector', 'density_matrix', 'density_matrix_qutip'. Defaults to 'statevector'.
- simulator
The underlying C++ simulator instance. typestr: Human-readable backend type string.
- simulate_gate(operation, qubit, cbit, parameter, is_dagger, control_qubits_set)[源代码]
Apply a single gate opcode to the simulator.
- 参数:
operation -- Gate name string.
qubit -- Qubit index or list of indices.
cbit -- Classical bit index.
parameter -- Gate parameters.
is_dagger -- Whether to apply the dagger version of the gate.
control_qubits_set -- Set of control qubits.
- simulate_opcodes_density_operator(n_qubit, program_body)[源代码]
Compute the density matrix after executing a list of opcodes.
- 参数:
n_qubit -- Number of qubits.
program_body -- List of opcodes to simulate.
- 返回:
Density matrix as a 2D numpy array.
- 抛出:
ValueError -- If simulator type is unknown.
- simulate_opcodes_pmeasure(n_qubit, program_body, measure_qubits)[源代码]
Compute measurement probabilities for a list of opcodes.
- 参数:
n_qubit -- Number of qubits.
program_body -- List of opcodes to simulate.
measure_qubits -- Qubits to measure.
- 返回:
List of probabilities for each measurement outcome.
- simulate_opcodes_shot(n_qubit, program_body, measure_qubits)[源代码]
Execute a list of opcodes and return a single measurement sample.
- 参数:
n_qubit -- Number of qubits.
program_body (List[tuple[str, int | list[int], int | list[int] | None, float | list[float] | tuple[float, ...] | None, bool, int | list[int]]]) -- List of opcodes to simulate.
measure_qubits -- Qubits to measure.
- 返回:
Integer representing the measured bitstring (decimal).
- 抛出:
NotImplementedError -- If backend is density_operator type.
- simulate_opcodes_stateprob(n_qubit, program_body)[源代码]
Compute state probabilities
(|amplitude|^2)for all basis states.- 参数:
n_qubit -- Number of qubits.
program_body -- List of opcodes to simulate.
- 返回:
Array of probabilities for each basis state.
- 抛出:
ValueError -- If simulator type is unknown.
- simulate_opcodes_statevector(n_qubit, program_body)[源代码]
Compute the final statevector after executing a list of opcodes.
- 参数:
n_qubit -- Number of qubits.
program_body -- List of opcodes to simulate.
- 返回:
Statevector as a complex numpy array.
- 抛出:
ValueError -- If backend is density_matrix type.
- qpandalite.simulator.opcode_simulator.backend_alias(backend_type)[源代码]
Resolve backend type aliases to canonical names.
Supported backends: statevector, density_matrix
Note: Uppercase and lowercase are both supported.
- 返回:
Canonical backend type string ("statevector" or "density_operator").
qpandalite.simulator.originir_simulator module#
OriginIR quantum program simulator.
This module provides simulators for OriginIR-format quantum programs, supporting both ideal and noisy simulations with topology validation.
- Key exports:
OriginIR_Simulator: Ideal simulator for OriginIR programs.
OriginIR_NoisySimulator: Noisy simulator for OriginIR programs with error models.
- class qpandalite.simulator.originir_simulator.OriginIR_NoisySimulator(backend_type='statevector', available_qubits=None, available_topology=None, error_loader=None, readout_error={})[源代码]
基类:
BaseNoisySimulatorNoisy OriginIR quantum program simulator.
Simulator for OriginIR-format quantum programs with noise model support, backed by C++.
- 参数:
backend_type -- Backend type ("statevector" or "densitymatrix").
available_qubits (List[int]) -- List of available qubit indices (optional).
available_topology (List[List[int]]) -- List of available qubit pairs (optional).
error_loader (ErrorLoader) -- ErrorLoader instance for gate error injection (optional).
readout_error (Dict[int, List[float]]) -- Dict mapping qubit index to [p0, p1] readout error rates (optional).
- class qpandalite.simulator.originir_simulator.OriginIR_Simulator(backend_type='statevector', available_qubits=None, available_topology=None, **extra_kwargs)[源代码]
基类:
BaseSimulatorOriginIR quantum program simulator.
Simulator for OriginIR-format quantum programs, backed by C++.
- 参数:
backend_type -- Backend type ("statevector" or "densitymatrix").
available_qubits (List[int]) -- List of available qubit indices (optional).
available_topology (List[List[int]]) -- List of available qubit pairs (optional).
**extra_kwargs -- Additional arguments passed to BaseSimulator.
qpandalite.simulator.qasm_simulator module#
OpenQASM 2.0 quantum program simulator.
This module provides simulators for OpenQASM 2.0 format quantum programs, supporting both ideal and noisy simulations.
- Key exports:
QASM_Simulator: Ideal simulator for OpenQASM 2.0 programs.
QASM_Noisy_Simulator: Noisy simulator for OpenQASM 2.0 programs with error models.
- class qpandalite.simulator.qasm_simulator.QASM_Noisy_Simulator(backend_type='statevector', available_qubits=None, available_topology=None, error_loader=None, readout_error={})[源代码]
基类:
BaseNoisySimulatorNoisy OpenQASM 2.0 quantum program simulator.
Simulator for OpenQASM 2.0 format quantum programs with noise model support.
- 参数:
backend_type -- Backend type ("statevector" or "densitymatrix").
available_qubits (List[int]) -- List of available qubit indices (optional).
available_topology (List[List[int]]) -- List of available qubit pairs (optional).
error_loader (ErrorLoader) -- ErrorLoader instance for gate error injection (optional).
readout_error (Dict[int, List[float]]) -- Dict mapping qubit index to [p0, p1] readout error rates (optional).
- class qpandalite.simulator.qasm_simulator.QASM_Simulator(backend_type='statevector', available_qubits=None, available_topology=None, least_qubit_remapping=False, **extra_kwargs)[源代码]
基类:
BaseSimulatorOpenQASM 2.0 quantum program simulator.
Simulator for OpenQASM 2.0 format quantum programs.
- 参数:
backend_type -- Backend type ("statevector" or "densitymatrix").
available_qubits (List[int]) -- List of available qubit indices (optional).
available_topology (List[List[int]]) -- List of available qubit pairs (optional).
least_qubit_remapping -- Whether to remap qubits to least-available indices (default False).
**extra_kwargs -- Additional arguments passed to BaseSimulator.
qpandalite.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 qpandalite.simulator.qutip_sim_impl.DensityOperatorSimulatorQutip[源代码]
基类:
objectDensity-matrix simulator backed by QuTiP.
- amplitude_damping(qubit, gamma)[源代码]
Apply amplitude damping noise.
- 参数:
qubit (int) -- Target qubit index.
gamma (float) -- Damping rate (0 to 1).
- 返回类型:
None
- bitflip(qubit, p)[源代码]
Apply bit-flip (X) noise.
- 参数:
qubit (int) -- Target qubit index.
p (float) -- Bit-flip probability.
- 返回类型:
None
- cnot(control_qubit, target_qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the CNOT (controlled-NOT) gate.
- 参数:
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.
- 返回类型:
None
- cswap(control_qubit, q1, q2, control_qubits_set=None, is_dagger=False)[源代码]
Apply the CSWAP (Fredkin) gate.
- 参数:
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.
- 返回类型:
None
- cz(qubit1, qubit2, control_qubits_set=None, is_dagger=False)[源代码]
Apply the CZ (controlled-Z) gate.
- 参数:
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.
- 返回类型:
None
- density_matrix: Qobj | None
- depolarizing(qubit, p)[源代码]
Apply depolarizing noise to a single qubit.
- 参数:
qubit (int) -- Target qubit index.
p (float) -- Depolarizing probability.
- 返回类型:
None
- hadamard(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the Hadamard gate.
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- init_n_qubit(n)[源代码]
Initialize the simulator with n qubits in the
|0...0>state.- 参数:
n (int)
- 返回类型:
None
- iswap(q1, q2, control_qubits_set=None, is_dagger=False)[源代码]
Apply the iSWAP gate.
- 参数:
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.
- 返回类型:
None
- kraus1q(qubit, parameters)[源代码]
Apply single-qubit Kraus noise.
- 参数:
qubit (int) -- Target qubit index.
parameters (list[list[float]]) -- List of Kraus operator matrix elements (flattened 2x2).
- 返回类型:
None
- kraus2q(q1, q2, parameters)[源代码]
Apply two-qubit Kraus noise.
- 参数:
q1 (int) -- First qubit index.
q2 (int) -- Second qubit index.
parameters (list[list[float]]) -- List of Kraus operator matrix elements (flattened 4x4).
- 返回类型:
None
- n_qubits: int
- pauli_error_1q(qubit, px, py, pz)[源代码]
Apply single-qubit Pauli error.
- 参数:
qubit (int) -- Target qubit index.
px (float) -- Probability of X error.
py (float) -- Probability of Y error.
pz (float) -- Probability of Z error.
- 返回类型:
None
- pauli_error_2q(q1, q2, parameters)[源代码]
Two-qubit Pauli error with 15 independent probabilities.
- 参数:
q1 (int) -- qubit 1 index
q2 (int) -- qubit 2 index
parameters (list[float] | tuple[float, ...]) -- list of 15 probabilities
- 返回类型:
None
- phase2q(q1, q2, theta1, theta2, theta3, control_qubits_set=None, is_dagger=False)[源代码]
Phase2Q gate: u1(q1, theta1), u1(q2, theta2), zz(q1, q2, theta3).
- 参数:
q1 (int)
q2 (int)
theta1 (float)
theta2 (float)
theta3 (float)
control_qubits_set (list[int] | None)
is_dagger (bool)
- 返回类型:
None
- phaseflip(qubit, prob)[源代码]
Apply phase-flip (Z) noise.
- 参数:
qubit (int) -- Target qubit index.
prob (float) -- Phase-flip probability.
- 返回类型:
None
- pmeasure(measure_qubits)[源代码]
Compute measurement probabilities for the given qubits.
- 参数:
measure_qubits (list[int])
- 返回类型:
list[float]
- rphi(qubit, theta, phi, control_qubits_set=None, is_dagger=False)[源代码]
Apply the RPhi gate (rotation around axis in XY plane).
- 参数:
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.
- 返回类型:
None
- rphi180(qubit, phi, control_qubits_set=None, is_dagger=False)[源代码]
Apply the RPhi180 gate (π rotation around axis in XY plane).
- 参数:
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.
- 返回类型:
None
- rphi90(qubit, phi, control_qubits_set=None, is_dagger=False)[源代码]
Apply the RPhi90 gate (π/2 rotation around axis in XY plane).
- 参数:
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.
- 返回类型:
None
- rx(qubit, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the RX gate.
- 参数:
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.
- 返回类型:
None
- ry(qubit, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the RY gate.
- 参数:
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.
- 返回类型:
None
- rz(qubit, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the RZ gate.
- 参数:
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.
- 返回类型:
None
- s(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the S gate (phase gate, π/2).
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- property state: ndarray
Return the density matrix as a NumPy array.
- stateprob()[源代码]
Return the diagonal of the density matrix (state probabilities).
- 返回类型:
ndarray
- swap(qubit1, qubit2, control_qubits_set=None, is_dagger=False)[源代码]
Apply the SWAP gate.
- 参数:
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.
- 返回类型:
None
- sx(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the SX (square-root of X) gate.
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- t(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the T gate (π/4 phase gate).
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- toffoli(c1, c2, target, control_qubits_set=None, is_dagger=False)[源代码]
Apply the Toffoli (CCNOT) gate.
- 参数:
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.
- 返回类型:
None
- twoqubit_depolarizing(q1, q2, p)[源代码]
Apply two-qubit depolarizing noise.
- 参数:
q1 (int) -- First qubit index.
q2 (int) -- Second qubit index.
p (float) -- Depolarizing probability.
- 返回类型:
None
- u1(qubit, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the U1 gate.
- 参数:
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.
- 返回类型:
None
- u2(qubit, phi, lam, control_qubits_set=None, is_dagger=False)[源代码]
Apply the U2 gate.
- 参数:
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.
- 返回类型:
None
- u3(qubit, theta, phi, lam, control_qubits_set=None, is_dagger=False)[源代码]
Apply the U3 gate.
- 参数:
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.
- 返回类型:
None
- uu15(q1, q2, params, control_qubits_set=None, is_dagger=False)[源代码]
U15 gate using KAK decomposition.
- 参数:
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
- 返回类型:
None
- x(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the X (NOT) gate.
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- xx(q1, q2, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the XX interaction gate.
- 参数:
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.
- 返回类型:
None
- xy(q1, q2, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the XY interaction gate.
- 参数:
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.
- 返回类型:
None
- y(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the Y gate.
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- yy(q1, q2, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the YY interaction gate.
- 参数:
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.
- 返回类型:
None
- z(qubit, control_qubits_set=None, is_dagger=False)[源代码]
Apply the Z gate.
- 参数:
qubit (int) -- Target qubit index.
control_qubits_set (list[int] | None) -- Control qubits.
is_dagger (bool) -- Whether to apply the dagger version.
- 返回类型:
None
- zz(q1, q2, theta, control_qubits_set=None, is_dagger=False)[源代码]
Apply the ZZ interaction gate.
- 参数:
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.
- 返回类型:
None