You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow passing in and returning the quantum register when loading cirq.Circuits into squin (#313)
While looking into this I realized that the only thing that makes sense
(IMO) to pass into or return from a circuit is the list of qubits. I
added two simple keyword arguments to control the behavior.
The result is that you can compose kernels that you can easily compose
kernels that you generate from circuits. For example:
```python
q = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q[0]), cirq.CX(*q))
get_entangled_qubits = squin.cirq.load_circuit(
circuit, return_register=True, kernel_name="get_entangled_qubits"
)
get_entangled_qubits.print()
entangle_qubits = squin.cirq.load_circuit(
circuit, register_as_argument=True, kernel_name="entangle_qubits"
)
@squin.kernel
def main():
qreg = get_entangled_qubits()
qreg2 = squin.qubit.new(1)
entangle_qubits([qreg[1], qreg2[0]])
return squin.qubit.measure(qreg2)
```
Here, `get_entangled_qubits` allocates a new register, entangles it and
returns the result, whereas `entangle_qubits` accepts a register of two
qubits to entangle. Of course, you could also pass in and return from
the same kernel by setting both `return_register=True` and
`register_as_argument=True`.
FYI, @jon-wurtz , let me know if this covers the use case you had in
mind.
Closes#302
0 commit comments