Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-24.04
tools:
python: "3.13"


# Build documentation in the "doc/" directory with Sphinx
sphinx:
configuration: docs/conf.py


# Optionally build your docs in additional formats such as PDF and ePub
formats:
- pdf
- epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
# This installs the package qiskit-calculquebec to ensure the code is available for autodoc reponsible for
# generating the API reference documentation.
- method: pip
path: .
80 changes: 52 additions & 28 deletions docs/FR/mitigation_exemple.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
" project_id=os.getenv(\"PROJECT_ID\"),\n",
")\n",
"backend = MonarQBackend(\"yukon\", my_client)\n",
"shots = 1000"
"shots = 1000"
]
},
{
Expand Down Expand Up @@ -111,17 +111,16 @@
"# Qubits physiques après transpilation\n",
"if transpiled_qc.layout and transpiled_qc.layout.final_layout:\n",
" physical_qubits = [\n",
" transpiled_qc.layout.final_layout[q]\n",
" for q in transpiled_qc.qubits\n",
" transpiled_qc.layout.final_layout[q] for q in transpiled_qc.qubits\n",
" ]\n",
"else:\n",
" physical_qubits = list(range(3))\n",
"\n",
"print(f\"Qubits physiques : {physical_qubits}\")\n",
"\n",
"# Exécution brute (référence)\n",
"sampler = Sampler(mode=backend)\n",
"job = sampler.run([transpiled_qc], shots=shots)\n",
"sampler = Sampler(mode=backend)\n",
"job = sampler.run([transpiled_qc], shots=shots)\n",
"counts_raw = job.result()[0].data.meas.get_counts()\n",
"print(f\"Counts bruts : {counts_raw}\")"
]
Expand Down Expand Up @@ -167,21 +166,23 @@
}
],
"source": [
"rem_matrix = ReadoutMitigation(backend, method='matrix')\n",
"rem_matrix = ReadoutMitigation(backend, method=\"matrix\")\n",
"rem_matrix.cals_from_system()\n",
"\n",
"# Afficher les fidélités\n",
"print(\"Fidélités de lecture (method='matrix') :\")\n",
"for q, info in zip(range(backend.target.num_qubits), rem_matrix.readout_fidelity()):\n",
" if info is not None:\n",
" print(f\" qubit {q:2d} : P(0|0)={info['p00']:.4f} P(1|1)={info['p11']:.4f} moy={info['mean']:.4f}\")\n",
" print(\n",
" f\" qubit {q:2d} : P(0|0)={info['p00']:.4f} P(1|1)={info['p11']:.4f} moy={info['mean']:.4f}\"\n",
" )\n",
"\n",
"# Correction\n",
"counts_rem_matrix = rem_matrix.apply_correction(counts_raw, qubits=physical_qubits)\n",
"print(f\"\\nCounts bruts : {counts_raw}\")\n",
"print(f\"Counts mitigés (matrix) : {counts_rem_matrix}\")\n",
"\n",
"#plot_histogram([counts_raw,counts_rem_matrix], legend=[\"raw\",\"mitig\"])"
"# plot_histogram([counts_raw,counts_rem_matrix], legend=[\"raw\",\"mitig\"])"
]
},
{
Expand Down Expand Up @@ -210,14 +211,22 @@
"\n",
"fig, ax = plt.subplots(figsize=(7, 5))\n",
"im = ax.imshow(inv_A, cmap=\"RdBu\", vmin=-1, vmax=1)\n",
"ax.set_xticks(range(2**n)); ax.set_yticks(range(2**n))\n",
"ax.set_xticks(range(2**n))\n",
"ax.set_yticks(range(2**n))\n",
"ax.set_xticklabels(labels, rotation=45, ha=\"right\")\n",
"ax.set_yticklabels(labels)\n",
"ax.set_title(f\"Matrice inverse de confusion ({2**n}×{2**n})\")\n",
"for i in range(2**n):\n",
" for j in range(2**n):\n",
" ax.text(j, i, f\"{inv_A[i,j]:.2f}\", ha=\"center\", va=\"center\", fontsize=7,\n",
" color=\"black\" if abs(inv_A[i,j]) < 0.5 else \"white\")\n",
" ax.text(\n",
" j,\n",
" i,\n",
" f\"{inv_A[i,j]:.2f}\",\n",
" ha=\"center\",\n",
" va=\"center\",\n",
" fontsize=7,\n",
" color=\"black\" if abs(inv_A[i, j]) < 0.5 else \"white\",\n",
" )\n",
"plt.colorbar(im)\n",
"plt.tight_layout()\n",
"plt.show()"
Expand Down Expand Up @@ -249,7 +258,7 @@
}
],
"source": [
"rem_m3 = ReadoutMitigation(backend, method='m3')\n",
"rem_m3 = ReadoutMitigation(backend, method=\"m3\")\n",
"rem_m3.cals_from_system()\n",
"\n",
"# Correction M3\n",
Expand Down Expand Up @@ -446,11 +455,19 @@
"from mitiq.zne.scaling import fold_global\n",
"\n",
"configs = [\n",
" (\"Richardson [1,2,3] + fold_random\", RichardsonFactory([1.0, 2.0, 3.0]), None),\n",
" (\"Richardson [1,3,5] + fold_random\", RichardsonFactory([1.0, 3.0, 5.0]), None),\n",
" (\"Linear [1,1.5,2,2.5,3] + fold_random\", LinearFactory([1.0, 1.5, 2.0, 2.5, 3.0]), None),\n",
" (\"Richardson [1,2,3] + fold_global\", RichardsonFactory([1.0, 2.0, 3.0]), fold_global),\n",
" (\"Linear [1,2,3] + fold_global\", LinearFactory([1.0, 2.0, 3.0]), fold_global),\n",
" (\"Richardson [1,2,3] + fold_random\", RichardsonFactory([1.0, 2.0, 3.0]), None),\n",
" (\"Richardson [1,3,5] + fold_random\", RichardsonFactory([1.0, 3.0, 5.0]), None),\n",
" (\n",
" \"Linear [1,1.5,2,2.5,3] + fold_random\",\n",
" LinearFactory([1.0, 1.5, 2.0, 2.5, 3.0]),\n",
" None,\n",
" ),\n",
" (\n",
" \"Richardson [1,2,3] + fold_global\",\n",
" RichardsonFactory([1.0, 2.0, 3.0]),\n",
" fold_global,\n",
" ),\n",
" (\"Linear [1,2,3] + fold_global\", LinearFactory([1.0, 2.0, 3.0]), fold_global),\n",
"]\n",
"\n",
"print(f\"{'Config':50s} {'Mitigé':>8} {'Erreur':>8}\")\n",
Expand Down Expand Up @@ -585,12 +602,14 @@
" qc.h(0)\n",
" qc.cx(0, 1)\n",
" for _ in range(depth):\n",
" qc.id(0); qc.id(1)\n",
" qc.id(0)\n",
" qc.id(1)\n",
" qc.cx(0, 1)\n",
" qc.h(0)\n",
" qc.measure(range(n), range(n))\n",
" return qc\n",
"\n",
"\n",
"DEPTHS = [4, 10, 30, 50]\n",
"results_ddd = {d: {} for d in DEPTHS}\n",
"\n",
Expand All @@ -602,7 +621,9 @@
" raw = ddd.run_unmitigated(circuit)\n",
" mit = ddd.run(circuit)\n",
" results_ddd[depth][rule] = mit\n",
" print(f\" rule={rule:<5} : brut={raw:.4f} DDD={mit:.4f} err={abs(1.0-mit):.4f}\")"
" print(\n",
" f\" rule={rule:<5} : brut={raw:.4f} DDD={mit:.4f} err={abs(1.0-mit):.4f}\"\n",
" )"
]
},
{
Expand All @@ -619,7 +640,7 @@
"outputs": [],
"source": [
"# Initialiser REM une seule fois\n",
"rem = ReadoutMitigation(backend, method='m3')\n",
"rem = ReadoutMitigation(backend, method=\"m3\")\n",
"rem.cals_from_system()\n",
"\n",
"# Récupérer les qubits physiques du circuit idle\n",
Expand All @@ -631,11 +652,11 @@
"else:\n",
" phys = list(range(circuit_idle.num_qubits))\n",
"\n",
"ddd_rem = DDDMitigation(backend, rule='xyxy', num_trials=3)\n",
"ddd_rem = DDDMitigation(backend, rule=\"xyxy\", num_trials=3)\n",
"\n",
"val_raw = ddd_rem.run_unmitigated(circuit_idle)\n",
"val_ddd = ddd_rem.run(circuit_idle)\n",
"val_ddd_rem = ddd_rem.run(circuit_idle, rem=rem, qubits=phys)\n",
"val_raw = ddd_rem.run_unmitigated(circuit_idle)\n",
"val_ddd = ddd_rem.run(circuit_idle)\n",
"val_ddd_rem = ddd_rem.run(circuit_idle, rem=rem, qubits=phys)\n",
"\n",
"print(f\"Brut : {val_raw:.4f} (err={abs(1.0-val_raw):.4f})\")\n",
"print(f\"DDD xyxy : {val_ddd:.4f} (err={abs(1.0-val_ddd):.4f})\")\n",
Expand Down Expand Up @@ -695,8 +716,8 @@
"source": [
"pt_zne = PauliTwirlingMitigation(backend, num_variants=10)\n",
"\n",
"raw = pt_zne.run_unmitigated(qc_pt)\n",
"pt_only = pt_zne.run(qc_pt)\n",
"raw = pt_zne.run_unmitigated(qc_pt)\n",
"pt_only = pt_zne.run(qc_pt)\n",
"pt_zne_val = pt_zne.run_with_zne(qc_pt)\n",
"\n",
"print(f\"Brut : {raw:.4f}\")\n",
Expand All @@ -705,6 +726,7 @@
"\n",
"# Avec factory personnalisée\n",
"from mitiq.zne.inference import RichardsonFactory\n",
"\n",
"val_rich = pt_zne.run_with_zne(\n",
" qc_pt,\n",
" factory=RichardsonFactory([1.0, 2.0, 3.0]),\n",
Expand All @@ -731,12 +753,14 @@
"# Résumé : P(|000⟩) pour le circuit GHZ 3 qubits (idéal = 0.5)\n",
"ideal = 0.5\n",
"\n",
"\n",
"def p000_from_counts(counts, n_shots=shots):\n",
" return counts.get(\"000\", 0) / n_shots\n",
"\n",
"raw_p = p000_from_counts(counts_raw)\n",
"\n",
"raw_p = p000_from_counts(counts_raw)\n",
"rem_matrix_p = p000_from_counts(counts_rem_matrix)\n",
"rem_m3_p = p000_from_counts(counts_rem_m3)\n",
"rem_m3_p = p000_from_counts(counts_rem_m3)\n",
"\n",
"print(f\"{'Technique':<30} {'P(|000⟩)':>10} {'Erreur':>8}\")\n",
"print(\"-\" * 52)\n",
Expand Down
Loading