-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
165 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pyqasm | ||
|
||
qasm_program = """ | ||
OPENQASM 3; | ||
include "stdgates.inc"; | ||
// Define custom gates | ||
gate hgate q { | ||
h q; | ||
} | ||
gate xgate q { | ||
x q; | ||
} | ||
gate cxgate q1, q2 { | ||
cx q1, q2; | ||
} | ||
// Define a subroutine for creating a Bell state | ||
def create_bell_state(qubit[2] q) { | ||
hgate q[0]; | ||
cxgate q[0], q[1]; | ||
return; | ||
} | ||
// Define a subroutine for a generic quantum operation | ||
def generic_operation(qubit[N] q) { | ||
for int i in [0:N-1] { | ||
hgate q[i]; | ||
xgate q[i]; | ||
y q[i]; | ||
rx(pi) q[i]; | ||
} | ||
return; | ||
} | ||
// Main program | ||
const int[32] N = 4; | ||
qubit[4] q; | ||
bit[4] c; | ||
// Create a Bell state using the alias | ||
create_bell_state(q[0:2]); | ||
measure q[0:1] -> c[0:1]; | ||
// Perform a generic operation on all qubits | ||
generic_operation(q); | ||
// Classical control flow | ||
if (c[0]) { | ||
hgate q[0]; | ||
} else { | ||
xgate q[0]; | ||
} | ||
// Define an array of angles for parameterized gates | ||
array[float[64], N] angles = {pi/2, pi/4, pi/8, pi/16}; | ||
// Apply parameterized rotations | ||
for int i in [0:N-1] { | ||
rx(angles[i]) q[i]; | ||
} | ||
// Measure the qubits | ||
c = measure q; | ||
""" | ||
|
||
pyqasm.validate(qasm_program) |