Skip to content
ホーム/HLQuantum
✨ 推奨アプローチ — 一度書けば、どこでも実行

HLQuantum — 高レベル量子抽象化ライブラリ

量子ハードウェアの複雑さを抽象化するPythonライブラリです。HLQuantumで回路を一度書けば、コードを1行も変更することなく、IBM Qiskit、Google Cirq、Amazon Braket、PennyLane、NVIDIA CUDA-Q、IonQ上で実行できます。

オープンソース6つのバックエンド実機QPUGPU対応

なぜHLQuantumを使うのか?

🔁

一度書けば、どこでも実行

同じ回路コードが、対応する6つのバックエンドのいずれでも実行できます — 変換も書き直しも不要です。

GPUアクセラレーション内蔵

回路をNVIDIA GPUシミュレータへ透過的にルーティングし、大規模回路を大幅に高速化します。

🛡️

エラー緩和

ZNE、読み出し緩和などの手法が内蔵されており、引数を1つ指定するだけで適用できます。

🧠

組み込みアルゴリズム

QFT、Grover、VQE、QAOA、Bernstein-Vazirani — すぐに使え、バックエンドに依存しません。

🔀

非同期マルチバックエンド

ベンチマークや検証のために、複数のバックエンド上で同時に実験を実行できます。

🤖

AI / MCP連携

Model Context Protocolのサポートにより、AIエージェントが量子実験をオーケストレーションできます。

対応バックエンド

バックエンドフレームワークインストール実機QPU
qiskitIBM Qiskitpip install hlquantum[qiskit]対応
cirqGoogle Cirqpip install hlquantum[cirq]シミュレータのみ
pennylaneXanadu PennyLanepip install hlquantum[pennylane]シミュレータのみ
braketAmazon Braketpip install hlquantum[braket]対応
cudaqNVIDIA CUDA-Qpip install hlquantum[cudaq]シミュレータのみ
ionqIonQ (via Qiskit)pip install hlquantum[ionq]対応

クイックスタート

1. インストール

terminal
# Install with your preferred backend
pip install hlquantum[qiskit]     # IBM Qiskit backend
pip install hlquantum[cirq]       # Google Cirq backend
pip install hlquantum[pennylane]  # PennyLane backend
pip install hlquantum[braket]     # Amazon Braket backend
pip install hlquantum[cudaq]      # NVIDIA CUDA-Q backend
pip install hlquantum[ionq]       # IonQ backend

# Or install multiple at once
pip install "hlquantum[qiskit,cirq,cudaq]"

2. 最初の回路を作成する

hello_quantum.py
import hlquantum as hlq

# Create a 2-qubit circuit
qc = hlq.Circuit(2)

# Apply gates using the fluent API
qc.h(0).cx(0, 1).measure_all()

# Run on the default backend (auto-detects installed SDK)
result = hlq.run(qc, shots=1000)
print(result)
# {'00': 507, '11': 493}

3. フラグ1つでバックエンドを切り替える

switch_backends.py
import hlquantum as hlq

qc = hlq.Circuit(2)
qc.h(0).cx(0, 1).measure_all()

# The SAME circuit, on DIFFERENT backends — zero code changes
r1 = hlq.run(qc, shots=1000, backend="qiskit")   # Qiskit Aer
r2 = hlq.run(qc, shots=1000, backend="cirq")      # Google Cirq
r3 = hlq.run(qc, shots=1000, backend="pennylane") # PennyLane
r4 = hlq.run(qc, shots=1000, backend="cudaq")     # NVIDIA GPU
r5 = hlq.run(qc, shots=1000, backend="braket")    # Amazon Braket
r6 = hlq.run(qc, shots=1000, backend="ionq")      # IonQ

for name, result in zip(["Qiskit","Cirq","PennyLane","CUDA-Q","Braket","IonQ"],
                         [r1, r2, r3, r4, r5, r6]):
    print(f"{name}: {result}")

@kernelデコレータ

@hlq.kernelデコレータを使うと、量子ロジックを標準的なPython関数として記述できます。HLQuantumはそれらを自動的にコンパイルし、選択したバックエンド上で実行します。

kernel_example.py
import hlquantum as hlq

@hlq.kernel
def ghz_state(n: int):
    """Create an n-qubit GHZ state."""
    qubits = hlq.qvector(n)
    hlq.h(qubits[0])
    for i in range(n - 1):
        hlq.cx(qubits[i], qubits[i + 1])
    hlq.measure_all(qubits)

# Run the kernel
result = hlq.run(ghz_state, args=(5,), shots=1000)
print(result)  # {'00000': ~500, '11111': ~500}

# Works on any backend
result_gpu = hlq.run(
    ghz_state,
    args=(20,),       # 20-qubit GHZ!
    shots=1000,
    backend="cudaq"   # GPU acceleration
)

組み込み量子アルゴリズム

HLQuantumには、あらゆるバックエンドで動作する一般的な量子アルゴリズムのすぐに使える実装が含まれています。

量子フーリエ変換 (QFT)位相推定Shorのアルゴリズム

離散フーリエ変換の量子版です。Shorの素因数分解アルゴリズムをはじめ、多くのアルゴリズムでサブルーチンとして使用されます。

python
import hlquantum as hlq
from hlquantum.algorithms import QFT

# Create a QFT circuit for 4 qubits
qft_circuit = QFT(n_qubits=4)
result = hlq.run(qft_circuit, shots=1000)
print(result)

Groverの探索アルゴリズム探索二次的高速化

構造化されていない探索に対して二次的な高速化をもたらします。マークされた要素をN回ではなく√N回のステップで見つけます。

python
import hlquantum as hlq
from hlquantum.algorithms import Grover

# Search for item "101" in a 3-qubit space
grover = Grover(oracle_string="101")
result = hlq.run(grover.circuit, shots=2000)

# The marked state should have high probability
print(result)  # {'101': ~1800, others: ~200}

VQE — 変分量子固有値ソルバー化学最適化

ハミルトニアンの基底状態エネルギーを求めます。NISQデバイス上での量子化学における重要なアルゴリズムです。

python
import hlquantum as hlq
from hlquantum.algorithms import VQE
from hlquantum.operators import PauliSum

# Define Hamiltonian
H = PauliSum.from_list([
    ("ZZ", -1.052), ("IZ", 0.398),
    ("ZI", -0.398), ("XX", 0.181),
])

vqe = VQE(hamiltonian=H, n_qubits=2, ansatz="TwoLocal", reps=2)
energy, params = vqe.run(backend="qiskit", max_iter=200)
print(f"Ground state energy: {energy:.6f}")

QAOA — 量子近似最適化組合せ最適化

MaxCut、グラフ分割、スケジューリングなどの組合せ最適化問題に対する近似アルゴリズムです。

python
import hlquantum as hlq
from hlquantum.algorithms import QAOA
import networkx as nx

# Define a MaxCut problem
graph = nx.Graph([(0,1),(1,2),(2,3),(3,0),(0,2)])

qaoa = QAOA(problem="maxcut", graph=graph, p=2)
result = qaoa.run(backend="pennylane", shots=2000)
print(f"Best cut: {result.best_solution}")
print(f"Cut value: {result.best_value}")

量子MLレイヤーとパイプライン

HLQuantumには量子回路のためのMLに着想を得た構成が含まれており、PyTorchのnn.Sequentialと同様に、変分アンザッツを層状のモデルとして構築できます。

hl_pipeline.py
import hlquantum as hlq
from hlquantum.layers import RYLayer, EntanglingLayer, Sequential

# Build a variational quantum model
model = Sequential([
    RYLayer(n_qubits=4),         # Layer of RY rotations
    EntanglingLayer(n_qubits=4), # CNOT entangling layer
    RYLayer(n_qubits=4),         # Another RY layer
    EntanglingLayer(n_qubits=4),
])

# Run the model (initializes random params)
result = model.run(shots=1000, backend="pennylane")

# Train the model (gradient-based)
loss_history = model.fit(
    X_train, y_train,
    optimizer="adam",
    learning_rate=0.01,
    epochs=50
)

非同期マルチバックエンド実行

同じ回路を複数のバックエンド上で同時に実行し、結果を比較できます。ノイズレベルのベンチマークや、プラットフォーム間での結果検証に最適です。

async_run.py
import hlquantum as hlq
import asyncio

qc = hlq.Circuit(3)
qc.h(0).cx(0, 1).cx(1, 2).measure_all()

async def benchmark_backends():
    tasks = {
        name: hlq.run_async(qc, shots=1000, backend=name)
        for name in ["qiskit", "cirq", "pennylane", "cudaq"]
    }
    results = {name: await task for name, task in tasks.items()}

    for name, result in results.items():
        print(f"{name}: {result}")

asyncio.run(benchmark_backends())

エラー緩和

HLQuantumには、実機ハードウェアでの実行のための組み込みエラー緩和手法が含まれています。

error_mitigation.py
import hlquantum as hlq
from hlquantum.mitigation import ZNE, ReadoutMitigation

qc = hlq.Circuit(2)
qc.h(0).cx(0, 1).measure_all()

# Zero-Noise Extrapolation (ZNE)
mitigated_result = hlq.run(
    qc,
    shots=2000,
    backend="qiskit",
    device="ibm_sherbrooke",  # Real hardware
    mitigation=ZNE(noise_factors=[1, 2, 3])
)

# Readout error mitigation
result_mit = hlq.run(
    qc,
    shots=2000,
    backend="qiskit",
    mitigation=ReadoutMitigation()
)

print(f"Raw result:      {hlq.run(qc, shots=2000)}")
print(f"Mitigated result: {mitigated_result}")

GPUアクセラレーション

gpu_accel.py
import hlquantum as hlq

# Large circuit — 28 qubits
qc = hlq.Circuit(28)
for i in range(28):
    qc.h(i)
for i in range(27):
    qc.cx(i, i + 1)
qc.measure_all()

# CPU simulation (may be slow for 28 qubits)
result_cpu = hlq.run(qc, shots=100, backend="qiskit")

# GPU simulation — orders of magnitude faster!
result_gpu = hlq.run(qc, shots=100, backend="cudaq")  # NVIDIA
result_gpu2 = hlq.run(qc, shots=100, backend="pennylane",
                       device="lightning.gpu")           # lightning.gpu

print(f"CPU: {result_cpu}")
print(f"GPU (CUDA-Q): {result_gpu}")
🤖

AI駆動型量子コンピューティング (MCP)

HLQuantumはModel Context Protocol (MCP) のサポートを含んでおり、AIエージェントが量子回路を自律的に構築、最適化、実行できるようになります。これにより、AI駆動型の量子アルゴリズム発見という新たなパラダイムが実現します。

HLQuantumのMCP連携について学ぶ