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 quantum computing devices and simulators in the backend. Visit www.aqt.eu to find available resources and information on how to get access to them.

After the Cirq installation has finished successfully, you are ready to use the offline simulator or different backends through the use of an access token and the corresponding parameters, as 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 the AQT Arnica API. Then you can retrieve the information which workspaces and quantum resources are available for you:

AQTSampler.fetch_resources(access_token)

Then you can specify the workspace and resource you want to send your quantum circuits to.

workspace = 'WORKSPACE_NAME'
resource = 'RESOURCE_NAME'
aqt_sampler = AQTSampler(workspace=workspace, resource=resource, access_token=access_token)

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(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.

aqt_sweep = aqt_sampler.run(circuit, repetitions=100)
print(aqt_sweep)
m=1010010001010001111001001111000110010000111000011011110110101010010101001101111100011001000000100010, 1010010001010001111001001111000110010000111000011011110110101010010101001101111100011001000000100010

Offline simulation of AQT devices

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 setting the simulate_ideal flag, as in the example below.

For running a simulation without noise model use

from cirq.aqt.aqt_sampler import AQTSamplerLocalSimulator

aqt_sampler = AQTSamplerLocalSimulator(simulate_ideal=True)

whereas for a simulation with noise model use

from cirq.aqt.aqt_sampler import AQTSamplerLocalSimulator

aqt_sampler = AQTSamplerLocalSimulator(simulate_ideal=False)

Then you can use the Sampler Simulator as you would the regular one, for example:

aqt_sweep = aqt_sampler.run(circuit, repetitions=100)
print(aqt_sweep)