はじめての量子計算QUANTUM COMPUTING FROM ZERO

動かして学ぶ、量子計算Learn quantum computing by running it

重ね合わせ・もつれから、QAOA・VQE・論文の再現まで。各章の終わりに演習として Arena の課題があり、結果は実行記録として残ります。社内研修にも使える印刷版があります。From superposition and entanglement to QAOA, VQE and reproducing papers. Each chapter ends with Arena challenges as exercises, and results are kept as run records. A printable edition works for in-house training.

はじめるStart 印刷用(日本語)Printable (Japanese)印刷用(英語)Printable (English)
目次Contents
  1. 準備:量子シミュレータをつなぐSetup: connect to the simulator
  2. 量子ビットと重ね合わせQubits and superposition
  3. もつれ(エンタングルメント)Entanglement
  4. たくさんの量子ビットをもつれさせるEntangling many qubits
  5. 重ね合わせを設計するDesigning superpositions
  6. 組合せ最適化と QUBOCombinatorial optimization and QUBO
  7. QAOA のつまみを回すTuning QAOA
  8. 制約を罰金で入れるConstraints as penalties
  9. VQE でエネルギーを求めるFinding energies with VQE
  10. 論文を再現するReproducing papers
  11. 次のステップNext steps

0準備:量子シミュレータをつなぐSetup: connect to the simulator

このコースでは、blueqat の量子シミュレータを実際に動かしながら、量子計算の基本を順番に学びます。数式はできるだけ使いません。This course teaches the basics of quantum computing step by step, by actually running circuits on blueqat's quantum simulator. We keep the math to a minimum.

まず ログイン して、アカウントページで API キー を発行します(無料)。これがあなたの鍵です。First sign in and issue an API key on your account page (free). That is your key.

使い方は2通りあります。AI エージェントから使う(MCP) なら、Claude などの AI エージェントにこのサーバーをつなぎ、日本語で依頼するだけで回路を組んで実行します。REST API から使う なら、https://qapi.blueqat.app に JSON を送ります。There are two ways to work. From an AI agent (MCP): connect Claude or another AI to this server and just ask in plain words -- it builds and runs the circuits. From the REST API: send JSON to https://qapi.blueqat.app.

実行するたびに run_id(実行の ID)が返ってきます。これがあなたの記録で、https://mcp.blueqat.app/runs/{run_id} で誰でも確かめられます。Every run returns a run_id. That is your record, and anyone can check it at https://mcp.blueqat.app/runs/{run_id}.

AI(Claude Code)につなぐConnect an AI (Claude Code)

claude mcp add --transport http blueqat https://mcp.blueqat.app/mcp --header "Authorization: Bearer YOUR_API_KEY"

ほかの MCP クライアント: streamable-HTTP で https://mcp.blueqat.app/mcp を追加し、Authorization: Bearer に API キー。Other MCP clients: add https://mcp.blueqat.app/mcp as streamable-HTTP with your API key in Authorization: Bearer.

1量子ビットと重ね合わせQubits and superposition

普通のビットは 0 か 1 のどちらかです。量子ビット は、測るまで 0 と 1 の両方の可能性を持っていられます。これを 重ね合わせ といいます。An ordinary bit is either 0 or 1. A qubit can hold both possibilities until it is measured. This is called superposition.

量子ビットは最初 0 です。アダマールゲート h をかけると、0 と 1 が半々の重ね合わせになります。測ると、毎回どちらか一方が出て、たくさん測ると半々になります。A qubit starts at 0. The Hadamard gate h turns it into an equal superposition of 0 and 1. Each measurement gives one or the other; over many shots you see half and half.

確率を自分で決めることもできます。ry(θ) は量子ビットを角度 θ だけ回すゲートで、1 が出る確率は sin²(θ/2) になります。θ = π/3(約 1.047)なら sin²(π/6) = 1/4 です。You can set the probability yourself. ry(θ) rotates the qubit by an angle θ, and the probability of 1 is sin²(θ/2). With θ = π/3 (about 1.047), that is sin²(π/6) = 1/4.

1 を確率 p で出したいときは、θ = 2·arcsin(√p) と計算します。p = 1/3 なら θ ≈ 1.231 です。To get 1 with probability p, use θ = 2·arcsin(√p). For p = 1/3, θ ≈ 1.231.

例(そのまま動きます)Example (runs as-is)

run_circuit({"n_qubits": 1, "gates": [{"gate": "h", "qubits": [0]}], "shots": 256})

0 と 1 がだいたい 128 回ずつ出ます。0 and 1 each come out about 128 times.

演習(Arena の課題)Exercises (Arena challenges)

2もつれ(エンタングルメント)Entanglement

2つの量子ビットを もつれ させると、別々に測っても結果がいつも揃うようになります。片方が 0 ならもう片方も 0、1 なら 1 です。When two qubits are entangled, their results always agree even though you measure them separately: if one is 0, so is the other; if one is 1, so is the other.

作り方は2手です。1つ目の量子ビットに h をかけて重ね合わせにし、CNOT cx で2つ目にコピーします。cx は「1つ目が 1 のときだけ2つ目をひっくり返す」ゲートです。It takes two gates. Put the first qubit in superposition with h, then copy it onto the second with CNOT cx -- a gate that flips the second qubit only when the first is 1.

これが ベル状態 です。測ると 00 と 11 だけが半々で出て、01 や 10 は出ません。This is a Bell state. Measuring it gives only 00 and 11, half and half -- never 01 or 10.

最後に2つ目を x でひっくり返すと、01 と 10 だけが出る「いつも反対になる」もつれになります。Flip the second qubit with x at the end and you get the always-opposite pair: only 01 and 10.

例(そのまま動きます)Example (runs as-is)

run_circuit({"n_qubits": 2, "gates": [{"gate": "h", "qubits": [0]}, {"gate": "cx", "qubits": [0, 1]}], "shots": 256})

ビット列は左端が qubit 0 です。00 と 11 だけが出ます。The leftmost bit is qubit 0. Only 00 and 11 appear.

演習(Arena の課題)Exercises (Arena challenges)

3たくさんの量子ビットをもつれさせるEntangling many qubits

ベル状態は3つ以上にも広げられます。h のあと cx を鎖のようにつなぐと、全部 0 か全部 1 だけが出る GHZ 状態 になります。Bell states extend to three or more qubits. After h, chain cx gates and you get a GHZ state: only all-zeros or all-ones.

もつれ方は1種類ではありません。W 状態 は「1 がちょうど1つだけ立った状態」を均等に重ねたもので、GHZ とは性質が違います。There is more than one kind of entanglement. A W state is an equal superposition of the strings with exactly one 1, and it behaves differently from GHZ.

cx を2つ使って、ある量子ビットに他の2つの 偶奇(パリティ) を書き込むこともできます。1 の数が偶数の状態だけが出るようになります。Two cx gates can write the parity of two qubits onto a third, so only strings with an even number of ones appear.

Arena では、同じ分布をより 少ないゲート数 で作った結果が上位になります。ゲートを減らす工夫を考えてみましょう。In the Arena, whoever makes the same distribution with fewer gates ranks higher. Look for ways to cut gates.

例(そのまま動きます)Example (runs as-is)

run_circuit({"n_qubits": 3, "gates": [{"gate": "h", "qubits": [0]}, {"gate": "cx", "qubits": [0, 1]}, {"gate": "cx", "qubits": [1, 2]}], "shots": 256})

000 と 111 だけが出ます。Only 000 and 111 appear.

演習(Arena の課題)Exercises (Arena challenges)

4重ね合わせを設計するDesigning superpositions

h を並べると 2, 4, 8… 通りの一様な重ね合わせが作れますが、3通り のように 2 の累乗でない数は作れません。A row of h gates makes uniform superpositions of 2, 4, 8… outcomes, but not of 3 or any number that is not a power of two.

そこで 制御つきのゲート を使います。まず ry で1つの量子ビットを「1 が 1/3」にし、それが 0 のときだけもう1つに h をかけます(制御アダマール ch)。That is where controlled gates come in. First use ry to make one qubit 1 with probability 1/3, then apply h to another qubit only when the first is 0 (a controlled Hadamard, ch).

ch は「制御の量子ビットが 1 のとき」に働くので、0 のときに働かせたいときは、前後を x ではさみます。ch acts when its control is 1; to act on 0 instead, sandwich it between x gates.

こうすると 00・10・01 の3通りがちょうど 1/3 ずつになります。同じ考え方で W 状態や Dicke 状態も作れます。The result is 00, 10 and 01 at exactly 1/3 each. The same idea builds W and Dicke states.

例(そのまま動きます)Example (runs as-is)

run_circuit({"n_qubits": 2, "gates": [{"gate": "ry", "qubits": [1], "params": [1.231]}, {"gate": "x", "qubits": [1]}, {"gate": "ch", "qubits": [1, 0]}, {"gate": "x", "qubits": [1]}], "shots": 256})

ry の角度 1.231 は 2·arcsin(√(1/3)) です。00・10・01 がほぼ均等に出ます。The ry angle 1.231 is 2·arcsin(√(1/3)). 00, 10 and 01 come out about equally.

演習(Arena の課題)Exercises (Arena challenges)

5組合せ最適化と QUBOCombinatorial optimization and QUBO

「どれを選ぶと一番良いか」を探す問題を 組合せ最適化 といいます。候補が増えると、全部を調べるのはすぐ無理になります。Problems that ask "which choice is best?" are combinatorial optimization. As candidates grow, checking them all quickly becomes impossible.

量子コンピュータで解くには、問題を QUBO の形に書きます。0 か 1 の変数 q を並べ、係数 × q_i や 係数 × q_i × q_j の和を 最小にする 形です。To solve one on a quantum computer, write it as a QUBO: 0/1 variables q, and a sum of coeff × q_i and coeff × q_i × q_j terms to minimize.

例えば MaxCut は、グラフの頂点を2色に塗り、色の違う辺をできるだけ多くする問題です。各辺 (i, j) について 2·q_i·q_j − q_i − q_j を足すと、色が違う辺ごとに −1 になるので、最小化すれば切れる辺が最大になります。Take MaxCut: colour a graph's vertices with two colours so that as many edges as possible join different colours. Adding 2·q_i·q_j − q_i − q_j for each edge (i, j) gives −1 for every cut edge, so minimizing maximizes the cut.

Arena の最適化の課題では QUBO が決められています。そのまま run_qaoa に渡してください。The Arena's optimization challenges fix the QUBO for you. Pass it to run_qaoa as given.

例Example: MaxCut:三角形MaxCut: triangle

run_qaoa(qubo=[{"coeff": -2.0, "qubits": [0]}, {"coeff": -2.0, "qubits": [1]}, {"coeff": -2.0, "qubits": [2]}, {"coeff": 2.0, "qubits": [0, 1]}, {"coeff": 2.0, "qubits": [0, 2]}, {"coeff": 2.0, "qubits": [1, 2]}], steps=2, shots=256)

演習(Arena の課題)Exercises (Arena challenges)

6QAOA のつまみを回すTuning QAOA

QAOA は、量子回路の角度を古典コンピュータで調整しながら、良い答えが出やすい状態を作る方法です。QAOA builds a state that tends to give good answers, while a classical computer tunes the circuit's angles.

つまみは3つあります。steps(深さ)を上げると表現力が増えます。seed(種)を変えると調整の出発点が変わります。n_starts を増やすと、複数の出発点から一番良いものを選びます。There are three knobs. Raising steps (depth) adds expressive power. Changing seed changes where tuning starts. Raising n_starts tries several starts and keeps the best.

返り値の best は「サンプルの中で値が最小のもの」です。いちばん多く出た状態(most_frequent)が最適とは限りません。答えには best を使いましょう。The result's best is the lowest-value sample. The most frequent state (most_frequent) is not always optimal -- quote best.

Arena では、サンプルのうち 最適解が出た割合 が高いほど上位です。パラメータを調整して、割合を上げてください。In the Arena you rank by the share of samples that are optimal. Turn the knobs to raise it.

例Example: MaxCut:6頂点のグラフMaxCut: 6-vertex graph

run_qaoa(qubo=[{"coeff": -2.0, "qubits": [0]}, {"coeff": -3.0, "qubits": [1]}, {"coeff": -3.0, "qubits": [2]}, {"coeff": -3.0, "qubits": [3]}, {"coeff": -3.0, "qubits": [4]}, {"coeff": -2.0, "qubits": [5]}, {"coeff": 2.0, "qubits": [0, 1]}, {"coeff": 2.0, "qubits": [0, 2]}, {"coeff": 2.0, "qubits": [1, 2]}, {"coeff": 2.0, "qubits": [1, 3]}, {"coeff": 2.0, "qubits": [2, 4]}, {"coeff": 2.0, "qubits": [3, 4]}, {"coeff": 2.0, "qubits": [3, 5]}, {"coeff": 2.0, "qubits": [4, 5]}], steps=2, shots=256)

演習(Arena の課題)Exercises (Arena challenges)

7制約を罰金で入れるConstraints as penalties

「ちょうど2人を選ぶ」「隣どうしは選ばない」といった 制約 は、QUBO では 罰金の項 として入れます。制約を破ると値が大きくなるようにするのです。Constraints such as "choose exactly two" or "never choose neighbours" enter a QUBO as penalty terms that make the value large when broken.

例えば「ちょうど k 個」なら (Σq − k)² に重み A を掛けて足します。A が小さすぎると制約を破った答えが勝ち、大きすぎると QAOA が解きにくくなります。For "exactly k", add A·(Σq − k)². If A is too small, rule-breaking answers win; too large, and QAOA struggles.

最大独立集合(隣り合わない頂点をできるだけ多く)は、選んだ数に −1、隣り合う2つを選ぶと +2 の罰金、という QUBO になります。Maximum independent set (as many vertices as possible, none adjacent) becomes −1 per chosen vertex and a +2 penalty for choosing two neighbours.

例Example: ちょうど 2 個を選ぶ:5人から2人を夜勤に(負担の小さい2人)Choose exactly 2: pick 2 of 5 staff for the night shift (lightest load)

run_qaoa(qubo=[{"coeff": -33.0, "qubits": [0]}, {"coeff": -35.0, "qubits": [1]}, {"coeff": -32.0, "qubits": [2]}, {"coeff": -35.0, "qubits": [3]}, {"coeff": -31.0, "qubits": [4]}, {"coeff": 24.0, "qubits": [0, 1]}, {"coeff": 24.0, "qubits": [0, 2]}, {"coeff": 24.0, "qubits": [0, 3]}, {"coeff": 24.0, "qubits": [0, 4]}, {"coeff": 24.0, "qubits": [1, 2]}, {"coeff": 24.0, "qubits": [1, 3]}, {"coeff": 24.0, "qubits": [1, 4]}, {"coeff": 24.0, "qubits": [2, 3]}, {"coeff": 24.0, "qubits": [2, 4]}, {"coeff": 24.0, "qubits": [3, 4]}], steps=2, shots=256)

演習(Arena の課題)Exercises (Arena challenges)

8VQE でエネルギーを求めるFinding energies with VQE

物理や化学では、ものの一番低いエネルギー(基底エネルギー)を知りたいことがよくあります。エネルギーは ハミルトニアン という式で表します。Physics and chemistry often need the lowest energy of a system, its ground-state energy, written as a Hamiltonian.

ハミルトニアンは パウリ演算子(X・Y・Z)の積の和で書きます。例えば −Z0 Z1 は「隣どうしが揃うと得」、−X0 は「横向きの磁場」です。A Hamiltonian is a sum of products of Pauli operators (X, Y, Z). For example −Z0 Z1 rewards aligned neighbours and −X0 is a transverse field.

VQE は、回路の角度を調整してエネルギーをできるだけ下げる方法です。変分原理 により、得られる値は必ず本当の基底エネルギー以上になります。VQE tunes a circuit's angles to push the energy down. By the variational principle, the result is never below the true ground-state energy.

run_vqe の layers(層の数)を増やすと、本当の値に近づきやすくなります。Arena では、厳密な値との差が小さいほど上位です。More layers in run_vqe usually get closer. In the Arena, the smaller your gap to the exact value, the higher you rank.

例Example: 横磁場イジング鎖:2量子ビット・h=1.0(臨界点)Transverse-field Ising chain: 2 qubits, h=1.0 (critical)

run_vqe(n_qubits=2, hamiltonian=[{"coeff": -1.0, "paulis": [{"op": "Z", "qubit": 0}, {"op": "Z", "qubit": 1}]}, {"coeff": -1.0, "paulis": [{"op": "X", "qubit": 0}]}, {"coeff": -1.0, "paulis": [{"op": "X", "qubit": 1}]}], layers=2)

演習(Arena の課題)Exercises (Arena challenges)

9論文を再現するReproducing papers

研究では、論文に書かれた数値を 自分の手で再現できるか がとても大切です。In research it matters a great deal whether a published number can be reproduced by someone else.

Farhi ら(2014) は、輪のグラフの MaxCut を深さ1の QAOA で解くと、切れる辺の割合(近似率)が 3/4 になることを示しました。6頂点の輪で確かめてみましょう。Farhi et al. (2014) showed that depth-1 QAOA on MaxCut of a ring cuts 3/4 of the edges on average (the approximation ratio). Check it on a 6-cycle.

O'Malley ら(2016) は、水素分子 H₂ の基底エネルギーを量子コンピュータで求めました。同じハミルトニアンを VQE で解くと、約 −1.137 ハートリーになります。O'Malley et al. (2016) computed the ground-state energy of H₂ on a quantum computer. Solving the same Hamiltonian with VQE gives about −1.137 hartree.

Arena の論文再現の課題では、実行結果が論文の値にどれだけ近いかで順位がつきます。Paper challenges rank you by how close your run comes to the published value.

演習(Arena の課題)Exercises (Arena challenges)

10次のステップNext steps

ここまでで、重ね合わせ・もつれ・QUBO と QAOA・VQE・論文再現をひと通り体験しました。You have now worked through superposition, entanglement, QUBO and QAOA, VQE, and reproducing papers.

Arena には、回路・最適化・物理・論文再現のベンチマーク課題が多数あります。結果は実行記録として残り、リーダーボード の各順位は記録までたどれます。The Arena has many more benchmark challenges across circuits, optimization, physics and paper reproduction. Results are kept as run records, and every leaderboard entry traces back to one.

AI エージェント(MCP)から使うと、エージェントが返り値の改善のヒントを読み、実行と提出を繰り返せます。業務の検証や社内研修にもお使いください。Over MCP, an AI agent can read the improvement hints in each result and keep running and submitting. It also suits internal evaluation and training.

実機(量子コンピュータ)での評価も準備中です。Evaluation on real quantum hardware is on the way.