Skip to content

Commit

Permalink
adding qasm3 test
Browse files Browse the repository at this point in the history
  • Loading branch information
str-anger committed Jun 18, 2024
1 parent 8e55e23 commit 99fcbf9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
13 changes: 11 additions & 2 deletions py-qiskit-simulation/qiskit_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ def simulate(
raise NotImplementedError(f"Backend {backend_name} is not found in Qiskit.")
backend_instance = backend()
transpiled_circuit = transpile(circuit, backend_instance)
print(backend_instance.run(transpiled_circuit, shots=shots, memory=save_shots).result())
result = backend_instance.run(transpiled_circuit, shots=shots, memory=save_shots).result()
print(result)
return result.get_memory()

if __name__ == "__main__":
filename = os.environ.get("qasm_file", "")
simulator_class = os.environ.get("simulator_class", "")
qasm_version = int(os.environ.get("qasm_version", "2"))
shots = int(os.environ.get("shots", "1000"))
simulate(filename, simulator_class, shots, save_shots=True)
measurements = simulate(
filename,
simulator_class,
shots,
qasm_version=qasm_version,
save_shots=True
)
1 change: 1 addition & 0 deletions py-qiskit-simulation/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy>=1.26.0
qiskit>=1.1.0
qiskit-aer>=0.14.2
qiskit_qasm3_import>=0.5.0
11 changes: 11 additions & 0 deletions tests/data/bell_state.qasm3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
OPENQASM 3;
include "stdgates.inc";

qubit a;
qubit b;
bit[2] bits;

h a;
cx a, b;
bits[0] = measure a;
bits[1] = measure b;
3 changes: 2 additions & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tests/mock.sh
tests/test-py-qiskit-simulation.sh
tests/test-py-qiskit-simulation.sh
tests/test-py-qiskit-simulation-qasm3.sh
22 changes: 22 additions & 0 deletions tests/test-py-qiskit-simulation-qasm3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extension=py-qiskit-simulation
venv=$extension/.aqueduct-extension-dev

# recreate and populate a clean virtual env
# comment these 3 lines if requirements are stable
rm -r $venv
python -m venv $venv
$venv/bin/pip install -r $extension/requirements.txt

export aqueduct_url="http://localhost:8000/"

export aqueduct_key=""
export qasm_file=$(realpath tests/data/bell_state.qasm3)
export simulator_class="Fake20QV1"
export qasm_version=3
export shots=2000

# run
$venv/bin/python $extension/qiskit_simulator.py
code=$?
echo "Result code: $code"
exit $code

0 comments on commit 99fcbf9

Please sign in to comment.