qermit.noise_model¶
- class qermit.noise_model.noise_model.ErrorDistribution(distribution, rng=Generator(PCG64) at 0x7FDA00369FC0)[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(qpt)[source]¶
For the manipulation of Pauli strings. In particular, how they are changed by the action of Clifford circuits.
Initialised with an initial qubit pauli tensor. Other methods will modify this Qubit Pauli Tensor.
- Parameters:
qpt (
QubitPauliTensor
) – Initial Qubit Pauli Tensor.
- apply_circuit(circuit)[source]¶
Commute the Pauli through the circuit. Given a Clifford circuit C, transform the Pauli P to Q such that PC = CQ.
- apply_gate(op, qubits)[source]¶
Commute the Pauli through the gate. Given a Clifford gate G, transform the Pauli P to Q such that PG = GQ.
- property dagger: QermitPauli¶
Generates the inverse of the Pauli.
- Returns:
Conjugate transpose of the Pauli.
- 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 qubit_pauli_tensor: QubitPauliTensor¶
Current state of the Pauli, following any operations which may have been acted upon it until now.
- Returns:
Current state of the 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.