circuits module

Class to handle logical qubits for the Steane and Bacon Shor code

class circuits.BaconShorCodeLogicalQubit(d, data_qubits, ancilla_qubits, ancillas, blocks, logical_one, logical_z, set_barrier=True)

Bases: qiskit.circuit.quantumcircuit.QuantumCircuit

Generates the gates for one logical Qubits of the Bacon Shor code

Parameters
  • d (int) – Number of logical “data” qubits to be initialised. Should be either 1 or 2 at present. Only the case with 1 qubit has been fully tested.

  • data_qubits (int) – Number of data qubits. Usually nine.

  • ancilla_qubits (int) – Number of ancilla qubits. Usually two.

  • ancilla (int) – Number of ancilla. Usually two for X and Z.

  • blocks (int) – Number of blocks

  • logical_z (bool) – True if a logical z is set up. Otherwise false

ancilla_dummy_gates(logical_qubit=0)

sets up a set of dummy ‘id’ gates against which noise is applied for each ancilla

Parameters

logical_qubit (int) – Number of the logical “data” qubit to measure. Should be either 0 or 1 at present.

define_data()

Defines empty lists

define_registers(d)

Set up registers to be used based on the number of logical qubits and whether error checking is needed.

Parameters

d (int) – Number of the logical “data” qubits to be initialised. Should be either 0 or 1 at present.

Notes

The registers are stored in a list so that they can be indexed to simplify subsequent code.

encoding_ft(logical_qubit=0)

Adds an encoding non fault tolerant gate.

Parameters

logical_qubit (int) – Number of the logical “data” qubit to encode. Should be either 0 or 1 at present.

encoding_nft(logical_qubit=0)

Adds an encoding non fault tolerant gate.

Parameters
  • logical_qubit (int) – Number of the logical “data” qubit to encode. Should be either 0 or 1 at present.

  • logical_one (Bool) – If true set up the logical one. Otherwise set up the logical zero.

logical_measure(logical_qubit=0)

Function to measure a logical qubit

Parameters

logical_qubit (int) – Number of the logical “data” qubit to measure. Should be either 0 or 1 at present.

reset_stabilizers(logical_qubit=0)

Function to reset all ancilla

Parameters

logical_qubit (int) – Number of the logical “data” qubit to set up ancilla for. Should be either 0 or 1 at present.

x_stabilizers(logical_qubit=0)

Function to set up x stabilizers or ancilla

Parameters

logical_qubit (int) – Number of the logical “data” qubit to set up ancilla for. Should be either 0 or 1 at present.

x_testing(logical_qubit=0, test_x_qubit=0)

Introduces one X error

Parameters
  • logical_qubit (int) – Number of the logical “data” qubit to test. Should be either 0 or 1 at present.

  • test_x_qubit (int) – Qubit on which X error is introduced

z_stabilizers(logical_qubit=0)

Function to set up z stabilizers or ancilla

Parameters

logical_qubit (int) – Number of the logical “data” qubit to set up ancilla for. Should be either 0 or 1 at present.

z_testing(logical_qubit=0, test_z_qubit=0)

Introduces one Z error

Parameters
  • logical_qubit (int) – Number of the logical “data” qubit to test. Should be either 0 or 1 at present.

  • test_z_qubit (int) – Qubit on which Z error is introduced

class circuits.SteaneCodeLogicalQubit(d, parity_check_matrix, codewords, ancilla=True, extend_ancilla=False, fault_tolerant_b=False, fault_tolerant_c=False, fault_tolerant_ancilla=False, ancilla_rounds=1, data_rounds=1, set_barrier=True)

Bases: qiskit.circuit.quantumcircuit.QuantumCircuit

Generates the gates for one or two logical Qubits of the Steane code

Parameters
  • d (int) – Number of logical “data” qubits to be initialised. Should be either 1 or 2 at present.

  • parity_check_matrix (list) – Holds the parity check matrix from which the gates will be constructed.

  • codewords (list) – Valid codewords for the Steane code

  • ancilla (bool) – True if need to set up ancilla. For some circuits these are not needed.

  • extend_ancilla (bool) – True if need to add extra ancilla for error correction without using MCT gates

  • fault_tolerant_b (bool) – True if need to set up scheme c for fault tolerant encoding with three rounds of measurement on the second logical qubit.

  • fault_tolerant_c (bool) – True if need to set up an extra qubit for fault tolerance

  • fault_tolerant_ancilla (bool) – True if need to set up fault tolerant ancilla

  • ancilla_rounds (int) – Number of rounds of ancilla measurement for fault tolerant ancilla

  • data_round (int) – Number of rounds of ancilla measurement for fault tolerant encoding

  • self_barrier (bool) – If true then barriers will be set.

Notes

Uses super to inherit methods from QuantumCircuit parent. The code is derived from the parity matrix. The parity matrix is validated to ensure each row is orthogonal to each valid codeword. The number of data qubits is calculated from the length of rows in the parity matrix. The number of ancilla is calculated from the number of columns in the parity matrix. Ancilla qubits are only set up if needed. For error correction without MCT gates extra ancilla are set up. An extra qubit can be added for a fault tolerant logical zero. Extra classical measurement ancilla are set up if there is more than one ancilla measurement round.

correct_errors(logical_qubit=0, mct=False)

Produces circuit to correct errors.

Parameters
  • logical_qubit (int) – Number of the logical “data” qubits on which to correct error. Should be either 0 or 1 at present.

  • mct (bool) – Controls whether an MCT gate shall be used

Notes

Need to swap ancilla bits to match how printed out. Reads through parity matrix to determine the corrections to be applied.

The error correcting circuit is either set up with MCT gates, which is simpler but needs more gates, or without MCT gates, which is more difficult to program but needs less gates. In the latter case corrections already applied need to be taken into account

when looking at

two or three bit corrections.

In both cases the error correcting gates are determined from the parity matrix.

The errors detected by the Z operators are bit flips, so are corrected by CX gates. The errors detected by the X operators are phase flips, so are corrected by CZ gates.

decode(logical_qubit=0, reduced=True, simple=False)

Un-computes setting up logical zero for data qubit.

Parameters
  • logical_qubit (int) – Number of the logical “data” qubits to set up logical zero for. Should be either 0 or 1 at present.

  • reduced (bool) – Checks to see if any gates are duplicated

  • simple (bool) – Simple decoding scheme when full logical zero is not required.

Notes

The full circuit reverses the encoding circuit. The gates needed are determined from the parity matrix.

For the simple decoding the logical status is determined from the parity of three bits.

define_data()

define standing data

Notes

The ancilla qubits for the X operator are self.__mx The ancilla qubits for the Z operator are self.__mz

There are more ancilla qubits if there are fault tolerant ancilla. In this case the classical measurement bits can support multiple rounds of measurement.

Also, multiple classical rounds of measurement are supported for Goto’s schemes b and c. In scheme b the multiple classical rounds are only on the second qubit.

define_registers(d)

Set up registers to be used based on number of logical qubits and whether error checking is needed.

Parameters

d (int) – Number of logical “data” qubits to be initialised. Should be either 0 or 1 at present.

Notes

The quantum and classical registers are stored in a list so that they can be indexed by logical qubit to simplify subsequent code. The registers needed depend on the number of logical qubits, whether extra ancilla qubits are needed for fault tolerance and the number of round of measurements needed.

dummy_decoding(input_string, logical_qubit=0)

Instead of the full decoding circuit a dummy circuit is set up for testing.

Parameters
  • input_string (str) – String to control gates set up

  • logical_qubit (int) – Number of the logical “data” qubits to apply logical Z gate on. Should be either 0 or 1 at present.

Notes

This function is not currently used by any workbook but is retained in case it is useful in future.

encode_fault_tolerant_method_C(control_qubits, logical_qubit=0)

Use a new qubit to encode fault tolerantly

Parameters
  • control_qubits (list) – List of control qubits

  • logical_qubit (int) – Number of the logical “data” qubits to encode fault tolerantly. Should be either 0 or 1 at present.

Notes

Uses Goto’s method C

force_X_error(physical_qubit, logical_qubit=0)

Introduce an X error on one physical qubit

Parameters
  • physical_qubit (int) – Number of qubit to force X error on.

  • logical_qubit (int) – Number of the logical “data” qubits to force error on. Should be either 0 or 1 at present.

force_Z_error(physical_qubit, logical_qubit=0)

Introduce Z error on one physical qubit

Parameters
  • physical_qubit (int) – Number of qubit to force Z error on.

  • logical_qubit (int) – Number of the logical “data” qubits to force error on. Should be either 0 or 1 at present.

list_data_qubits()

Returns a list of data qubits

Returns

output_list – list of data qubits

Return type

list

logical_data_reset(logical_qubit=0)

Resets the data for a logical qubit

Parameters

logical_qubit (int) – Number of the logical “data” qubits to reset. Should be either 0 or 1 at present.

Notes

This function is needed for a fault tolerant encoding scheme. Usually the data qubits are reset as part of setting up the logical zero. In one scheme the logical zero is not set up, but a reset is still needed.

logical_gate_CX(logical_control_qubit, logical_target_qubit)

Apply a logical CX gate

Parameters
  • logical_control_qubit (int) – Number of the logical “data” qubit which controls the CX gate

  • logical_target_qubit (int) – Number of the logical “data” qubit which is the target for the CX gate

logical_gate_H(logical_qubit=0)

Apply a logical H gate

Parameters

logical_qubit (int) – Number of the logical “data” qubits to apply Hadamard on. Should be either 0 or 1 at present.

logical_gate_X(logical_qubit=0)

Apply a logical X gate

Parameters

logical_qubit (int) – Number of the logical “data” qubits to apply logical X gate to. Should be either 0 or 1 at present.

logical_gate_Z(logical_qubit=0)

Apply a logical Z gate

Parameters

logical_qubit (int) – Number of the logical “data” qubits to apply logical Z gate on. Should be either 0 or 1 at present.

logical_measure_ancilla(logical_qubit=0, ancilla_round=1)

Makes measurement of the ancilla qubits of a logical qubit.

Parameters
  • logical_qubit (int) – Number of the logical “data” qubits to measure. Should be either 0 or 1 at present.

  • ancilla_round (int) – Round of ancilla measurement. Can be more than one for fault tolerant ancilla.

Notes

If there is more than one ancilla round of measurement the classical measurements bit created above can be used. For example, if there are three rounds of measuremement three classical measurement bits are created, one for each round.

logical_measure_data(logical_qubit=0)

Makes measurement of the data qubits of a logical qubit.

Parameters
  • logical_qubit (int) – Number of the logical “data” qubits to measure. Should be either 0 or 1 at present.

  • measure_round (int) – Round of data measurement. Can be more than one for scheme B or C.

Notes

For Scheme B there are normally three rounds of measuremement for the second logical qubit and three classical measurement bits are created, one for each round. For Scheme C there are also normally three rounds of measurement.

logical_measure_data_FT(logical_qubit=0, measure_round=1)

Makes measurement of the data qubits of a logical qubit needed for FT schemes

Parameters
  • logical_qubit (int) – Number of the logical “data” qubits to measure. Should be either 0 or 1 at present.

  • measure_round (int) – Round of data measurement. Can be more than one for scheme B or C.

Notes

For Scheme B there are normally three rounds of measuremement for the second logical qubit and three classical measurement bits are created, one for each round. For Scheme C there are also normally three rounds of measurement.

set_up_ancilla(logical_qubit=0)

Set up gates for ancilla based on entries in the parity matrix

Parameters

logical_qubit (int) – Number of the logical “data” qubits to set up ancilla gates for. Should be either 0 or 1 at present.

Notes

The ancilla needed are determined from the parity matrix. Fault tolerant logic sets up four ancilla qubits, set these up in a GHZ, and then apply a CZ gate to each one individually and then decomputes the GHZ gate.

set_up_logical_zero(logical_qubit=0, reduced=True, logical_one=False)

Set up logical zero for data qubit

Parameters
  • logical_qubit (int) – Number of the logical “data” qubit to initialise. Should be either 0 or 1 at present.

  • reduced (bool) – Checks to see if any gates are duplicated

  • logical_one (bool) – Add extra gates to set up a logical one

Notes

Columns of the parity matrix with only one entry are prepared in the + state. CX gates are set up from these + state to data qubits associated with parity matrix entries in the same row which are unity.

If reduced = True possible unnecessary duplicate CX gates are identified. If possible two CX gates are removed and replaced by one new CX gates.

validate_parity_matrix()

Validate the parity matrix against the allowed codewords