The BaseFaultTolerance Module

The BaseFaultTolerance module contains base classes for Quantum Error Correction and Quantum Fault Tolerance. These classes are generic; they require the user to provide the relevant algorithms when they are initialized. For specific quantum codes, see the Codes page. Note that only the Steane code is currently implemented.

class BaseFaultTolerance.BaseFaultTolerantMeasurement(*args, **kwargs)[source]

A class for implementing fault-tolerant measurement. NOT YET IMPLEMENTED.

Attributes
is_analysis_pass

Check if the pass is an analysis pass.

is_transformation_pass

Check if the pass is a transformation pass.

Methods

name()

Return the name of the pass.

run(dag)

Run a pass on the DAGCircuit.

class BaseFaultTolerance.Encoder(encoderCircuit, numAncillas)[source]

A class for implementing the non-fault tolerant ecoding of the Steane \(|0\rangle\) state.

Methods

createEncoderCircuit :

Creates a circuit encoding the \(|0\rangle\) state

createEncoderDag :

Creates a DAG encoding the \(|0\rangle\) state

getEncoderCircuit :

Adds gates encoding the \(|0\rangle\) state to a circuit

getEncoderDag :

Adds gates encoding the \(|0\rangle\) state to a DAG

createEncoderCircuit(numQubits)[source]

Creates a circuit encoding the specified number of qubits to the encoded \(|0\rangle\) state.

Parameters
numQubitsint

The number of qubits to initialize to the encoded \(|0\rangle\) state.

createEncoderDag(numQubits)[source]

Creates a DAG encoding the specified number of qubits to the encoded \(|0\rangle\) state.

Parameters
numQubitsint

The number of qubits to initialize to the encoded \(|0\rangle\) state.

getEncoderCircuit(circuit, qregs, cregs=None, ancillas=None)[source]

Encodes the specified Quantum Registers to the encoded \(|0\rangle\) state for the given circuit.

Parameters
dagDAGCircuit

The circuit for which to create the encoding.

qregslist(QuantumRegister)

The Quantum Registers to encode to the \(|0\rangle\).

cregslist(ClassicalRegister), Optional

The Classical Registers used to encode to the \(|0\rangle\), if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the cregs[i] classical register.

ancillaslist(AncillaRegister), list(QuantumRegister), Optional

The Ancilla Registers used to encode to the \(|0\rangle\), if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the ancillas[i] ancilla register.

getEncoderDag(dag, qregs, cregs=None, ancillas=None)[source]

Encodes the specified Quantum Registers to the encoded \(|0\rangle\) state for the given DAG.

Parameters
dagDAGCircuit

The circuit for which to create the encoding.

qregslist(QuantumRegister)

The Quantum Registers to encode to the \(|0\rangle\).

cregslist(ClassicalRegister), Optional

The Classical Registers used to encode to the \(|0\rangle\), if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the cregs[i] classical register.

ancillaslist(AncillaRegister), list(QuantumRegister), Optional

The Ancilla Registers used to encode to the \(|0\rangle\), if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the ancillas[i] ancilla register.

class BaseFaultTolerance.ErrorCorrector(syndromeDetector, syndromeCorrector)[source]

A class for implementing non-fault tolerant error correction (syndrome detection and correction) for an arbitrary error correction scheme. This class combines SyndromeDetection and SyndromeCorrection into a single class for ease of use.

Parameters
syndromeDetectorSyndromeDetector

An object representing syndrome detection.

syndromeCorrectorSyndromeCorrector

An object representing syndrome correction.

Methods

errorCorrectCircuit :

Implements error correction for the given circuit.

errorCorrecDag :

Implements error correction for the given DAG.

errorCorrectCircuit(circuit, qregs, cregs=None, ancillas=None)[source]

Creates gates implementing fault tolerant error correction for the given qubits in the given circuit.

Parameters
circuitQuantumCircuit

The circuit for which to perform error correction.

qregslist(QuantumRegister)

The Quantum Registers to on which to perform error correction.

cregslist(ClassicalRegister)

The Classical Registers used to perform error correction, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the syndrome correction process for the qregs[i] quantum register will use the cregs[i] classical register.

errorCorrectDag(dag, qregs, cregs=None, ancillas=None)[source]

Creates gates implementing non-fault tolerant error correction for the given qubits in the given DAG.

Parameters
dagDAGCircuit

The dag for which to perform error correction.

qregslist(QuantumRegister)

The Quantum Registers to on which to perform error correction.

cregslist(ClassicalRegister)

The Classical Registers used to perform error correction, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the syndrome correction process for the qregs[i] quantum register will use the cregs[i] classical register.

class BaseFaultTolerance.FaultTolerance(*args, **kwargs)[source]

A Transpiler pass that converts a given quantum computation into an equivalent one with error correction. NOT YET IMPLEMENTED

Attributes
is_analysis_pass

Check if the pass is an analysis pass.

is_transformation_pass

Check if the pass is a transformation pass.

Methods

name()

Return the name of the pass.

run()

Run a pass on the DAGCircuit.

run()[source]

Run a pass on the DAGCircuit. This is implemented by the pass developer.

Args:

dag (DAGCircuit): the dag on which the pass is run.

Raises:

NotImplementedError: when this is left unimplemented for a pass.

class BaseFaultTolerance.FaultTolerantEncoder(encoder, checkerCircuit, numAncillas, correctVal, numRepeats)[source]

A class for implementing an fault tolerant ecoding of the \(|0\rangle\) state for an arbitrary quantum code.

Parameters
encoderEncoder

An Encoder object representing the \(|0\rangle\) state non-fault tolerant encoding process.

checkerCircuitQuantumCircuit

A circuit for determining whether the \(|0\rangle\) state has been encoded properly.

numAncillasint

The number of ancilla qubits used to check the encoded effect. Note: the ancilla qubits must be at the end of the list of qubits for the circuit.

correctValint

The classical register value corresponding to the correct initialization of the encoded \(|0\rangle\) state.

numRepeatsint

The number of times to attempt to create the encoded \(|0\rangle\) state.

Methods

createEncoderCircuit :

Creates a circuit encoding the \(|0\rangle\) state

createEncoderDag :

Creates a DAG encoding the \(|0\rangle\) state

getEncoderCircuit :

Adds gates encoding the \(|0\rangle\) state to a circuit

getEncoderDag :

Adds gates encoding the \(|0\rangle\) state to a DAG

createEncoderCircuit(numQubits)[source]

Creates a circuit fault-tolerantly encoding the specified number of qubits to the encoded \(|0\rangle\) state.

Parameters
numQubitsint

The number of qubits to initialize to the encoded \(|0\rangle\) state.

createEncoderDag(numQubits)[source]

Creates a DAG fault-tolerantly encoding the specified number of qubits to the encoded \(|0\rangle\) state.

Parameters
numQubitsint

The number of qubits to initialize to the encoded \(|0\rangle\) state.

getEncoderCircuit(circuit, qregs, cregs1=None, ancillas1=None, cregs2=None, ancillas2=None)[source]

Fault-tolerantly encodes the specified Quantum Registers to the encoded \(|0\rangle\) state for the given circuit.

Parameters
dagDAGCircuit

The circuit for which to create the encoding.

qregslist(QuantumRegister)

The Quantum Registers to encode to the \(|0\rangle\).

cregslist(ClassicalRegister), Optional

The Classical Registers used to encode to the \(|0\rangle\), if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the cregs[i] classical register.

ancillaslist(AncillaRegister), list(QuantumRegister), Optional

The Ancilla Registers used to encode to the \(|0\rangle\), if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the ancillas[i] ancilla register.

getEncoderDag(dag, qregs, cregs1=None, ancillas1=None, cregs2=None, ancillas2=None)[source]

Fault-tolerantly encodes the specified Quantum Registers to the encoded \(|0\rangle\) state for the given DAG.

Parameters
dagDAGCircuit

The circuit for which to create the encoding.

qregslist(QuantumRegister)

The Quantum Registers to encode to the \(|0\rangle\).

cregslist(ClassicalRegister), Optional

The Classical Registers used to encode to the \(|0\rangle\), if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the cregs[i] classical register.

ancillaslist(AncillaRegister), list(QuantumRegister), Optional

The Ancilla Registers used to encode to the \(|0\rangle\), if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(cregs) == len(qregs) and the encoding process for the qregs[i] quantum register will use the ancillas[i] ancilla register.

class BaseFaultTolerance.FaultTolerantGates(gatesToCircuit)[source]

A class for implementing fault tolerant gates for an arbitrary quantum error correction code.

Parameters
gatesToCircuitmap(str, (QuantumCircuit, int))

A map representing conversions between gates and circuits implementing fault tolerant versions of those gates. The keys of the map are the QASM label for the gate in question, given by gate.qasm(). The outputs of the map are tuples of the form (circuit, numAncillas), where circuit is a fault-tolerant implementation of a gate and numAncillas is the number of ancillas qubits used in the fault-tolerant implementation of the gate.

Methods

addGateCircuit :

Adds a fault tolerant gate to the given circuit.

addGateDag :

Adds a fault tolerant gate to the given DAG.

addGateCircuit(circuit, gate, qregs, cregs=None, ancillas=None)[source]

Adds the specified number of fault tolerant implementations of a quantum gate to the given circuit.

Parameters
circuitQuantumCircuit

The circuit on which to perform the fault tolerant gate.

gateGate

The non-fault tolerant gate for which to implement a fault tolerant version.

qregslist(list(QuantumRegister))

The Quantum Registers to on which to perform the fault tolerant gate. Each qregs[i] represents the list of quantum registers which correspond to the ith input to the non-fault tolerant version of the gate in question. Note that each qregs[i] must have the same length.

cregslist(list(ClassicalRegister)), Optional

The Classical Registers used to perform syndrome detection, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs[0]) and the syndrome detection process for the qregs[i][j] quantum register will use the cregs[j] classical register.

ancillaslist(list(AncillaRegister)), list(list(QuantumRegister)), Optional

The Ancilla Registers used to perform syndrome detection,, if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(qregs[0]) and the syndrome detection process for the qregs[i][j] quantum register will use the ancillas[j] ancilla register.

addGateDag(dag, gate, qregs, cregs=None, ancillas=None)[source]

Adds the specified number of fault tolerant implementations of a quantum gate to the given DAG.

Parameters
dagDAGCircuit

The dag on which to perform the fault tolerant gate.

gateGate

The non-fault tolerant gate for which to implement a fault tolerant version.

qregslist(list(QuantumRegister))

The Quantum Registers to on which to perform the fault tolerant gate. Each qregs[i] represents the list of quantum registers which correspond to the ith input to the non-fault tolerant version of the gate in question. Note that each qregs[i] must have the same length.

cregslist(list(ClassicalRegister)), Optional

The Classical Registers used to perform syndrome detection, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs[0]) and the syndrome detection process for the qregs[i][j] quantum register will use the cregs[j] classical register.

ancillaslist(list(AncillaRegister)), list(list(QuantumRegister)), Optional

The Ancilla Registers used to perform syndrome detection,, if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(qregs[0]) and the syndrome detection process for the qregs[i][j] quantum register will use the ancillas[j] ancilla register.

class BaseFaultTolerance.SyndromeCorrector(correctorCircuit)[source]

A class for implementing fault tolerant syndrome correction for an arbitrary error correction scheme.

Parameters
correctorCircuitQuantumCircuit

A Quantum Circuit implementing fault tolerant syndrome correction for a single qubit.

Methods

syndromeCorrectCircuit :

Implements syndrome correction for the given circuit.

syndromeCorrectDag :

Implements syndrome correction for the given DAG.

syndromeCorrectCircuit(circuit, qregs, cregs)[source]

Creates gates implementing fault tolerant syndrome correction for the given qubits in the given circuit.

Parameters
circuitQuantumCircuit

The circuit for which to perform syndrome correction.

qregslist(QuantumRegister)

The Quantum Registers to on which to perform syndrome correction.

cregslist(ClassicalRegister)

The Classical Registers used to perform syndrome correction, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the syndrome correction process for the qregs[i] quantum register will use the cregs[i] classical register.

syndromeCorrectDag(dag, qregs, cregs)[source]

Creates gates implementing fault tolerant syndrome correction for the given qubits in the given DAG.

Parameters
dagDAGCircuit

The dag for which to perform syndrome correction.

qregslist(QuantumRegister)

The Quantum Registers to on which to perform syndrome correction.

cregslist(ClassicalRegister)

The Classical Registers used to perform syndrome correction, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the syndrome correction process for the qregs[i] quantum register will use the cregs[i] classical register.

class BaseFaultTolerance.SyndromeDetector(detectorCircuit, numAncillas)[source]

A class for implementing non-fault tolerant syndrome detection for an arbitrary error correction scheme.

Parameters
detectorCircuitQuantumCircuit

A Quantum Circuit implementing non-fault tolerant syndrome detection.

numAncillasint

The number of ancilla qubits used in the syndrome detection.

Methods

syndromeDetectCircuit :

Implements syndrome detection for the given circuit.

syndromeDetectDag :

Implements syndrome detection for the given DAG.

syndromeDetectCircuit(circuit, qregs, cregs=None, ancillas=None)[source]

Creates gates implementing non-fault tolerant syndrome detection for the given qubits in the given circuit.

Parameters
circuitQuantumCircuit

The circuit for which to perform syndrome detection.

qregslist(QuantumRegister)

The Quantum Registers to on which to perform syndrome detection.

cregslist(ClassicalRegister), Optional

The Classical Registers used to perform syndrome detection, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the syndrome detection process for the qregs[i] quantum register will use the cregs[i] classical register.

ancillaslist(AncillaRegister), list(QuantumRegister), Optional

The Ancilla Registers used to perform syndrome detection,, if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(cregs) == len(qregs) and the syndrome detection process for the qregs[i] quantum register will use the ancillas[i] ancilla register.

syndromeDetectDag(dag, qregs, cregs=None, ancillas=None)[source]

Creates gates implementing non-fault tolerant syndrome detection for the given qubits in the given DAG.

Parameters
dagDAGCircuit

The DAG for which to perform syndrome detection.

qregslist(QuantumRegister)

The Quantum Registers to on which to perform syndrome detection.

cregslist(ClassicalRegister), Optional

The Classical Registers used to perform syndrome detection, if classical registers are needed. If cregs is provided, it must satisfy len(cregs) == len(qregs) and the syndrome detection process for the qregs[i] quantum register will use the cregs[i] classical register.

ancillaslist(AncillaRegister), list(QuantumRegister), Optional

The Ancilla Registers used to perform syndrome detection,, if ancilla registers are needed. If ancillas is provided, it must satisfy len(ancillas) == len(cregs) == len(qregs) and the syndrome detection process for the qregs[i] quantum register will use the ancillas[i] ancilla register.