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

Update version of OpenQASM 3.0 standard library #12387

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 35 additions & 28 deletions qiskit/qasm/libs/stdgates.inc
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
// OpenQASM 3 standard gate library
// OpenQASM 3.0 standard gate library
//
// Vendored from the OpenQASM 3.0 project at
// https://github.com/openqasm/openqasm.git@4ca1d793833b24a1.
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right link? It leads to a Not Found message.

// Used under the terms of its Apache-2.0 license.
// Copyright 2017-2024 OpenQASM Contributors.


// phase gate
gate p(lambda) a { ctrl @ gphase(lambda) a; }
gate p(λ) a { ctrl @ gphase(λ) a; }

// Pauli gate: bit-flip or NOT gate
gate x a { U(pi, 0, pi) a; }
gate x a { U(π, 0, π) a; gphase(-π/2);}
// Pauli gate: bit and phase flip
gate y a { U(pi, pi/2, pi/2) a; }
// Pauli gate: phase flip
gate z a { p(pi) a; }
gate y a { U(π, π/2, π/2) a; gphase(-π/2);}
// Pauli gate: phase flip
gate z a { p(π) a; }

// Clifford gate: Hadamard
gate h a { U(pi/2, 0, pi) a; }
gate h a { U(π/2, 0, π) a; gphase(-π/4);}
// Clifford gate: sqrt(Z) or S gate
gate s a { pow(1/2) @ z a; }
gate s a { pow(0.5) @ z a; }
// Clifford gate: inverse of sqrt(Z)
gate sdg a { inv @ pow(1/2) @ z a; }
gate sdg a { inv @ pow(0.5) @ z a; }

// sqrt(S) or T gate
gate t a { pow(1/2) @ s a; }
gate t a { pow(0.5) @ s a; }
// inverse of sqrt(S)
gate tdg a { inv @ pow(1/2) @ s a; }
gate tdg a { inv @ pow(0.5) @ s a; }

// sqrt(NOT) gate
gate sx a { pow(1/2) @ x a; }
gate sx a { pow(0.5) @ x a; }

// Rotation around X-axis
gate rx(theta) a { U(theta, -pi/2, pi/2) a; }
gate rx(θ) a { U(θ, -π/2, π/2) a; gphase(-θ/2);}
// rotation around Y-axis
gate ry(theta) a { U(theta, 0, 0) a; }
gate ry(θ) a { U(θ, 0, 0) a; gphase(-θ/2);}
// rotation around Z axis
gate rz(lambda) a { gphase(-lambda/2); U(0, 0, lambda) a; }
gate rz(λ) a { gphase(-λ/2); U(0, 0, λ) a; }

// controlled-NOT
gate cx c, t { ctrl @ x c, t; }
gate cx a, b { ctrl @ x a, b; }
// controlled-Y
gate cy a, b { ctrl @ y a, b; }
// controlled-Z
gate cz a, b { ctrl @ z a, b; }
// controlled-phase
gate cp(lambda) a, b { ctrl @ p(lambda) a, b; }
gate cp(λ) a, b { ctrl @ p(λ) a, b; }
// controlled-rx
gate crx(theta) a, b { ctrl @ rx(theta) a, b; }
gate crx(θ) a, b { ctrl @ rx(θ) a, b; }
// controlled-ry
gate cry(theta) a, b { ctrl @ ry(theta) a, b; }
gate cry(θ) a, b { ctrl @ ry(θ) a, b; }
// controlled-rz
gate crz(theta) a, b { ctrl @ rz(theta) a, b; }
gate crz(θ) a, b { ctrl @ rz(θ) a, b; }
// controlled-H
gate ch a, b { ctrl @ h a, b; }

Expand All @@ -57,19 +64,19 @@ gate ccx a, b, c { ctrl @ ctrl @ x a, b, c; }
// controlled-swap
gate cswap a, b, c { ctrl @ swap a, b, c; }

// four parameter controlled-U gate with relative phase
gate cu(theta, phi, lambda, gamma) c, t { p(gamma) c; ctrl @ U(theta, phi, lambda) c, t; }
// four parameter controlled-U gate with relative phase γ
gate cu(θ, φ, λ, γ) a, b { p(γ-θ/2) a; ctrl @ U(θ, φ, λ) a, b; }

// Gates for OpenQASM 2 backwards compatibility
// CNOT
gate CX c, t { ctrl @ U(pi, 0, pi) c, t; }
gate CX a, b { ctrl @ U(π, 0, π) a, b; }
// phase gate
gate phase(lambda) q { U(0, 0, lambda) q; }
gate phase(λ) q { U(0, 0, λ) q; }
// controlled-phase
gate cphase(lambda) a, b { ctrl @ phase(lambda) a, b; }
gate cphase(λ) a, b { ctrl @ phase(λ) a, b; }
// identity or idle gate
gate id a { U(0, 0, 0) a; }
// IBM Quantum experience gates
gate u1(lambda) q { U(0, 0, lambda) q; }
gate u2(phi, lambda) q { gphase(-(phi+lambda)/2); U(pi/2, phi, lambda) q; }
gate u3(theta, phi, lambda) q { gphase(-(phi+lambda)/2); U(theta, phi, lambda) q; }
gate u1(λ) q { U(0, 0, λ) q; }
gate u2(φ, λ) q { gphase(-(φ+λ+π/2)/2); U(π/2, φ, λ) q; }
gate u3(θ, φ, λ) q { gphase(-(φ+λ+θ)/2); U(θ, φ, λ) q; }
7 changes: 7 additions & 0 deletions releasenotes/notes/update-qasm3-lib-40e15bc24234970d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features_qasm:
- |
The vendored version of the OpenQASM 3.0 standard library has been
updated to match `the state as of commit 4ca1d79383 <https://github.com/openqasm/openqasm/blob/4ca1d793833b24a195dcb8a5db99f1bd21b0d32f/examples/stdgates.inc>`__.
This should generally have no effect on your use of Qiskit, unless you
were retrieving our vendored file for your own use.