AQT Cirq Tutorial

View on QuantumAI Run in Google Colab View source on GitHub Download notebook
try:
    import cirq
except ImportError:
    print("installing cirq...")
    !pip install --quiet cirq
    print("installed cirq.")

AQT supports Cirq as a third party software development kit and offers access to various quantum computing devices and simulators in the backend. Login to the AQT Gateway Portal to get a list of available devices.

After the Cirq installation has finished successfully, you are ready to use different backends by the use of a token and the corresponding backend URL like in the following getting started tutorial.

Use your AQT credentials

import cirq
from cirq.aqt.aqt_device import get_aqt_device
from cirq.aqt.aqt_sampler import AQTSampler
access_token = 'MY_TOKEN'

Where MY_TOKEN is your access token for a specific AQT device. You need to subscribe to an AQT backend at the AQT Gateway Portal and retrieve the access token. Then you can access the AQT device by:

device, qubits = get_aqt_device(2)
print(device)
0───1

Sample a quantum circuit

You can then use that device in Cirq. For example, preparing the Bell state

\[ |\psi\rangle=\frac{1}{\sqrt{2} }(|00\rangle-\mathrm{i}|11\rangle) \]

by writing

circuit = cirq.Circuit(device=device)
circuit.append([cirq.XX(qubits[0], qubits[1])**0.5])
device.validate_circuit(circuit)
print(circuit, qubits)
0: ───XX───────
      │
1: ───XX^0.5─── [cirq.LineQubit(0), cirq.LineQubit(1)]

This circuit can then be sampled on the real-hardware backend as well as on a simulator.

url = 'BACKEND_URL'
aqt_sampler = AQTSampler(url, access_token=access_token)
aqt_sweep = aqt_sampler.run(circuit, repetitions=100)
print(aqt_sweep)
m=1010010001010001111001001111000110010000111000011011110110101010010101001101111100011001000000100010, 1010010001010001111001001111000110010000111000011011110110101010010101001101111100011001000000100010

Where BACKEND_URL is the API URL of the AQT backend as specified in your subscription.

AQT Simulators

The AQT simulators are capable of running ideal simulations (without a noise model) and real simulations (with a noise model) of a quantum circuit. Using a simulator with noise model allows you to estimate the performance of running a circuit on the real hardware. Switching between the two simulation types is done by using the respective BACKEND_URL in above example.

For running a simulation without noise model use

url = 'https://gateway.aqt.eu/marmot/sim/'

whereas for a simulation with noise model use

url = 'https://gateway.aqt.eu/marmot/sim/noise-model-1'

We will provide different noise models in the future, which will be listed on the subscriptions page at the AQT Gateway Portal.