-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify tests and create a new folder
- Loading branch information
Showing
14 changed files
with
140 additions
and
4 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,9 @@ | ||
from qiskit import QuantumCircuit | ||
|
||
|
||
def create_hello_world_circuit() -> QuantumCircuit: | ||
circuit = QuantumCircuit(2) | ||
circuit.h(0) | ||
circuit.cx(0, 1) | ||
circuit.measure_all() | ||
return circuit |
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,10 @@ | ||
import os | ||
import tarfile | ||
from qiskit_serverless import save_result | ||
|
||
with tarfile.open("/data/my_file.tar", "r:gz") as tar: | ||
with tar.extractfile("./my_file.txt") as f: | ||
text = f.read() | ||
|
||
print(text) | ||
save_result({"Message": str(text)}) |
Binary file not shown.
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 @@ | ||
print("Hello World!") |
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,22 @@ | ||
from qiskit import QuantumCircuit | ||
from qiskit.primitives import StatevectorSampler as Sampler | ||
|
||
from qiskit_serverless import save_result | ||
|
||
# all print statement will be available in job logs | ||
print("Running pattern...") | ||
|
||
# creating circuit | ||
circuit = QuantumCircuit(2) | ||
circuit.h(0) | ||
circuit.cx(0, 1) | ||
circuit.measure_all() | ||
|
||
# running Sampler primitive | ||
sampler = Sampler() | ||
quasi_dists = sampler.run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
# saves results of program execution, | ||
# which will be accessible by calling `.result()` | ||
save_result(quasi_dists) | ||
print("Completed running pattern.") |
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,20 @@ | ||
# source_files/program_3.py | ||
|
||
from qiskit_serverless import get_arguments, save_result | ||
|
||
from qiskit.primitives import StatevectorSampler as Sampler | ||
|
||
# get all arguments passed to this program | ||
arguments = get_arguments() | ||
|
||
# get specific argument that we are interested in | ||
circuit = arguments.get("circuit") | ||
|
||
sampler = Sampler() | ||
|
||
quasi_dists = sampler.run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
print(f"Quasi distribution: {quasi_dists}") | ||
|
||
# saving results of a program | ||
save_result({"quasi_dists": quasi_dists}) |
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,13 @@ | ||
# source_files/program_4.py | ||
|
||
from qiskit_serverless import save_result | ||
|
||
import pendulum | ||
|
||
dt_toronto = pendulum.datetime(2012, 1, 1, tz="America/Toronto") | ||
dt_vancouver = pendulum.datetime(2012, 1, 1, tz="America/Vancouver") | ||
|
||
diff = dt_vancouver.diff(dt_toronto).in_hours() | ||
|
||
print(diff) | ||
save_result({"hours": diff}) |
26 changes: 26 additions & 0 deletions
26
tests/docker/source_files/pattern_with_parallel_workflow.py
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,26 @@ | ||
# source_files/program_with_parallel_workflow.py | ||
|
||
from qiskit_serverless import get_arguments, save_result, distribute_task, get | ||
|
||
from qiskit import QuantumCircuit | ||
from qiskit.primitives import StatevectorSampler as Sampler | ||
from qiskit.circuit.random import random_circuit | ||
|
||
|
||
@distribute_task() | ||
def distributed_sample(circuit: QuantumCircuit): | ||
"""Distributed task that returns quasi distribution for given circuit.""" | ||
return Sampler().run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
|
||
arguments = get_arguments() | ||
circuits = arguments.get("circuits") | ||
|
||
# run distributed tasks as async function | ||
# we get task references as a return type | ||
sample_task_references = [distributed_sample([(circuit)]) for circuit in circuits] | ||
|
||
# now we need to collect results from task references | ||
results = get(sample_task_references) | ||
|
||
save_result({"results": results}) |
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,11 @@ | ||
import os | ||
import tarfile | ||
from qiskit_serverless import save_result | ||
|
||
with open("./my_file.txt", "w") as f: | ||
f.write("Hello!") | ||
|
||
with tarfile.open("/data/my_file.tar", "w:gz") as tar: | ||
tar.add("./my_file.txt") | ||
|
||
save_result({"Message": "my_file.txt archived into my_file.tar"}) |
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,22 @@ | ||
from qiskit import QuantumCircuit | ||
from qiskit.primitives import StatevectorSampler as Sampler | ||
|
||
from qiskit_serverless import save_result | ||
|
||
# all print statement will be available in job logs | ||
print("Running program...") | ||
|
||
# creating circuit | ||
circuit = QuantumCircuit(2) | ||
circuit.h(0) | ||
circuit.cx(0, 1) | ||
circuit.measure_all() | ||
|
||
# running Sampler primitive | ||
sampler = Sampler() | ||
quasi_dists = sampler.run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
# saves results of program execution, | ||
# which will be accessible by calling `.result()` | ||
save_result(quasi_dists) | ||
print("Completed running program.") |
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
File renamed without changes.
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