Skip to content

Allow passing in and returning the quantum register when loading cirq.Circuits into squin #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

david-pl
Copy link
Collaborator

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:

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

@david-pl david-pl requested review from Roger-luo and weinbe58 June 10, 2025 12:06
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Contributor

github-actions bot commented Jun 10, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
8806 7769 88% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/bloqade/squin/cirq/_init_.py 94% 🟢
src/bloqade/squin/cirq/lowering.py 93% 🟢
TOTAL 94% 🟢

updated for commit: 1349feb by action🐍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Returning and passing in the quantum register from/to a loaded cirq.Circuit
1 participant