Decomposition

Expand a function call in the editor into its underlying Qubi source or into flat gates. Decomposition works on expandable functions (blackbox: false), including Grover, QFT, Deutsch, and your own unencapsulated routines.

Where to find it

In the Circuit Builder toolbar, hover the four-square Decompose button (visible when the file contains function calls). Choose Partial or Full. The editor replaces the call line in the main layer with the expansion result.

Partial decomposition

Produces an editable copy of the function body for the specific call:

  • Prelude assignments bind call arguments (target = 0b1011, arg = (target, 0..(len(target)-1))).
  • All if / elseif / else branches stay in the source, including unreachable guards.
  • Local variables, LOOP headers, and ANNOTATE spans are preserved.
  • argmax in the body becomes len(arg)-1.

Use partial decompose to read how Grover picks wires, to tweak oracle logic, or to study algorithm structure before flattening.

Full decomposition

Flattens into executable gates and loops:

  • Statically false if branches are removed; taken paths are inlined.
  • Annotations and labels are dropped.
  • Variables inside loops are resolved per iteration (so counters like ti++ unroll correctly).
  • LOOP blocks remain when the count is still symbolic; fixed counts unroll when possible.

You can run partial first, inspect the prelude, then full-decompose the result to get raw H, CX, and CZ lines. Chaining partial → full matches decomposing the original call in one step.

Limits

  • Encapsulated / blackbox functions (single tile on the diagram) have no inspectable body to expand.
  • Built-in matrix gates (H, CX, …) are already atomic; decomposition targets function calls only.
  • When argument expressions cannot bind (missing import, wrong arity), the tool reports an error and leaves the line unchanged.