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

Add oqpy.gate for gate definitions #60

Merged

Conversation

rmshaffer
Copy link
Contributor

This PR implements support for gate definitions (issue #1).

The spec for gate definitions is contained here: https://openqasm.com/language/gates.html

Basic usage is as follows:

prog = oqpy.Program()
q = oqpy.Qubit("q", needs_declaration=False)
with oqpy.gate(prog, q, "rz", [oqpy.AngleVar(name="theta")]) as theta:
    prog.gate(q, "u", theta, 0, 0)
with oqpy.gate(prog, q, "t"):
    prog.gate(q, "rz", oqpy.pi / 4)
prog.gate(oqpy.PhysicalQubits[0], "t")
print(prog.to_qasm())

produces:

OPENQASM 3.0;
gate rz(theta) q {
    u(theta, 0, 0) q;
}
gate t q {
    rz(pi / 4) q;
}
t $0;

@CLAassistant
Copy link

CLAassistant commented Aug 15, 2023

CLA assistant check
All committers have signed the CLA.

@rmshaffer rmshaffer marked this pull request as ready for review August 15, 2023 20:21
Copy link
Collaborator

@PhilReinhold PhilReinhold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one suggestion, but otherwise looks great!

oqpy/program.py Show resolved Hide resolved
@PhilReinhold PhilReinhold merged commit b5cb6b5 into openqasm:main Aug 17, 2023
11 checks passed
@rmshaffer rmshaffer deleted the rmshaffer/gate-definitions-defcals branch August 17, 2023 19:53
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.

4 participants