Commit 2445d7bb authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Work on extending QASM to support extern quantum subroutines



Need to debug the MLIR code gen...

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 5945da0b
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
OPENQASM 3;


const n_counting = 3;

// Declare external quantum subroutine:
def QCOR__IQFT__Interop qubit[n_counting]:qq extern;

// For this example, the oracle is the T gate 
// on the provided qubit
gate oracle b {
    t b;
}

// Define some counting qubits
qubit counting[n_counting];

// Allocate the qubit we'll 
// put the initial state on
qubit state;

// We want T |1> = exp(2*i*pi*phase) |1> = exp(i*pi/4)
// compute phase, should be 1 / 8;

// Initialize to |1>
x state;

// Put all others in a uniform superposition
h counting;

// Loop over and create ctrl-U**2k
int repetitions = 1;
for i in [0:n_counting] {
    ctrl @ pow(repetitions) @ oracle counting[i], state;
    repetitions *= 2;
}

// Run inverse QFT 
QCOR__IQFT__Interop counting;

// Now lets measure the counting qubits
bit c[n_counting];
measure counting -> c;

// Backend is QPP which is lsb, 
// so return should be 100
print(c);
+3 −1

File changed.

Preview size limit exceeded, changes collapsed.

+12 −10
Original line number Diff line number Diff line
@@ -106,16 +106,17 @@ COMMA=105
EQUALS=106
ARROW=107
MINUS=108
Constant=109
Whitespace=110
Newline=111
Integer=112
Identifier=113
RealNumber=114
TimingLiteral=115
StringLiteral=116
LineComment=117
BlockComment=118
EXTERN=109
Constant=110
Whitespace=111
Newline=112
Integer=113
Identifier=114
RealNumber=115
TimingLiteral=116
StringLiteral=117
LineComment=118
BlockComment=119
'OPENQASM'=1
'include'=2
'QCOR_EXPECT_TRUE'=3
@@ -224,3 +225,4 @@ BlockComment=118
'='=106
'->'=107
'-'=108
'extern'=109
+841 −830

File changed.

Preview size limit exceeded, changes collapsed.

+4 −3
Original line number Diff line number Diff line
@@ -30,9 +30,10 @@ public:
    T__86 = 87, T__87 = 88, T__88 = 89, T__89 = 90, T__90 = 91, T__91 = 92, 
    T__92 = 93, T__93 = 94, T__94 = 95, LBRACKET = 96, RBRACKET = 97, LBRACE = 98, 
    RBRACE = 99, LPAREN = 100, RPAREN = 101, COLON = 102, SEMICOLON = 103, 
    DOT = 104, COMMA = 105, EQUALS = 106, ARROW = 107, MINUS = 108, Constant = 109, 
    Whitespace = 110, Newline = 111, Integer = 112, Identifier = 113, RealNumber = 114, 
    TimingLiteral = 115, StringLiteral = 116, LineComment = 117, BlockComment = 118
    DOT = 104, COMMA = 105, EQUALS = 106, ARROW = 107, MINUS = 108, EXTERN = 109, 
    Constant = 110, Whitespace = 111, Newline = 112, Integer = 113, Identifier = 114, 
    RealNumber = 115, TimingLiteral = 116, StringLiteral = 117, LineComment = 118, 
    BlockComment = 119
  };

  explicit qasm3Lexer(antlr4::CharStream *input);
Loading