-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from rigetticomputing/feature/run-quil-script
Feature/run quil script
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
X 0 | ||
MEASURE 0 [0] |
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,33 @@ | ||
""" | ||
This module run basic Quil text files agains the Forest QVM API. Usage | ||
""" | ||
import sys | ||
|
||
from pyquil.quil import Program | ||
import pyquil.forest as forest | ||
|
||
qvm = forest.Connection() | ||
|
||
help_string = "Script takes two arguments. Quil program filename is required as the first " \ | ||
"argument and number of classical registers to return is the optional second " \ | ||
"argument (defaults to 8)." | ||
|
||
if __name__ == '__main__': | ||
assert len(sys.argv) == 2 or len(sys.argv) == 3, help_string | ||
if sys.argv[1] == '-h' or sys.argv[1] == '--help': | ||
print help_string | ||
sys.exit() | ||
filepath = str(sys.argv[1]) | ||
if len(sys.argv) == 3: | ||
classical_register_num = int(sys.argv[2]) | ||
else: | ||
classical_register_num = 8 | ||
|
||
with open(filepath) as file: | ||
quil_prog = file.read() | ||
p = Program(quil_prog) | ||
|
||
print "Running Quil Program from: ", filepath | ||
print "---------------------------" | ||
print "Output: " | ||
print qvm.run(p, range(classical_register_num)) |