Code Monkey home page Code Monkey logo

bqcloud's Introduction

Blueqat cloud SDK (bqcloud)

Client SDK for Blueqat cloud.

Install

pip install blueqat-cloud

Handling API key

Register API

import bqcloud
api = bqcloud.register_api("Your API key here")

Your API key is stored to $HOME/.bqcloud/api_key. If you don't want to save API key, use insteads following codes.

import bqcloud
api = bqcloud.api.Api("Your API key here")

Load API

Once API key is saved, the key can be loaded from file.

import bqcloud
api = bqcloud.load_api()

Available Machines

IonQAria1
IonQHarmony
OqcLucy
AspenM3

Gate

Create a task

from blueqat import Circuit
from bqcloud import load_api, Device
api = load_api()

task = api.execute(Circuit().h[0].cx[0, 1], Device.IonQDevice, 10)

Show a status

print(task.status())

Update a task

task.update()

Wait a task

# Wait until task is done. It may takes so long time.
result = task.wait()
print(result.shots())
# 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")

Get fetched result again

# 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")

List tasks

tasks = api.tasks()
print(list(tasks))
if tasks[0].result() is not None:
    print(tasks[0].result().shots())

bqcloud's People

Contributors

gyu-don avatar minatoyuichiro avatar t-k avatar

Watchers

 avatar  avatar  avatar

Forkers

kuantumbs

bqcloud's Issues

Executor model

class AbstractExecutor: def execute(self, Device, options: dict) -> AbstractTask
class CloudExecutor: AbstractExecutor
class LocalExecutor: AbstractExecutor
Api.get_executor(self) -> CloudExecutor
get_local_executor() -> LocalExecutor

It simplifies API class dispatching.

Cloud gzip response

headers = {
    "Content-Type": "application/json",
    "X-Api-Key": API_KEY,
    "Accept-Encoding": "gzip",
}

with urllib.request.urlopen(req) as res:
    body = (
        gzip.decompress(res.read())
        if res.headers.get("Content-Encoding") == "gzip"
        else res.read()
    )

Q: Does res.read() returns bytes or str?

Multiple API keys

Store and load multiple API keys.
This feature is needed for working with trusted partners.

api からの annealing でエラーになる

blueqat のクラウド環境において、このリポジトリのサンプルを参考にアニーリングを実行すると、エラーが発生します。
しかし、ジョブは投げられており、blueqat の API key のページで参照すると、結果が戻ってきています。


TypeError Traceback (most recent call last)
in
1 import bqcloud
2 api = bqcloud.load_api()
----> 3 api.annealing([[-1, 0], [0, 0.5]], 5, 10)

/opt/conda/lib/python3.9/site-packages/bqcloud/api.py in annealing(self, qubo, chain_strength, num_reads)
79 "num_reads": num_reads
80 })
---> 81 return AnnealingResult(**res)
82
83 def execute(self,

TypeError: init() got an unexpected keyword argument 'task'

Local simulator device

Make a device that runs a local simulator. It is required for developing and debugging.

BraketResult.shots() should see measured_qubits

c = Circuit().x[0, 1, 3]
rigg = api.execute(c, Device.Aspen9, shots=50)
rigg.wait().shots()
# Expected: 1011, Actual: Counter({'101': 2, '110': 2, '111': 36, '011': 8, '001': 2})

The number of qubits is changed.

rigg.wait().result is as following.

GateModelQuantumTaskResult(
..., # Omitted
measured_qubits=[0, 1, 3],
measurement_counts=Counter({'111': 36, '011': 8, '101': 2, '110': 2, '001': 2}),
measurement_probabilities={'101': 0.04, '110': 0.04, '111': 0.72, '011': 0.16, '001': 0.04}, measurements_copied_from_device=True,
measurement_counts_copied_from_device=False, measurement_probabilities_copied_from_device=False,
_result_types_indices={})

So, BraketResult should check measured_qubits and reconstruct the Counter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.