CQCL / tket

Source code for the TKET quantum compiler, Python bindings and utilities
https://docs.quantinuum.com/tket/
Apache License 2.0
256 stars 48 forks source link

Make classical registers optional arguments in `Circuit.add_circbox_with_regmap` and `Circuit.add_circbox_regwise` #1368

Open CalMacCQ opened 6 months ago

CalMacCQ commented 6 months ago

As it stands currently cregmap and cregs are non-optional arguments to Circuit.add_circbox_with_regmap) and Circuit.add_circbox_regwise

See the section of the user manual -> https://tket.quantinuum.com/user-manual/manual_circuit.html#circuit-boxes

Consider the following example...

from pytket.circuit import Circuit, CircBox

qpe_circ = Circuit()
a = qpe_circ.add_q_register("a", 2)
s = qpe_circ.add_q_register("s", 1)

qpe_circ.H(a[0])
qpe_circ.CU1(0.94, a[1], s[0])

qpe_box = CircBox(qpe_circ)

algorithm_circ = Circuit()
ancillas = algorithm_circ.add_q_register("ancillas", 2)
state = algorithm_circ.add_q_register("state", 1)
algorithm_circ.X(state[0])

algorithm_circ.add_circbox_with_regmap(qpe_box, qregmap={"a": "ancillas", "s": "state"})

This gives a TypeError and its not clear why based on the error message.

The way to fix this is to pass in an empty dict cregmap argument to specify how to map the classical registers inside and outside the box to be joined. This unnatural as my Circuit has no bits (only qubits). I think it'd be more user friendly to make these arguments optional.

The same is true for Circuit.add_circbox_regiwise. You need to pass in an empty list for the cregs arg adding a CircBox to a pure quantum circuit.

The following snippet works... (note the cregmap = {})

from pytket.circuit import Circuit, CircBox

qpe_circ = Circuit()
a = qpe_circ.add_q_register("a", 2)
s = qpe_circ.add_q_register("s", 1)

qpe_circ.H(a[0])
qpe_circ.CU1(0.94, a[1], s[0])

qpe_box = CircBox(qpe_circ)

algorithm_circ = Circuit()
ancillas = algorithm_circ.add_q_register("ancillas", 2)
state = algorithm_circ.add_q_register("state", 1)
algorithm_circ.X(state[0])

algorithm_circ.add_circbox_with_regmap(qpe_box, qregmap={"a": "ancillas", "s": "state"}, cregmap = {})
github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale.