common.title

Overview
Service overview
Terms of service

Privacy policy

Contact

Sign in
Sign up
common.title

Run the IonQ and Rigetti via blueqat cloud

gyu-don

2021/04/22 07:41

Run the IonQ and Rigetti via blueqat cloud

I'm very happy to inform you that now we can run IonQ and Rigetti quantum computers via blueqat cloud! All you have to learn is only blueqat. You don't need to read the docs of other quantum computing libraries.

Usage is described in bqcloud README , but I demonstrate mainly usage for it

Register your API key

First, you may want to register the API key to a local file.

    • When your API key is not stored (e.g. you use it the first time), you can store the key as follows.
from bqcloud import register_api api = register_api("API KEY HERE")
    • When the key is stored, you can load as follows.
from bqcloud import load_api api = load_api()
    • If you don't want to store the key, you can use API for the session.
import bqcloud api = bqcloud.api.Api("API KEY HERE")

Execution of quantum circuit via cloud

Circuit of blueqat can run on blueqat cloud.

Now, measurement is automatically done in all qubit. So you don't contain measuring in the circuit. (Specifications may change in the future)

    • Run with IonQ device
from blueqat import Circuit from bqcloud import Device # Circuit, Device, the number of shots, group name (Optional) task = api.execute(Circuit().h[0].cx[0, 1], Device.IonQDevice, 10, "hello-world") # You may omit group name as follows, but it is useful for searching your tasks after. # task = api.execute(Circuit().h[0].cx[0, 1], Device.IonQDevice, 10)
    • Run with Rigettiデバイス(Aspen-9)
from blueqat import Circuit from bqcloud import Device # Circuit, Device, the number of shots, group name (Optional) task2 = api.execute(Circuit().h[0].cx[0, 1], Device.Aspen9, 10, "hello-world") # You may omit group name as follows, but it is useful for searching your tasks after. # task = api.execute(Circuit().h[0].cx[0, 1], Device.Aspen9, 10)

Handling the task

These machines are not always running and tasks may queued for running. So, the server returns Task before complete to run the circuit.

Display the status

You can display the status of task as follows. If status is Status.COMPLETED, the result is ready.

print(task.status())
Status.QUEUED

Update the task

You can update the task to latest state. Update after completed, the result is fetched.

task.update()

Wait for complete

Following code is the way to waiting for the task to complete. If call task.wait() with the time for timeout (second), None is returned when timeout occured. The time for timeout is zero or omitted, it waits until complete the task and returns the result.

# Wait 10 sec. If complete, result is returned, otherwise, None is returned. result = task.wait(timeout=10) if result: print(result.shots()) else: print("timeout")
timeout

Get the result of completed task

Once the task is completed and updated, you can get the result as follows.

# Once updated or waited after task completed, task.result() returns the result. result = task.result() if result: print(result.shots()) else: print("result is not fetched.")
result is not fetched.

© 2024, blueqat Inc. All rights reserved