-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
305 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
|
||
import pennylane as qml | ||
from pilot.pilot_compute_service import ExecutionEngine, PilotComputeService | ||
from time import sleep | ||
|
||
RESOURCE_URL = "ssh://localhost" | ||
WORKING_DIRECTORY = os.path.join(os.environ["HOME"], "work") | ||
|
||
pilot_compute_description = { | ||
"resource": RESOURCE_URL, | ||
"number_of_nodes": 2, | ||
"cores_per_node": 10, | ||
} | ||
|
||
|
||
def start_pcs(): | ||
pcs = PilotComputeService(ExecutionEngine.DASK, WORKING_DIRECTORY) | ||
for i in range(2): | ||
pilot_compute_description["name"] = f"pilot-{i}" | ||
pcs.create_pilot(pilot_compute_description=pilot_compute_description) | ||
return pcs | ||
|
||
def pennylane_quantum_circuit(): | ||
wires = 4 | ||
layers = 1 | ||
dev = qml.device('default.qubit', wires=wires, shots=None) | ||
|
||
@qml.qnode(dev) | ||
def circuit(parameters): | ||
qml.StronglyEntanglingLayers(weights=parameters, wires=range(wires)) | ||
return [qml.expval(qml.PauliZ(i)) for i in range(wires)] | ||
|
||
shape = qml.StronglyEntanglingLayers.shape(n_layers=layers, n_wires=wires) | ||
weights = qml.numpy.random.random(size=shape) | ||
return circuit(weights) | ||
|
||
|
||
if __name__ == "__main__": | ||
pcs = None | ||
try: | ||
# Start Pilots | ||
pcs = start_pcs() | ||
|
||
pilots = pcs.get_pilots() | ||
|
||
# print pilot names | ||
for pname in pilots: | ||
print(pname) | ||
|
||
# Submit tasks to pcs | ||
tasks = [] | ||
for i in range(1000): | ||
k = pcs.submit_task(f"task_pennylane-{i}", pennylane_quantum_circuit) | ||
tasks.append(k) | ||
|
||
for i in range(1000): | ||
k = pcs.submit_task(f"task_pennylane-{i}", pennylane_quantum_circuit, pilot=pilots[0]) | ||
tasks.append(k) | ||
|
||
|
||
pcs.wait_tasks(tasks) | ||
finally: | ||
if pcs: | ||
pcs.cancel() | ||
|
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
Oops, something went wrong.