common.title

Docs
Quantum Circuit
TYTAN CLOUD

QUANTUM GAMING


Overview
Contact
Event
Project
Research

Terms of service (Web service)

Terms of service (Quantum and ML Cloud service)

Privacy policy


Sign in
Sign up
common.title

blueqatクラウドでのAPIによる量子コンピュータジョブ投入:IonQ・IQM・OQCへの対応について

Yuichiro Minato

2025/05/27 01:09

blueqatクラウドでのAPIによる量子コンピュータジョブ投入:IonQ・IQM・OQCへの対応について

はじめに

blueqatでは、クラウド経由で複数の量子コンピュータにジョブを投入できる環境を提供しています。研究用途から企業での応用まで、柔軟に対応可能な設計となっており、現在は主に IonQIQM、および OQC へのジョブ実行が可能です。

ジョブの投入方式は各バックエンドごとに異なり、以下のように分かれています:

  • IonQ / IQM:Qiskit を経由してジョブを投入
  • OQC:OpenQASM 形式の回路を専用インターフェースから実行(専用回線経由)

IonQ / IQM へのジョブ投入(Qiskit経由)

blueqatでは、Qiskit をベースとした回路定義により、IonQおよびIQMの量子プロセッサにジョブを投入できます。

🔹 特徴

  • Qiskitで記述した回路をそのまま送信可能
  • blueqatのAPI経由でクラウド実行(Qiskitとの統合をバックエンド側で吸収)
  • 結果はJSON形式で取得可能

🔹 利用例(簡略)

from enum import Enum
import httpx
from qiskit import qpy
import io
from qiskit import QuantumCircuit
from qiskit.result import Result
import json

UA = "blueqat/1.0 (blueqatQuantumTaskAPI; +https://blueqat.com/)"

class Device(str, Enum):
    Harmony = "Harmony"
    Aria_1 = "Aria 1"
    Aria_2 = "Aria 2"
    Forte_1 = "Forte 1"
    Garnet = "Garnet"

class BqQuantumTaskClient:
    api_key: str
    endpoint: str

    def __init__(
        self, api_key: str, endpoint: str = "https://quantum-task-api.blueqat.com"
    ):
        self.api_key = api_key
        self.endpoint = endpoint

    async def create_quantum_task(
        self, circuit: QuantumCircuit, device: Device, shots: int
    ) -> Result:
        buffer = io.BytesIO()
        qpy.dump(circuit, buffer)
        buffer.seek(0)
        files = {
            "qpyfile": (
                "qpy",
                buffer,
                "data:application/octet-stream",
            ),
        }
        async with httpx.AsyncClient() as client:
            headers = {
                "user-agent": UA,
                "x-api-key": self.api_key,
                "accept-encoding": "gzip, deflate",
            }
            result = await client.post(
                f"{self.endpoint}/v1/jobs/create",
                files=files,
                data={
                    "shots": shots,
                    "backend": device.value,
                },
                headers=headers,
                timeout=None,
            )

            # --- ここから修正 ---
            if result.status_code != 200:
                raise Exception(f"HTTP Error {result.status_code}: {result.text}")

            if not result.content:
                raise Exception("Empty response from server.")

            content_type = result.headers.get("Content-Type", "")
            if "application/json" not in content_type:
                raise Exception(f"Expected JSON response, got: {content_type}\nBody: {result.text}")

            try:
                data = result.json()
            except json.JSONDecodeError as e:
                raise Exception(f"Failed to parse JSON: {e}\nRaw response: {result.text}")

            if "ok" not in data or not data["ok"]:
                raise Exception(data.get("error", "Unknown error occurred"))

            payload = data["payload"]
            return Result.from_dict(payload)
            # --- 修正ここまで ---

    async def get_quantum_task(self, job_id: str) -> Result:
        async with httpx.AsyncClient() as client:
            result = await client.post(
                f"{self.endpoint}/v1/jobs/get",
                data=json.dumps({"job_id": job_id}),
                headers=self.get_default_headers(),
                timeout=None,
            )
            data = result.json()
            if "ok" not in data or not data["ok"]:
                raise Exception(data["error"])
            payload = data["payload"]
            return Result.from_dict(payload)

    def get_default_headers(self):
        return {
            "user-agent": UA,
            "x-api-key": self.api_key,
            "accept-encoding": "gzip, deflate",
            "content-type": "application/json",
        }

qc = QuantumCircuit(3) 
qc.h(0) 
for qubit in range(1, 3): 
    qc.cx(0, qubit)

api_key = "<設定画面から確認可能>"
client = BqQuantumTaskClient( api_key=api_key, )

task= await client.create_quantum_task( circuit=qc, shots=1, device=Device.<デバイス名>, )

result = await client.get_quantum_task( job_id=task.job_id, )

※ APIキーは個人の設定から確認できます。

OQC へのジョブ投入(OpenQASM + 専用回線)

Oxford Quantum Circuits (OQC) へのジョブ投入には、OpenQASM 形式で記述した量子回路を、専用ネットワーク環境下のインターフェースを通じて送信する必要があります。

🔹 特徴

  • 回路形式は OpenQASM に準拠
  • 通信には専用回線(セキュアトンネル)を使用
  • blueqatが提供する専用ツール/環境設定が必要
  • セットアップ・利用は個別対応(要お問い合わせ)
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
h q[0];
cx q[0], q[1];
measure q[0] -> c[0];
measure q[1] -> c[1];

ご利用対象と導入条件

現在のAPI提供は blueqatと契約済みの企業様 を主対象としていますが、個人でも利用できます。

お問い合わせ

以下の内容についてお気軽にご相談ください:

  • 利用申請・トライアル導入
  • API仕様書・サンプルコードのご提供
  • OQC専用環境の構築支援

まとめ

blueqatの提供する量子ジョブ投入APIは、IonQやIQMに対する Qiskitベースのスムーズな実行 に加え、OQCのようなハードウェア特性に応じた柔軟な対応が可能です。量子ハードウェアを意識せず、共通的なインターフェースで開発と実行が進められる環境をご提供しています。

今後も対応ハードウェアやツールの拡充が予定されており、業務や研究における量子技術の実装を加速させる一助となるはずです。

© 2025, blueqat Inc. All rights reserved