forked from ProjectQ-Framework/ProjectQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathibm16.py
More file actions
executable file
·43 lines (32 loc) · 1.25 KB
/
ibm16.py
File metadata and controls
executable file
·43 lines (32 loc) · 1.25 KB
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
import projectq.setups.ibm16
from projectq.backends import IBMBackend
from projectq.ops import All, Entangle, Measure
from projectq import MainEngine
def run_test(eng):
"""
Runs a test circuit on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
Returns:
measurement (list<int>): List of measurement outcomes.
"""
# allocate the quantum register to entangle
qureg = eng.allocate_qureg(8)
Entangle | qureg
# measure; should be all-0 or all-1
All(Measure) | qureg
# run the circuit
eng.flush()
# access the probabilities via the back-end:
results = eng.backend.get_probabilities(qureg)
for state, probability in sorted(list(results.items())):
print("Measured {} with p = {}.".format(state, probability))
# return one (random) measurement outcome.
return [int(q) for q in qureg]
if __name__ == "__main__":
# create main compiler engine for the 16-qubit IBM back-end
eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024,
verbose=False, device='ibmqx5'),
engine_list=projectq.setups.ibm16.get_engine_list())
# run the circuit and print the result
print(run_test(eng))