forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.py
38 lines (30 loc) · 1.53 KB
/
host.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
## Copyright (c) Microsoft Corporation. All rights reserved.
## Licensed under the MIT License.
## This Python script calls the TeleportRandomMessage Q# operation
## defined in the TeleportationSample.qs file.
## The first step is to import the qsharp package.
## For instructions on how to install the package, see: https://docs.microsoft.com/en-us/quantum/install-guide/python
import qsharp
# All the .qs files found under the current working directory are compiled and
# available in the workspace.
# use get_workspace_operations() to check the operations available in the current workspace:
print(qsharp.get_workspace_operations())
# these operations can be imported into Python. For example:
from Microsoft.Quantum.Samples.Teleportation import TeleportClassicalMessage, TeleportRandomMessage
# once imported, an operation can be simulated:
TeleportRandomMessage.simulate()
print("------------------")
# If the operation takes parameters, pass them as named arguments to simulate:
r = TeleportClassicalMessage.simulate(message=True)
print("Sent True, Received:", r)
r = TeleportClassicalMessage.simulate(message=False)
print("Sent False, Received:", r)
print("------------------")
# and the quantum resources needed to execute the operation can be easily estimated:
resources = TeleportRandomMessage.estimate_resources()
print("Estimated resources needed for teleport:\n", resources)
print("------------------")
# You can use these operation iteratively from Python:
for i in range(10):
TeleportRandomMessage.simulate()
print("------------------")