mimiqcircuits.decomposition.basis.flattened

Flattened decomposition basis.

Classes

FlattenedBasis()

Decomposition basis that expands containers and keeps every other operation.

class FlattenedBasis[source]

Bases: DecompositionBasis

Decomposition basis that expands containers and keeps every other operation.

GateCall, Block and BlockCall, and the Inverse of a GateCall, are expanded with FlattenContainers until none is left, at any depth. An IfStatement whose body is a container becomes one conditional instruction per instruction of the body. Gates are not decomposed, and that includes a GateCall wrapped in Control, Power, Parallel or Repeat, which is kept.

Examples

>>> from mimiqcircuits import *
>>> # a declared gate that holds a Bell-pair preparation
>>> bell = GateDecl("bell", (), Circuit().push(GateH(), 0).push(GateCX(), 0, 1))
>>> c = Circuit()
>>> c.push(bell(), 0, 1)
2-qubit circuit with 1 instruction:
└── bell() @ q[0:1]

>>> c.push(GateSWAP(), 0, 1)
2-qubit circuit with 2 instructions:
├── bell() @ q[0:1]
└── SWAP @ q[0:1]

>>> # the call is expanded; SWAP is a gate and is kept
>>> decompose(c, FlattenedBasis())
2-qubit circuit with 3 instructions:
├── H @ q[0]
├── CX @ q[0], q[1]
└── SWAP @ q[0:1]
isterminal(op)[source]

Check whether an operation is kept, that is not a container.

Parameters:

op (Operation) – The operation to check.

Returns:

False for the containers listed in the class description and for an IfStatement whose body is one, True otherwise.

Return type:

bool

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

Expand one level of a container.

Parameters:
  • op (Operation) – The container, or the IfStatement of one, to expand.

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

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

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

Returns:

A new Circuit with the contents of op, each made conditional if op is an IfStatement.

Raises:

DecompositionError – If op is not a container.

Return type:

Circuit