Skip to content

Commit

Permalink
bug fix on ibm example; new aqt example; updated the main README file (
Browse files Browse the repository at this point in the history
…#368)

Co-authored-by: dbretaud <[email protected]>
  • Loading branch information
dbretaud and Ytterbot authored Apr 30, 2020
1 parent f88a0f6 commit 6ef8a0e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
24 changes: 21 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,34 @@ Instead of simulating a quantum program, one can use our resource counter (as a
**Running a quantum program on IBM's QE chips**

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

.. code-block:: python
import projectq.setups.ibm
from projectq.backends import IBMBackend
token='MY_TOKEN'
device='ibmq_16_melbourne'
compiler_engines = projectq.setups.ibm.get_engine_list(device=device)
eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024,
compiler_engines = projectq.setups.ibm.get_engine_list(token=token,device=device)
eng = MainEngine(IBMBackend(token=token, use_hardware=True, num_runs=1024,
verbose=False, device=device),
engine_list=compiler_engines)
**Running a quantum program on AQT devices**

To run a program on the AQT trapped ion quantum computer, choose the `AQTBackend` and the corresponding setup:

.. code-block:: python
import projectq.setups.aqt
from projectq.backends import AQTBackend
token='MY_TOKEN'
device='aqt_device'
compiler_engines = projectq.setups.aqt.get_engine_list(token=token,device=device)
eng = MainEngine(AQTBackend(token=token,use_hardware=True, num_runs=1024,
verbose=False, device=device),
engine_list=compiler_engines)
Expand Down
67 changes: 67 additions & 0 deletions examples/aqt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import matplotlib.pyplot as plt
import getpass

from projectq import MainEngine
from projectq.backends import AQTBackend
from projectq.libs.hist import histogram
from projectq.ops import Measure, Entangle, All
import projectq.setups.aqt


def run_entangle(eng, num_qubits=3):
"""
Runs an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
"""
# allocate the quantum register to entangle
qureg = eng.allocate_qureg(num_qubits)

# entangle the qureg
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 in results:
# print("Measured {} with p = {}.".format(state, results[state]))
# or plot them directly:
histogram(eng.backend, qureg)
plt.show()

# return one (random) measurement outcome.
return [int(q) for q in qureg]


if __name__ == "__main__":
#devices available to subscription:
# aqt_simulator (11 qubits)
# aqt_simulator_noise (11 qubits)
# aqt_device (4 qubits)
#
# To get a subscription, create a profile at :
# https://gateway-portal.aqt.eu/
#
device = None # replace by the AQT device name you want to use
token = None # replace by the token given by AQT
if token is None:
token = getpass.getpass(prompt='AQT token > ')
if device is None:
device = getpass.getpass(prompt='AQT device > ')
# create main compiler engine for the AQT back-end
eng = MainEngine(AQTBackend(use_hardware=True, token=token, num_runs=200,
verbose=False, device=device),
engine_list=projectq.setups.aqt.get_engine_list(
token=token, device=device))
# run the circuit and print the result
print(run_entangle(eng))
7 changes: 6 additions & 1 deletion examples/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ def run_entangle(eng, num_qubits=3):
# ibmq_16_melbourne (15 qubit)
# ibmq_essex (5 qubit)
# ibmq_qasm_simulator (32 qubits)
# and plenty of other 5 qubits devices!
#
# To get a token, create a profile at:
# https://quantum-computing.ibm.com/
#
device = None # replace by the IBM device name you want to use
token = None # replace by the token given by IBMQ
if token is None:
token = getpass.getpass(prompt='IBM Q token > ')
if device is None:
token = getpass.getpass(prompt='IBM device > ')
device = getpass.getpass(prompt='IBM device > ')
# create main compiler engine for the IBM back-end
eng = MainEngine(IBMBackend(use_hardware=True, token=token, num_runs=1024,
verbose=False, device=device),
Expand Down

0 comments on commit 6ef8a0e

Please sign in to comment.