File tree Expand file tree Collapse file tree
examples/netqasm/teleport Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from netqasm .runtime .settings import set_simulator
2+
3+ set_simulator ("simulaqron" )
4+
5+ from netqasm .runtime .application import default_app_instance
6+ from netqasm .sdk .external import NetQASMConnection
7+ from netqasm .sdk import Qubit , EPRSocket
8+
9+ from simulaqron .run .run import run_applications
10+
11+ def run_alice ():
12+ epr_socket : EPRSocket = EPRSocket ("Bob" )
13+ with NetQASMConnection ("Alice" , epr_sockets = [epr_socket ]) as alice :
14+ # Create a qubit
15+ q = Qubit (alice )
16+ q .H ()
17+
18+ # Create entanglement
19+ epr = epr_socket .create_keep ()[0 ]
20+
21+ # Teleport
22+ q .cnot (epr )
23+ q .H ()
24+ m1 = q .measure ()
25+ m2 = epr .measure ()
26+ return m1 , m2
27+
28+
29+ def run_bob ():
30+ epr_socket : EPRSocket = EPRSocket ("Alice" )
31+ with NetQASMConnection ("Bob" , epr_sockets = [epr_socket ]):
32+ entangled_qubit = epr_socket .recv_keep ()[0 ]
33+ meas = entangled_qubit .measure ()
34+ return meas
35+
36+ if __name__ == "__main__" :
37+ apps = default_app_instance (
38+ [
39+ ("Alice" , run_alice ),
40+ ("Bob" , run_bob )
41+ ]
42+ )
43+ raw_results = run_applications (apps , use_app_config = False , enable_logging = False )
44+
45+ results = {}
46+
47+ for name , raw_result in raw_results [0 ].items ():
48+ if isinstance (raw_result , tuple ):
49+ results [name ] = tuple (int (result ) for result in raw_result )
50+ else :
51+ results [name ] = int (raw_result )
52+
53+ print (results )
You can’t perform that action at this time.
0 commit comments