pygsti.extras.rb.simulate

Clifford circuits with Pauli errors simulation functions

Module Contents

Classes

IndDepolErrorModel

todo

Functions

random_paulierror_in_chp(q)

todo.

random_pauli_in_chp(q)

todo.

stdgate_to_chp(gate, chpqubits)

todo

depolarizing_errors_circuit_simulator(circuitlist, shots, errormodel, gate_to_chp=None, aux_info_list=None, collision_action='keepseparate', outdir='', perge_chp_files=True, returnds=True, verbosity=1)

todo.

circuit_simulator_for_tensored_independent_pauli_errors(circuit, pspec, errormodel, counts, alloutcomes=False, idle1q_placeholder='I')

A Clifford circuit simulator for an error model whereby each gate in the circuit induces independent Pauli

oneshot_circuit_simulator_for_tensored_independent_pauli_errors(circuit, pspec, errormodel, idle1q_placeholder='I')

Generates a single measurement result for the circuit_simulator_for_tensored_independent_pauli_errors()

rb_with_pauli_errors(pspec, errormodel, lengths, k, counts, qubit_subset=None, filename=None, rbtype='DRB', rbspec=[], returndata=True, appenddata=False, verbosity=0, idle1q_placeholder='I')

Simulates RB with Pauli errors. Can be used to simulated Clifford RB, direct RB and mirror RB. This

create_iid_pauli_error_model(pspec, one_qubit_gate_errorrate, two_qubit_gate_errorrate, idle_errorrate, measurement_errorrate=0.0, ptype='uniform', idle1q_placeholder='I')

Returns a dictionary encoding a Pauli-stochastic error model whereby the errors are the same on all the

create_locally_gate_independent_pauli_error_model(pspec, gate_errorrate_dict, measurement_errorrate_dict={}, ptype='uniform', idle1q_placeholder='I')

Returns a dictionary encoding a Pauli-stochastic error model whereby the errors are independent of the gates,

create_local_pauli_error_model(pspec, one_qubit_gate_errorrate_dict, two_qubit_gate_errorrate_dict, measurement_errorrate_dict={}, ptype='uniform')

Returns a dictionary encoding a Pauli-stochastic error model whereby the errors caused by a gate act

Attributes

_samp

pygsti.extras.rb.simulate._samp
pygsti.extras.rb.simulate.random_paulierror_in_chp(q)

todo.

pygsti.extras.rb.simulate.random_pauli_in_chp(q)

todo.

pygsti.extras.rb.simulate.stdgate_to_chp(gate, chpqubits)

todo Converts any of the standard Clifford gates to a chp string.

class pygsti.extras.rb.simulate.IndDepolErrorModel(gate_errors, readout_errors)

Bases: object

todo

layer_uniform_pauli_probability(self, layer, qubitorder)

todo.

readout_uniform_pauli_probability(self, qubitorder)

todo

pygsti.extras.rb.simulate.depolarizing_errors_circuit_simulator(circuitlist, shots, errormodel, gate_to_chp=None, aux_info_list=None, collision_action='keepseparate', outdir='', perge_chp_files=True, returnds=True, verbosity=1)

todo.

pygsti.extras.rb.simulate.circuit_simulator_for_tensored_independent_pauli_errors(circuit, pspec, errormodel, counts, alloutcomes=False, idle1q_placeholder='I')

A Clifford circuit simulator for an error model whereby each gate in the circuit induces independent Pauli errors on some or all of the qubits, with user-specified error probabilities that can vary between gate and between Pauli. State preparation and measurements errors are restricted to bit-flip errors on the output.

This simulator is a stochastic-unravelling simulator that uses an efficient-in-qubit-number representation of the action of Clifford gates on Paulis. Specifically, it samples Pauli errors according to the error statistics provided, and propogates them through the layers of Clifford gates in the circuit using the conjugation action of the Cliffords on Paulis (as represented by 2n X 2n symplectic matrices for n qubits). This is repeated for the number of counts (counts) requested. So, this function takes a time to run that scales as (counts * n^2 * circuit depth). Therefore, this method will be slower than the pyGSTi density-matrix simulators at low qubit number and high counts.

Parameters
  • circuit (Circuit) – The circuit to simulate. It should only contain gates that are also contained within the provided QubitProcessorSpec pspec and are Clifford gates.

  • pspec (QubitProcessorSpec) – The QubitProcessorSpec that defines the device. The Clifford model in QubitProcessorSpec should contain all of the gates that are in the circuit.

  • errormodel (dict) –

    A dictionary defining the error model. This errormodel should have keys that are Label objects (the elements of the circuit). The values for a particular Label is an (n,4) numpy array of floats, that encodes the errors caused by the gate specified by that Label. The (i,j) value in the array is the probability that this gate is followed by Pauli i where Pauli 0 = identity, Pauli 1 = X, Pauli 2 = Y and Pauli 3 = Z. So, if the arrray is [1.,0.,0.,0.] in every row then there is no errors, if it is [1-p,p/3,p/3,p/3] in row j then there is equal probability of each Pauli error on qubit j with an error probability of p.

    Some simple error models can be auto-constructed using create_locally_gate_independent_pauli_error_model() or create_iid_pauli_error_model()`.

  • counts (The number of counts, i.e., the number of repeats of the circuit that data should be generated for.) –

  • alloutcomes (bool, optional) – If True then a dictionary is returned where the keys are all possible outcomes (i.e., all length n bit strings) and the values are the counts for all of the outcomes. If False, then the returned dictionary only contains keys for those outcomes that happen at least once.

  • TODO (docstring: idle1q_placeholder) –

Returns

dict – A dictionary of simulated measurement outcome counts.

pygsti.extras.rb.simulate.oneshot_circuit_simulator_for_tensored_independent_pauli_errors(circuit, pspec, errormodel, idle1q_placeholder='I')

Generates a single measurement result for the circuit_simulator_for_tensored_independent_pauli_errors() simulator

Parameters
  • circuit (Circuit) – The circuit to simulate. It should only contain gates that are also contained within the provided QubitProcessorSpec pspec and are Clifford gates.

  • pspec (QubitProcessorSpec) – The QubitProcessorSpec that defines the device. The Clifford model in QubitProcessorSpec should contain all of the gates that are in the circuit.

  • errormodel (dict) – A dictionary defining the error model. This errormodel should have keys that are Label objects (the elements of the circuit). The values for a particular Label is an (n,4) numpy array of floats, that encodes the errors caused by the gate specified by that Label. The (i,j) value in the array is the probability that this gate is followed by Pauli i where Pauli 0 = identity, Pauli 1 = X, Pauli 2 = Y and Pauli 3 = Z. So, if the arrray is [1.,0.,0.,0.] in every row then there is no errors, if it is [1-p,p/3,p/3,p/3] in row j then there is equal probability of each Pauli error on qubit j with an error probability of p.

  • TODO (docstring: idle1q_placeholder) –

Returns

tuple – A tuple of values that are 0 or 1, corresponding to the results of a z-measurement on all the qubits. The ordering of this tuple corresponds to the ordering of the wires in the circuit.

pygsti.extras.rb.simulate.rb_with_pauli_errors(pspec, errormodel, lengths, k, counts, qubit_subset=None, filename=None, rbtype='DRB', rbspec=[], returndata=True, appenddata=False, verbosity=0, idle1q_placeholder='I')

Simulates RB with Pauli errors. Can be used to simulated Clifford RB, direct RB and mirror RB. This function:

  1. Samples RB circuits

  2. Simulates the RB circuit with the specified Pauli-errors error model

  3. Records the summary RB data to file and/or returns this RB data.

Step 1 is implemented using the in-built RB samplers. For more information see rb.sample. Step 2 is implemented using the circuit_simulator_for_tensored_independent_pauli_errors() stochastic errors circuit simulator. See that function for more details.

Parameters
  • pspec (QubitProcessorSpec) – The QubitProcessorSpec that defines the device.

  • errormodel (dict) –

    A dictionary defining the error model. This errormodel should have keys that are Label objects corresponding to the gates in pspec. The values for a particular Label is an (n,4) numpy array of floats, that encodes the errors caused by the gate specified by that Label. The (i,j) value in the array is the probability that this gate is followed by Pauli i where Pauli 0 = identity, Pauli 1 = X, Pauli 2 = Y and Pauli 3 = Z. So, if the arrray is [1.,0.,0.,0.] in every row then there is no errors, if it is [1-p,p/3,p/3,p/3] in row j then there is equal probability of each Pauli error on qubit j with an error probability of p.

    Some simple error models can be auto-constructed using create_locally_gate_independent_pauli_error_model() or create_iid_pauli_error_model()`.

  • lengths (list) – A list of the RB lengths to sample and simulate circuits at. E.g., for Clifford RB this is the number of Cliffords in the uncompiled circuit - 2 (see rb.sample.clifford_rb_circuit()).

  • k (int) – The number of circuits to sample and simulate at each RB length.

  • counts (int) – The number of counts for each circuit.

  • qubit_subset (list) – If not None, a list of qubit labels that the RB experiment should be over, that is a subset of the qubits in pspec.

  • filename (str, optional) – A filename for where to save the data (if None, the data is not saved to file).

  • rbtype ({'DRB', 'CRB', 'MRB'}) – The RB type to simulate. ‘DRB’ corresponds to direct RB, ‘CRB’ corresponds to Clifford RB, and ‘MRB’ corresponds to mirror RB.

  • rbspec (list, optional) – Handed to the RB sampling function for all arguments after pspec and the RB lengths, which are the first two arguments handed to the relevant function. See the relevant RB circuit sampling functions for details.

  • returndata (bool, optional) – Whether to return the data

  • appenddata (bool, optional) – If writing to file (i.e., filename is not None), whether to append the data to an already existing file or to write over any existing file.

  • verbosity (int, optional) – The amount of print-to-screen.

Returns

None or RBSummaryDataset – If returndata an RBSummaryDataset containing the results. Else, None

pygsti.extras.rb.simulate.create_iid_pauli_error_model(pspec, one_qubit_gate_errorrate, two_qubit_gate_errorrate, idle_errorrate, measurement_errorrate=0.0, ptype='uniform', idle1q_placeholder='I')

Returns a dictionary encoding a Pauli-stochastic error model whereby the errors are the same on all the 1-qubit gates, and the same on all 2-qubit gates. The probability of the 3 different Pauli errors on each qubit is specified by ptype and can either be uniform, or always X, Y, or Z errors.

The dictionary returned is in the appropriate format for the circuit_simulator_for_tensored_independent_pauli_errors() circuit simulator function.

Parameters
  • pspec (QubitProcessorSpec) – The QubitProcessorSpec that defines the device.

  • one_qubit_gate_errorrate (float) – The 1-qubit gates error rate (the probability of a Pauli error on the target qubit) not including idle gates.

  • two_qubit_gate_errorrate (float) – The 2-qubit gates error rate (the total probability of a Pauli error on either qubit the gate acts on – each qubit has independent errors with equal probabilities).

  • idle_errorrate (float) – The idle gates error rate.

  • measurement_errorrate (flip) – The measurement error rate for all of the qubits. This is the probability that a qubits measurement result is bit-flipped.

  • ptype (str, optional) – Can be ‘uniform’, ‘X’, ‘Y’ or ‘Z’. If ‘uniform’ then 3 Pauli errors are equally likely, if ‘X’, ‘Y’ or ‘Z’ then the errors are always Pauli X, Y or Z errors, respectively.

  • TODO (docstring idle1q_placeholder) –

Returns

dict – An dict that encodes the error model described above in the format required for the simulator circuit_simulator_for_tensored_independent_pauli_errors().

pygsti.extras.rb.simulate.create_locally_gate_independent_pauli_error_model(pspec, gate_errorrate_dict, measurement_errorrate_dict={}, ptype='uniform', idle1q_placeholder='I')

Returns a dictionary encoding a Pauli-stochastic error model whereby the errors are independent of the gates, with a qubit subject to an error after a circuit layer with the probabilities specified by the dict gate_errorrate_dict. The probability of the 3 different Pauli errors on each qubit is specified by ptype and can either be uniform, or always X, Y, or Z errors.

The dictionary returned is in the appropriate format for the circuit_simulator_for_tensored_independent_pauli_errors() circuit simulator function.

Parameters
  • pspec (QubitProcessorSpec) – The QubitProcessorSpec that defines the device.

  • gate_errorrate_dict (dict) – A dict where the keys are elements of pspec.qubit_labels and the values are floats in [0,1]. The element for qubit with label q is the error probability for that qubit.

  • measurement_errorrate_dict (dict) – A dict where the keys are elements of pspec.qubit_labels and the values are floats in [0,1]. The element for qubit with label q is the measurement bit-flip error probability for that qubit. All qubits that do not have a measurement error rate specified are assumed to have perfect measurements.

  • ptype (str, optional) – Can be ‘uniform’, ‘X’, ‘Y’ or ‘Z’. If ‘uniform’ then 3 Pauli errors are equally likely, if ‘X’, ‘Y’ or ‘Z’ then the errors are always Pauli X, Y or Z errors, respectively.

  • TODO (docstring: idle1q_placeholder) –

Returns

dict – An dict that encodes the error model described above in the format required for the simulator circuit_simulator_for_tensored_independent_pauli_errors().

pygsti.extras.rb.simulate.create_local_pauli_error_model(pspec, one_qubit_gate_errorrate_dict, two_qubit_gate_errorrate_dict, measurement_errorrate_dict={}, ptype='uniform')

Returns a dictionary encoding a Pauli-stochastic error model whereby the errors caused by a gate act only on the “target” qubits of the gate, all the 1-qubit gates on a qubit have the same error rate, and all the 2-qubit gates on a qubit have the same error rate. The probability of the 3 different Pauli errors on each qubit is specified by ptype and can either be uniform, or always X, Y, or Z errors.

The dictionary returned is in the appropriate format for the circuit_simulator_for_tensored_independent_pauli_errors() circuit simulator function.

Parameters
  • pspec (QubitProcessorSpec) – The QubitProcessorSpec that defines the device.

  • one_qubit_gate_errorrate_dict (dict) – A dict where the keys are elements of pspec.qubit_labels and the values are floats in [0,1]. The element for qubit with label q is the error probability for all 1-qubit gates on that qubit

  • two_qubit_gate_errorrate_dict (dict) – A dict where the keys are 2-qubit gates in pspec and the values are floats in [0,1]. This is the error probability for the 2-qubit gate, split evenly into independent Pauli errors on each of the qubits the gate is intended to act on.

  • measurement_errorrate_dict (dict) – A dict where the keys are elements of pspec.qubit_labels and the values are floats in [0,1]. The element for qubit with label q is the measurement bit-flip error probability for that qubit. All qubits that do not have a measurement error rate specified are assumed to have perfect measurements.

ptypestr, optional

Can be ‘uniform’, ‘X’, ‘Y’ or ‘Z’. If ‘uniform’ then 3 Pauli errors are equally likely, if ‘X’, ‘Y’ or ‘Z’ then the errors are always Pauli X, Y or Z errors, respectively.

Returns

dict – An dict that encodes the error model described above in the format required for the simulator circuit_simulator_for_tensored_independent_pauli_errors().