Skip to content

Commit 6ef8a0e

Browse files
dbretaudYtterbot
andauthored
bug fix on ibm example; new aqt example; updated the main README file (#368)
Co-authored-by: dbretaud <logiciqt@gmail.com>
1 parent f88a0f6 commit 6ef8a0e

3 files changed

Lines changed: 94 additions & 4 deletions

File tree

README.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,34 @@ Instead of simulating a quantum program, one can use our resource counter (as a
102102
103103
**Running a quantum program on IBM's QE chips**
104104

105-
To run a program on the IBM Quantum Experience chips, all one has to do is choose the `IBMBackend` and the corresponding compiler:
105+
To run a program on the IBM Quantum Experience chips, all one has to do is choose the `IBMBackend` and the corresponding setup:
106106

107107
.. code-block:: python
108108
109109
import projectq.setups.ibm
110110
from projectq.backends import IBMBackend
111111
112+
token='MY_TOKEN'
112113
device='ibmq_16_melbourne'
113-
compiler_engines = projectq.setups.ibm.get_engine_list(device=device)
114-
eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024,
114+
compiler_engines = projectq.setups.ibm.get_engine_list(token=token,device=device)
115+
eng = MainEngine(IBMBackend(token=token, use_hardware=True, num_runs=1024,
116+
verbose=False, device=device),
117+
engine_list=compiler_engines)
118+
119+
120+
**Running a quantum program on AQT devices**
121+
122+
To run a program on the AQT trapped ion quantum computer, choose the `AQTBackend` and the corresponding setup:
123+
124+
.. code-block:: python
125+
126+
import projectq.setups.aqt
127+
from projectq.backends import AQTBackend
128+
129+
token='MY_TOKEN'
130+
device='aqt_device'
131+
compiler_engines = projectq.setups.aqt.get_engine_list(token=token,device=device)
132+
eng = MainEngine(AQTBackend(token=token,use_hardware=True, num_runs=1024,
115133
verbose=False, device=device),
116134
engine_list=compiler_engines)
117135

examples/aqt.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import matplotlib.pyplot as plt
2+
import getpass
3+
4+
from projectq import MainEngine
5+
from projectq.backends import AQTBackend
6+
from projectq.libs.hist import histogram
7+
from projectq.ops import Measure, Entangle, All
8+
import projectq.setups.aqt
9+
10+
11+
def run_entangle(eng, num_qubits=3):
12+
"""
13+
Runs an entangling operation on the provided compiler engine.
14+
15+
Args:
16+
eng (MainEngine): Main compiler engine to use.
17+
num_qubits (int): Number of qubits to entangle.
18+
19+
Returns:
20+
measurement (list<int>): List of measurement outcomes.
21+
"""
22+
# allocate the quantum register to entangle
23+
qureg = eng.allocate_qureg(num_qubits)
24+
25+
# entangle the qureg
26+
Entangle | qureg
27+
28+
# measure; should be all-0 or all-1
29+
All(Measure) | qureg
30+
31+
# run the circuit
32+
eng.flush()
33+
34+
# access the probabilities via the back-end:
35+
# results = eng.backend.get_probabilities(qureg)
36+
# for state in results:
37+
# print("Measured {} with p = {}.".format(state, results[state]))
38+
# or plot them directly:
39+
histogram(eng.backend, qureg)
40+
plt.show()
41+
42+
# return one (random) measurement outcome.
43+
return [int(q) for q in qureg]
44+
45+
46+
if __name__ == "__main__":
47+
#devices available to subscription:
48+
# aqt_simulator (11 qubits)
49+
# aqt_simulator_noise (11 qubits)
50+
# aqt_device (4 qubits)
51+
#
52+
# To get a subscription, create a profile at :
53+
# https://gateway-portal.aqt.eu/
54+
#
55+
device = None # replace by the AQT device name you want to use
56+
token = None # replace by the token given by AQT
57+
if token is None:
58+
token = getpass.getpass(prompt='AQT token > ')
59+
if device is None:
60+
device = getpass.getpass(prompt='AQT device > ')
61+
# create main compiler engine for the AQT back-end
62+
eng = MainEngine(AQTBackend(use_hardware=True, token=token, num_runs=200,
63+
verbose=False, device=device),
64+
engine_list=projectq.setups.aqt.get_engine_list(
65+
token=token, device=device))
66+
# run the circuit and print the result
67+
print(run_entangle(eng))

examples/ibm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ def run_entangle(eng, num_qubits=3):
4848
# ibmq_16_melbourne (15 qubit)
4949
# ibmq_essex (5 qubit)
5050
# ibmq_qasm_simulator (32 qubits)
51+
# and plenty of other 5 qubits devices!
52+
#
53+
# To get a token, create a profile at:
54+
# https://quantum-computing.ibm.com/
55+
#
5156
device = None # replace by the IBM device name you want to use
5257
token = None # replace by the token given by IBMQ
5358
if token is None:
5459
token = getpass.getpass(prompt='IBM Q token > ')
5560
if device is None:
56-
token = getpass.getpass(prompt='IBM device > ')
61+
device = getpass.getpass(prompt='IBM device > ')
5762
# create main compiler engine for the IBM back-end
5863
eng = MainEngine(IBMBackend(use_hardware=True, token=token, num_runs=1024,
5964
verbose=False, device=device),

0 commit comments

Comments
 (0)