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 proposal.md using pyquil quilt-demo branch changes #48

Merged
merged 4 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 104 additions & 12 deletions grammars/Quil.g4
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ grammar Quil;
quil : allInstr? ( NEWLINE+ allInstr )* NEWLINE* EOF ;

allInstr : defGate
| defGateAsPauli
| defCircuit
| defFrame
| defWaveform
| defCalibration
| defMeasCalibration
| instr
;

instr : gate
instr : fence
| fenceAll
| delay
| gate
| measure
| defLabel
| halt
Expand All @@ -28,7 +36,16 @@ instr : gate
| nop
| include
| pragma
| memoryDescriptor
| pulse
| setFrequency
| shiftFrequency
| setPhase
| shiftPhase
| swapPhase
| setScale
| capture
| rawCapture
| memoryDescriptor // this is a little unusual, but it's in steven's example
;

// C. Static and Parametric Gates
Expand All @@ -41,19 +58,24 @@ qubit : INT ;
param : expression ;

modifier : CONTROLLED
| DAGGER ;
| DAGGER
| FORKED ;

// D. Gate Definitions

defGate : DEFGATE name ( ( LPAREN variable ( COMMA variable )* RPAREN ) | ( AS gateType ) )? COLON NEWLINE matrix ;
defGate : DEFGATE name (( LPAREN variable ( COMMA variable )* RPAREN ) | ( AS gatetype ))? COLON NEWLINE matrix ;
defGateAsPauli : DEFGATE name ( LPAREN variable ( COMMA variable )* RPAREN )? qubitVariable+ AS PAULISUM COLON NEWLINE pauliTerms ;

variable : PERCENTAGE IDENTIFIER ;

gateType : MATRIX | PERMUTATION ;
gatetype : MATRIX
| PERMUTATION ;

matrix : ( matrixRow NEWLINE )* matrixRow ;
matrixRow : TAB expression ( COMMA expression )* ;

pauliTerms : ( pauliTerm NEWLINE )* pauliTerm;
pauliTerm : TAB IDENTIFIER LPAREN expression RPAREN qubitVariable+ ;

// E. Circuits

defCircuit : DEFCIRCUIT name ( LPAREN variable ( COMMA variable )* RPAREN )? qubitVariable* COLON NEWLINE circuit ;
Expand Down Expand Up @@ -115,8 +137,8 @@ include : INCLUDE STRING ;

// M. Pragma Support

pragma : PRAGMA IDENTIFIER pragma_name* STRING? ;
pragma_name : IDENTIFIER | INT ;
pragma : PRAGMA ( IDENTIFIER | keyword ) pragma_name* STRING? ;
pragma_name : IDENTIFIER | keyword | INT ;

// Expressions (in order of precedence)

Expand All @@ -141,10 +163,54 @@ number : MINUS? ( realN | imaginaryN | I | PI ) ;
imaginaryN : realN I ;
realN : FLOAT | INT ;

// Analog control

waveformName : name (DIVIDE name)? ;

defFrame : DEFFRAME frame ( COLON frameSpec+ )? ;
frameSpec : NEWLINE TAB frameAttr COLON ( expression | STRING ) ;
frameAttr : SAMPLERATE | INITIALFREQUENCY | DIRECTION | HARDWAREOBJECT | CENTERFREQUENCY;

defWaveform : DEFWAVEFORM waveformName ( LPAREN param (COMMA param)* RPAREN )? COLON NEWLINE matrix ;
defCalibration : DEFCAL name (LPAREN param ( COMMA param )* RPAREN)? qubitOrFormal+ COLON ( NEWLINE TAB instr )* ;
defMeasCalibration : DEFCAL MEASURE qubitOrFormal ( name )? COLON ( NEWLINE TAB instr )* ;

pulse : NONBLOCKING? PULSE frame waveform ;
capture : NONBLOCKING? CAPTURE frame waveform addr ;
rawCapture : NONBLOCKING? RAWCAPTURE frame expression addr ;

setFrequency : SETFREQUENCY frame expression ;
shiftFrequency : SHIFTFREQUENCY frame expression ;
setPhase : SETPHASE frame expression ;
shiftPhase : SHIFTPHASE frame expression ;
swapPhase : SWAPPHASE frame frame ;
setScale : SETSCALE frame expression ;

delay : DELAY qubitOrFormal+ STRING* expression ;
fenceAll : FENCE ;
fence : FENCE qubitOrFormal+ ;

qubitOrFormal : qubit | qubitVariable ;
namedParam : IDENTIFIER COLON expression ;
waveform : waveformName (LPAREN namedParam ( COMMA namedParam )* RPAREN)? ;
frame : qubitOrFormal+ STRING ;

// built-in waveform types include: "flat", "gaussian", "draggaussian", "erfsquare"


////////////////////
// LEXER
////////////////////

keyword : DEFGATE | DEFCIRCUIT | MEASURE | LABEL | HALT | JUMP | JUMPWHEN | JUMPUNLESS
| RESET | WAIT | NOP | INCLUDE | PRAGMA | DECLARE | SHARING | OFFSET | AS | MATRIX
| PERMUTATION | NEG | NOT | TRUE | FALSE | AND | IOR | XOR | OR | ADD | SUB | MUL
| DIV | MOVE | EXCHANGE | CONVERT | EQ | GT | GE | LT | LE | LOAD | STORE | PI | I
| SIN | COS | SQRT | EXP | CIS | CAPTURE | DEFCAL | DEFFRAME | DEFWAVEFORM
| DELAY | DIRECTION | FENCE | INITIALFREQUENCY | CENTERFREQUENCY | NONBLOCKING | PULSE | SAMPLERATE
| SETFREQUENCY | SETPHASE | SETSCALE | SHIFTPHASE | SWAPPHASE | RAWCAPTURE
| CONTROLLED | DAGGER | FORKED ;

// Keywords

DEFGATE : 'DEFGATE' ;
Expand All @@ -167,6 +233,11 @@ DECLARE : 'DECLARE' ;
SHARING : 'SHARING' ;
OFFSET : 'OFFSET' ;

AS : 'AS' ;
MATRIX : 'MATRIX' ;
PERMUTATION : 'PERMUTATION' ;
PAULISUM : 'PAULI-SUM';

NEG : 'NEG' ;
NOT : 'NOT' ;
TRUE : 'TRUE' ; // Deprecated
Expand Down Expand Up @@ -204,9 +275,6 @@ SQRT : 'SQRT' ;
EXP : 'EXP' ;
CIS : 'CIS' ;

MATRIX : 'MATRIX' ;
PERMUTATION : 'PERMUTATION' ;

// Operators

PLUS : '+' ;
Expand All @@ -215,10 +283,34 @@ TIMES : '*' ;
DIVIDE : '/' ;
POWER : '^' ;

// analog keywords

CAPTURE : 'CAPTURE' ;
DEFCAL : 'DEFCAL' ;
DEFFRAME : 'DEFFRAME' ;
DEFWAVEFORM : 'DEFWAVEFORM' ;
DELAY : 'DELAY' ;
DIRECTION : 'DIRECTION' ;
FENCE : 'FENCE' ;
HARDWAREOBJECT : 'HARDWARE-OBJECT' ;
INITIALFREQUENCY : 'INITIAL-FREQUENCY' ;
CENTERFREQUENCY : 'CENTER-FREQUENCY' ;
NONBLOCKING : 'NONBLOCKING' ;
PULSE : 'PULSE' ;
SAMPLERATE : 'SAMPLE-RATE' ;
SETFREQUENCY : 'SET-FREQUENCY' ;
SHIFTFREQUENCY : 'SHIFT-FREQUENCY' ;
SETPHASE : 'SET-PHASE' ;
SETSCALE : 'SET-SCALE' ;
SHIFTPHASE : 'SHIFT-PHASE' ;
SWAPPHASE : 'SWAP-PHASE' ;
RAWCAPTURE : 'RAW-CAPTURE' ;

// Modifiers

CONTROLLED : 'CONTROLLED' ;
DAGGER : 'DAGGER' ;
FORKED : 'FORKED' ;

// Identifiers

Expand All @@ -231,7 +323,7 @@ FLOAT : [0-9]+ ( '.' [0-9]+ )? ( ( 'e'|'E' ) ( '+' | '-' )? [0-9]+

// String

STRING : '"' ~( '\n' | '\r' )* '"';
STRING : '"' ~( '\n' | '\r' | '"' )* '"';

// Punctuation

Expand Down
Loading