mimiqcircuits.decomposition.rules.flatten_containers¶
Rewrite rule for flattening container operations.
Classes
Rewrite rule that expands container operations into their contents. |
- class FlattenContainers[source]¶
Bases:
RewriteRuleRewrite rule that expands container operations into their contents.
Matches
GateCall,Block,BlockCall, and theInverseof aGateCall, and replaces each by the instructions it holds (inverted for anInverse), remapped onto the targets. One step expands one level: nested containers stay as they are. Gates are never decomposed.FlattenedBasisrepeats this rule until no container is left.Examples
>>> from mimiqcircuits import * >>> # declare a gate that prepares a Bell pair, and call it >>> bell = GateDecl("bell", (), Circuit().push(GateH(), 0).push(GateCX(), 0, 1)) >>> c = Circuit() >>> c.push(bell(), 2, 3) 4-qubit circuit with 1 instruction: └── bell() @ q[2:3] >>> # the call is replaced by its body, on qubits 2 and 3 >>> decompose_step(c, FlattenContainers()) 4-qubit circuit with 2 instructions: ├── H @ q[2] └── CX @ q[2], q[3]
- decompose_step(op, qubits, bits, zvars)[source]¶
Expand one level of a container operation.
- Parameters:
- Returns:
A new
Circuitwith the contents ofopon those indices.- Raises:
DecompositionError – If
opis not a container this rule matches.- Return type: