-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathworker_manager.py
56 lines (44 loc) · 1.62 KB
/
worker_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright 2021 The Floq Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Example of TPU worker management.
This code makes synchronous request to Floq service to start TPU worker and
sends circuit for execution once the worker is up and running. Finally, when the
quantum circuit simulation is done, the script sends another synchronous request
to stop the worker.
"""
import cirq
import floq.client
import floq.client.schemas
API_KEY = "api_key"
def main() -> None:
"""Script entry point."""
client = floq.client.CirqClient(API_KEY)
# Start worker
client.tpu_worker.start()
# Get worker status
status = client.tpu_worker.status()
print(status)
# Submit circuit
qubits = cirq.LineQubit.range(1)
circuit = cirq.Circuit([cirq.X(qubits[0]), cirq.measure(qubits[0])])
result = client.simulator.run(circuit)
print(result)
# Stop worker
client.tpu_worker.stop()
# Get worker status
status = client.tpu_worker.status()
print(status)
if __name__ == "__main__":
main()