mimiqcircuits.decomposition.basis.flattened¶
Flattened decomposition basis.
Classes
Decomposition basis that expands containers and keeps every other operation. |
- class FlattenedBasis[source]¶
Bases:
DecompositionBasisDecomposition basis that expands containers and keeps every other operation.
GateCall,BlockandBlockCall, and theInverseof aGateCall, are expanded withFlattenContainersuntil none is left, at any depth. AnIfStatementwhose body is a container becomes one conditional instruction per instruction of the body. Gates are not decomposed, and that includes aGateCallwrapped inControl,Power,ParallelorRepeat, 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]
- decompose(op, qubits, bits, zvars)[source]¶
Expand one level of a container.
- Parameters:
- Returns:
A new
Circuitwith the contents ofop, each made conditional ifopis anIfStatement.- Raises:
DecompositionError – If
opis not a container.- Return type: