Module circuit_parser

class CircuitToString(basis_gates, measurements, full_state_projection=False)[source]

Bases: object

Contains the translational elements to convert the Qiskit circuits to cQASM code.

Parameters:
  • basis_gates (List[str]) – List of basis gates from the configuration.

  • measurements (Measurements) – The measured qubits/classical bits and the number of qubits and classical bits.

  • full_state_projection (bool) – When full_state_projection = True, no measurement statements are added.

static get_mask_data(mask)[source]

Get mask data

A mask is a continuous set of 1-bits with a certain length. This method returns the lowest bit of the mask and the length of the mask.

Examples:

76543210

bit_nr

00111000

lowest mask bit = 3, mask_length = 3

00000001

lowest mask bit = 0, mask_length = 1

11111111

lowest mask bit = 0, mask_length = 8

10000000

lowest mask bit = 7, mask_length = 1

Parameters:

mask (int) – The mask to get the mask data from.

Returns:

The mask data, i.e. a tuple (lowest_bit_number, mask_length)

Return type:

Tuple[int, int]

parse(stream, instruction)[source]

Parses a gate.

For each type of gate a separate (private) parsing method is defined and called. The resulting cQASM code is written to the stream. When the gate is a binary controlled gate, Qiskit uses two instructions to handle it. The first instruction is a so-called bfunc with the conditional information (mask, value to check etc.) which is stored for later use. The next instruction is the actual gate which must be executed conditionally. The parsing is forwarded to method _parse_bin_ctrl_gate which reads the earlier stored bfunc. When a gate is not supported _gate_not_supported is called which raises an exception.

Parameters:
  • stream (StringIO) – The string-io stream to where the resulting cQASM is written.

  • instruction (QasmQobjInstruction) – The Qiskit instruction to translate to cQASM.

Return type:

None