Skip to content
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

utils: (qssa-builder) introduce builder for qssa #34

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

alexarice
Copy link
Collaborator

Lets a qssa program be built in a style similar to qref programs.

Still needs some unit tests. I also don't think the name hints are propagating correctly yet.

@alexarice alexarice requested a review from kimxworrall January 23, 2025 12:11
@alexarice alexarice self-assigned this Jan 23, 2025
@superlopuh
Copy link
Member

I'm curious about this, what's the use-case and intended API? Do you have a circuit that you'd like to have some sugar for?

@alexarice
Copy link
Collaborator Author

alexarice commented Jan 23, 2025

I have a circuit which was a real pain to write without this. Essentially it's much easier to write a circuit when thinking of a gate as an operation which mutates qubits rather than as an SSA operation, and this builder lets you write in the first style and converts to the SSA style

Edit: circuit appears in future PR which has not been pushed yet

@alexarice
Copy link
Collaborator Author

@superlopuh https://github.com/xdslproject/inconspiquous/blob/temp/inconspiquous/transforms/qec/inline.py here is some code that uses this builder. Would be keen to know if you can think of a better way to achieve this, or if you think subclassing the builder is a bad idea

@superlopuh
Copy link
Member

Nice! It's not a bad idea, although I wonder if there's already some quantum circuit DSL/library that you could IR gen from instead? This already looks rather pretty so it's your call.

@alexarice
Copy link
Collaborator Author

I don't think there's a dsl that would let you mix in the classical mlir operations in this way.

@alexarice
Copy link
Collaborator Author

An alternative could be to have a direct generation method on GateAttr, instead of using a builder. I might investigate what that would look like next week

@alexarice
Copy link
Collaborator Author

I had a play around and don't particularly like the method on GateAttr as it doesn't extend to dynamic gates. I'll merge this for now, can always iterate on the design.

@alexarice alexarice merged commit f460da2 into main Jan 27, 2025
5 checks passed
@alexarice alexarice deleted the alexarice/qssa-builder branch January 27, 2025 14:58
@alexarice
Copy link
Collaborator Author

I also played around with having a contextmanager for ancilla qubits, which would allocate them and then measure them an the end, but I couldn't find a satisfying interface for returning the measured value

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

Successfully merging this pull request may close these issues.

2 participants