Skip to content

Commit

Permalink
Remove grammar declaration within defcal
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Schoenfeld committed Mar 1, 2021
1 parent 7ba6725 commit c70be53
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions examples/cphase.qasm
@@ -1,9 +1,9 @@
gate cphase(angle[32]: θ) a, b
gate cphase(θ) a, b
{
U(0, 0, θ / 2) a;
CX a, b;
U(0, 0, -θ / 2) b;
CX a, b;
U(0, 0, θ / 2) b;
}
cphase(π / 2) q[0], q[1];
cphase(π / 2) q[0], q[1];
32 changes: 16 additions & 16 deletions examples/stdgates.inc
@@ -1,7 +1,7 @@
// Standard gate library

// phase gate (Z-rotation by lambda)
gate phase(angle[32]:lambda) q { U(0, 0, lambda) q; }
gate phase(lambda) q { U(0, 0, lambda) q; }
// controlled-NOT
gate CX c, t { ctrl @ U(pi, 0, pi) c, t; }
gate cx c, t { CX c, t; }
Expand All @@ -24,26 +24,26 @@ gate t a { phase(pi/4) a; }
// C3 gate: conjugate of sqrt(S)
gate tdg a { phase(-pi/4) a; }
// Rotation around X-axis
gate rx(angle[32]:theta) a { U(theta, -pi / 2, pi / 2) a; }
gate rx(theta) a { U(theta, -pi / 2, pi / 2) a; }
// rotation around Y-axis
gate ry(angle[32]:theta) a { U(theta, 0, 0) a; }
gate ry(theta) a { U(theta, 0, 0) a; }
// rotation around Z axis
gate rz(angle[32]:phi) a { phase(phi) a; }
gate rz(phi) a { phase(phi) a; }
// controlled-Phase
gate cz a, b { h b; cx a, b; h b; }
// controlled-Y
gate cy a, b { sdg b; cx a, b; s b; }
// controlled-H
gate ch a, b {
h b;
h b;
sdg b;
cx a, b;
h b;
h b;
t b;
cx a, b;
t b; s a;
h b;
s b;
t b; s a;
h b;
s b;
x b;
}
// Toffoli
Expand All @@ -52,13 +52,13 @@ gate ccx a, b, c
h c;
cx b, c;
tdg c;
cx a, c;
cx a, c;
t c;
cx b, c;
cx b, c;
tdg c;
cx a, c;
cx a, c;
t b; t c; h c;
cx a, b;
cx a, b;
t a; tdg b;
cx a, b;
}
Expand All @@ -70,15 +70,15 @@ gate cswap a, b, c
cx c, b;
}
// controlled-rz
gate crz(angle[32]:lambda) a, b
gate crz(lambda) a, b
{
phase(lambda / 2) b;
cx a, b;
phase(-lambda / 2) b;
cx a, b;
}
// controlled-phase
gate cphase(angle[32]:lambda) a, b
gate cphase(lambda) a, b
{
phase(lambda / 2) a;
cx a, b;
Expand All @@ -87,7 +87,7 @@ gate cphase(angle[32]:lambda) a, b
phase(lambda / 2) b;
}
// controlled-U
gate cu(angle[32]:theta,angle[32]:phi,angle[32]:lambda) c, t
gate cu(theta, phi, lambda) c, t
{
// implements controlled-U(theta,phi,lambda) with target t and control c
phase((lambda - phi)/2) t;
Expand Down
4 changes: 3 additions & 1 deletion examples/t1.qasm
Expand Up @@ -15,8 +15,10 @@ kernel tabulate(int[32], int[32], int[32]);

bit c0, c1;

defcalgrammar "openpulse";

// define a gate calibration for an X gate on any qubit
defcal "openpulse" x $q {
defcal x $q {
play drive($q), gaussian(100, 30, 5);
}

Expand Down
4 changes: 2 additions & 2 deletions source/grammar/qasm3.g4
Expand Up @@ -445,13 +445,13 @@ calibrationGrammarDeclaration
;

calibrationDefinition
: 'defcal' calibrationGrammar? Identifier
: 'defcal' Identifier
( LPAREN calibrationArgumentList? RPAREN )? identifierList
returnSignature? LBRACE .*? RBRACE // for now, match anything inside body
;

calibrationGrammar
: '"openpulse"' | StringLiteral // currently: pulse grammar string can be anything
: '"openpulse"' | StringLiteral // currently: pulse grammar string can be anything
;

calibrationArgumentList
Expand Down
8 changes: 4 additions & 4 deletions source/language/pulses.rst
Expand Up @@ -83,15 +83,15 @@ the most specific definition found for a given operation. Thus, given,
the operation ``rx(pi/2) $0`` would match to (3), ``rx(pi) $0`` would
match (2), ``rx(pi/2) $1`` would match (1).

Users specify the grammar used inside ``defcal`` blocks with a ``defcalgrammar "name"`` declaration, or by
an optional grammar string in a ``defcal`` definition, e.g.
Users specify the grammar used inside ``defcal`` blocks with a ``defcalgrammar "name"`` declaration.
For instance,

.. code-block:: c
defcalgrammar "openpulse";
defcal "openpulse" measure $0 -> bit { ... }
are two equivalent ways to specify that the ``measure`` definition uses the ``"openpulse"`` grammar.
specifies that all `defcal`'s will use the "openpulse" grammar.


Note that ``defcal`` and ``gate`` communicate orthogonal information to the compiler. ``gate``'s
define unitary transformation rules to the compiler. The compiler may
Expand Down

0 comments on commit c70be53

Please sign in to comment.