mimiqcircuits.decomposition.basis.qasm

OpenQASM 2.0 decomposition basis.

Classes

QASMBasis()

Decomposition basis targeting the OpenQASM 2.0 gate library.

class mimiqcircuits.decomposition.basis.qasm.QASMBasis[source]

Bases: DecompositionBasis

Decomposition basis targeting the OpenQASM 2.0 gate library.

The terminal gates are the OpenQASM 2.0 built-ins and the gates of the qelib1.inc include file that have a direct MIMIQ counterpart, so a decomposed circuit can be written as OpenQASM 2.0 and read back by any parser that ships the standard qelib1.inc.

Terminal Operations

Fundamental gates (OpenQASM 2.0 built-in):
  • GateU, GateCX

Single-qubit gates from qelib1.inc:
  • Legacy U gates: GateU3, GateU2, GateU1

  • Pauli: GateID, GateX, GateY, GateZ

  • Hadamard: GateH

  • Phase: GateS, GateSDG, GateT, GateTDG

  • Rotations: GateRX, GateRY, GateRZ

Two-qubit gates from qelib1.inc:
  • Controlled Paulis and Hadamard: GateCY, GateCZ, GateCH

  • Controlled rotations: GateCRX, GateCRY, GateCRZ

  • GateSWAP

  • Ising couplings: GateRXX, GateRZZ

Three- and four-qubit gates from qelib1.inc:
  • GateCCX, GateCSWAP, GateC3X

Non-unitary operations:
  • Measure, Reset, Barrier

  • IfStatement whose inner operation is terminal

Custom gates:
  • GateCall whose declaration contains only terminal operations

Every other operation is decomposed through CanonicalRewrite. Operations that OpenQASM 2.0 cannot express and that have no decomposition into the gates above (noise channels, classical operations, annotations, Z-register operations, …) raise DecompositionError.

MeasureReset decomposes into Measure followed by Reset. This leaves the same state and bit as its canonical decomposition, a measurement and an X conditioned on its outcome, and unlike that conditional it can be written for a circuit of any number of bits. OpenQASM 2.0 has no loops, so WhileStatement raises DecompositionError.

Example

>>> from mimiqcircuits import Circuit, GateH, GateCCX
>>> from mimiqcircuits.decomposition import decompose, QASMBasis
>>> c = Circuit()
>>> c.push(GateH(), 0)
1-qubit circuit with 1 instruction:
└── H @ q[0]

>>> c.push(GateCCX(), 0, 1, 2)
3-qubit circuit with 2 instructions:
├── H @ q[0]
└── C₂X @ q[0:1], q[2]

>>> # Decompose to QASM-compatible gates
>>> qasm_circuit = decompose(c, QASMBasis())

See also

CanonicalBasis, CliffordTBasis, StimBasis

isterminal(op)[source]

Check if an operation is terminal in the OpenQASM 2.0 basis.

Parameters:

op (Operation) – The operation to check.

Returns:

True if the operation is in the QASM gate set.

Return type:

bool

decompose(op, qubits, bits, zvars)[source]

Decompose a non-terminal operation using canonical rewrite.

Parameters:
  • op (Operation) – The operation to decompose.

  • qubits (Sequence[int]) – Qubit indices for the operation.

  • bits (Sequence[int]) – Classical bit indices for the operation.

  • zvars (Sequence[int]) – Z-variable indices for the operation.

Returns:

A Circuit containing the decomposed instructions.

Raises:

DecompositionError – If the operation cannot be decomposed.

Return type:

Circuit