qermit.noise_model¶
- class qermit.noise_model.noise_model.ErrorDistribution(distribution, rng=Generator(PCG64) at 0x7F9512A3A960)[source]¶
Model of a Pauli error channel. Contains utilities to analyse and sample from distributions of errors.
- Attributes:
distribution: Dictionary mapping a string of Pauli errors to the probability that they occur. rng: Randomness generator.
- Parameters:
- Raises:
Exception – Raised if error probabilities sum to greater than 1.
- classmethod from_dict(distribution_dict)[source]¶
Generates ErrorDistribution from json serialisable representation.
- classmethod from_ptm(ptm, pauli_index)[source]¶
Convert a Pauli Transfer Matrix (PTM) to an error distribution.
- Parameters:
- Return type:
- Returns:
The converted error distribution.
- property identity_error_rate: float¶
The rate at which no error occurs.
- Returns:
Rate at which no error occurs. Calculated as 1 minus the total error rate of error in this distribution.
- classmethod mixture(distribution_list)[source]¶
Generates the distribution corresponding to the mixture of a list of distributions.
- Parameters:
distribution_list (
List
[ErrorDistribution
]) – List of instances of ErrorDistribution.- Return type:
- Returns:
Mixture distribution.
- order(reverse=True)[source]¶
Reorders the distribution dictionary based on probabilities.
- Parameters:
reverse (
bool
) – Order from high to low, defaults to True
- reset_rng(rng)[source]¶
Reset randomness generator.
- Parameters:
rng (
Generator
) – Randomness generator.
- scale(scaling_factor)[source]¶
Scale the error rates of this error distribution. This is done by converting the error distribution to a PTM, scaling that matrix appropriately, and converting back to a new error distribution.
- Parameters:
scaling_factor (
float
) – The factor by which the noise should be scaled.- Return type:
- Returns:
A new error distribution with the noise scaled.
- class qermit.noise_model.noise_model.NoiseModel(noise_model)[source]¶
Module for managing and executing a circuit noise model. In particular error models are assigned to each gate, and logical errors from circuits can be sampled.
- Attributes:
- noise_model: Mapping from gates to the error model which corresponds
to that gate.
- Parameters:
noise_model (
Dict
[OpType
,ErrorDistribution
]) – Map from gates to their error models.
- counter_propagate(cliff_circ, n_counts, **kwargs)[source]¶
Generate random noisy instances of the given circuit and propagate the noise to create a counter of logical errors. Note that kwargs are passed onto random_propagate.
- Parameters:
- Return type:
- Returns:
Counter of logical errors.
- classmethod from_dict(noise_model_dict)[source]¶
Convert JSON serialised version of noise model back to an instance of NoiseModel.
- get_effective_pre_error_distribution(cliff_circ, n_rand=1000, **kwargs)[source]¶
Retrieve the effective noise model of a given circuit. This is to say, repeatedly generate circuits with coherent noise added at random. Push all errors to the front of the circuit. Return a counter of the errors which have been pushed to the front.
- get_error_distribution(optype)[source]¶
Recovers error model corresponding to particular OpType.
- Parameters:
optype (
OpType
) – OpType for which noise model should be retrieved.- Return type:
- Returns:
Error model corresponding to particular OpType.
- property noisy_gates: List[OpType]¶
List of OpTypes with noise.
- Returns:
List of OpTypes with noise.
- random_propagate(cliff_circ, direction=Direction.backward)[source]¶
Generate a random noisy instance of the given circuit and propagate the noise forward or backward to recover the logical error.
- reset_rng(rng)[source]¶
Reset randomness generator.
- Parameters:
rng (
Generator
) – Randomness generator to be reset to.
- class qermit.noise_model.qermit_pauli.QermitPauli(Z_list, X_list, qubit_list, phase=0)[source]¶
For the manipulation of Pauli strings. In particular, how they are changed by the action of Clifford circuits. Note that each term in the tensor product of the Paulis should be thought of as: (i)^{phase}X^{X_list}Z^{Z_list}
Initialisation is by a list of qubits, and lists of 0, 1 values indicating that a Z or X operator acts there.
- Parameters:
- CX(control_qubit, target_qubit)[source]¶
Act CX operation. In particular this transforms the Pauli (i)^{phase}X^{X_liist}Z^{Z_list} to CX(i)^{phase}X^{X_liist}Z^{Z_list}CX^{dagger}.
- H(qubit)[source]¶
Act H operation. In particular this transforms the Pauli (i)^{phase}X^{X_liist}Z^{Z_list} to H(i)^{phase}X^{X_liist}Z^{Z_list}H^{dagger}.
- Parameters:
qubit (
Qubit
) – Qubit in Pauli on which H is acted.
- S(qubit)[source]¶
Act S operation on the pauli. In particular this transforms the pauli (i)^{phase}X^{X_liist}Z^{Z_list} to (i)^{phase}SX^{X_liist}Z^{Z_list}S^{dagger}.
- Parameters:
qubit (
Qubit
) – Qubit in Pauli onto which S is acted.
- apply_circuit(circuit)[source]¶
Apply a circuit to a pauli. This is to say commute tha Pauli through the circuit. The circuit should be a Clifford circuit.
- Parameters:
circuit (
Circuit
) – Circuit to be applied.
- apply_gate(op_type, qubits, **kwargs)[source]¶
Apply operation of given type to given qubit in the pauli. At present the recognised operation types are H, S, CX, Z, Sdg, X, Y, CZ, SWAP, and Barrier.
- static commute_coeff(pauli_one, pauli_two)[source]¶
Calculate the coefficient which result from commuting pauli_one past pauli_two. That is to say P_2 P_1 = c P_1 P_2 where c is the coefficient returned by this function.
- Parameters:
pauli_one (
QermitPauli
) – First Paulipauli_two (
QermitPauli
) – Second Pauli
- Raises:
Exception – Raised if the Paulis do not act on matching qubits.
- Return type:
- Returns:
Coefficient resulting from commuting the two Paulis.
- dagger()[source]¶
Generates the inverse of the Pauli.
- Return type:
- Returns:
Conjugate transpose of the Pauli.
- classmethod from_pauli_iterable(pauli_iterable, qubit_list)[source]¶
Create a QermitPauli from a Pauli iterable.
- Parameters:
- Return type:
- Returns:
The pauli corresponding to the given iterable.
- classmethod from_qubit_pauli_string(qps)[source]¶
Create a Pauli from a qubit pauli string.
- Parameters:
qps (
QubitPauliString
) – Qubit pauli string to be converted to a Pauli.- Return type:
- Returns:
Pauli created from qubit pauli string.
- get_control_circuit(control_qubit)[source]¶
Controlled circuit which acts Pauli.
- Return type:
- Returns:
Controlled circuit acting Paulii.
- property is_identity: bool¶
True is the pauli represents the all I string.
- Returns:
True is the pauli represents the all I string.
- is_measureable(qubit_list)[source]¶
Checks if this Pauli would be measurable on the given qubits in the computational bases. That is to say if at least one Pauli on the given qubits anticommutes with Z.
- property pauli_string: Tuple[List[Pauli], complex]¶
List of Paulis which correspond to Pauli, and the phase.
- Returns:
[description]
- post_apply_X(qubit)[source]¶
Post-apply X Pauli ito qubit.
- Parameters:
qubit (
Qubit
) – Qubit to which X is post-applied.
- post_apply_Z(qubit)[source]¶
Post-apply Z Pauli ito qubit.
- Parameters:
qubit (
Qubit
) – Qubit to which Z is post-applied.
- pre_apply_X(qubit)[source]¶
Pre-apply X Pauli ito qubit.
- Parameters:
qubit (
Qubit
) – Qubit to which X is pre-applied.
- pre_apply_Z(qubit)[source]¶
Pre-apply Z Pauli ito qubit.
- Parameters:
qubit (
Qubit
) – Qubit to which Z is pre-applied.
- pre_multiply(pauli)[source]¶
Pre-multiply by a Pauli.
- Parameters:
pauli (
QermitPauli
) – Pauli to pre multiply by.
- property qubit_pauli_string: Tuple[QubitPauliString, complex]¶
Qubit pauli string corresponding to Pauli, along with the appropriate phase.
- Returns:
Pauli string and phase corresponding to Pauli.
- classmethod random_pauli(qubit_list, rng=Generator(PCG64) at 0x7F9512A3AA40)[source]¶
Generates a uniformly random Pauli.
- Parameters:
- Return type:
- Returns:
Random pauli.
- qermit.noise_model.pauli_error_transpile.PauliErrorTranspile(noise_model)[source]¶
Generates compiler pass which adds coherent noise to a circuit.
- Parameters:
noise_model (
NoiseModel
) – Model describing the noise to be added. Should be a Pauli noise model.- Return type:
- Returns:
Compiler pass adding random coherent Pauli noise.
- class qermit.noise_model.transpiler_backend.TranspilerBackend(transpiler, result_dict={}, max_batch_size=1000, n_cores=1)[source]¶
Provides a backend like interface for noise simulation via compiler passes. In particular, for each shot a new circuit is generated by applying the given compiler pass.
- Attributes:
transpiler: Compiler pass to apply to simulate noise on a single instance of a circuit. max_batch_size: Shots are simulated in batches. This is the largest shot batch size permitted. result_dict: A dictionary mapping handles to results. backend: Backend used to simulate compiled circuits. n_cores: The number of cores used when simulating shots in parallel.
Initialisation method.
- Parameters:
transpiler (
BasePass
) – Compiler to use during noise simulation.max_batch_size (
int
) – Size of the largest batch of shots, defaults to 1000. The total number of shots is distributed between bathes of size 1000 plus a smaller batch for left over shot. These batches will be distributed to multiple cores.result_dict (
Dict
[ResultHandle
,BackendResult
]) – Results dictionary, may be used to store existing results within backend, defaults to {}n_cores (
int
) – Shots will be taken in parallel. This parameter specifies the number of cores to use. The default is to use one core.
- default_compilation_pass(**kwargs)[source]¶
Return a compiler pass which has no affect on the circuit.
- Return type:
- get_result(handle)[source]¶
Retrieve result from backend.
- Parameters:
handle (
ResultHandle
) – Handle identifying result.- Return type:
- Returns:
Result corresponding to handle.
- get_results(handles)[source]¶
Get the results corresponding to a collection of result handles.
- Parameters:
handles (
Iterable
[ResultHandle
]) – A collection of handles to retrieve.- Return type:
- Returns:
The results corresponding to the given collection of
- process_circuit(circuit, n_shots, **kwargs)[source]¶
[summary]
- Parameters:
- Return type:
- Returns:
Handle identifying results in result_dict.
- process_circuits(circuits, n_shots)[source]¶
Processes a collection of circuits by making use multiple calls to process_circuit.