{ "cells": [ { "cell_type": "markdown", "id": "noisy-run-0", "metadata": {}, "source": [ "# A noisy run\n", "\n", "A job may name noise channels: `depolarizing_1q`, `depolarizing_2q`, `amplitude_damping`, `dephasing` and `readout`, each a probability. The density matrix is exact; trajectories are an estimate, reported with a standard error; a Clifford circuit with Pauli noise samples Pauli frames." ] }, { "cell_type": "code", "execution_count": 1, "id": "noisy-run-1", "metadata": { "execution": { "iopub.execute_input": "2026-11-11T12:23:55.075966Z", "iopub.status.busy": "2026-11-11T12:23:55.075881Z", "iopub.status.idle": "2026-11-11T12:23:55.081150Z", "shell.execute_reply": "2026-11-11T12:23:55.080713Z" } }, "outputs": [], "source": [ "import wai_quantum as wq" ] }, { "cell_type": "code", "execution_count": 2, "id": "noisy-run-2", "metadata": { "execution": { "iopub.execute_input": "2026-11-11T12:23:55.082015Z", "iopub.status.busy": "2026-11-11T12:23:55.081940Z", "iopub.status.idle": "2026-11-11T12:23:55.084498Z", "shell.execute_reply": "2026-11-11T12:23:55.084339Z" } }, "outputs": [ { "data": { "text/plain": [ "Key(did:key:z6MkehRgf7yJbgaGfYsdoAsKdBPE3dj2CYhowQdcjqSJgvVd, in memory)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A fixed key for this page, so that its receipts repeat byte for byte when it runs\n", "# again. Keep a key of your own: wq.Key.generate().save(\"my.key\"), then\n", "# wq.Key.from_file(\"my.key\"); with no key given, wq.run signs with this user's key,\n", "# the command line's.\n", "key = wq.Key(bytes(range(32)))\n", "key" ] }, { "cell_type": "code", "execution_count": 3, "id": "noisy-run-3", "metadata": { "execution": { "iopub.execute_input": "2026-11-11T12:23:55.085190Z", "iopub.status.busy": "2026-11-11T12:23:55.085125Z", "iopub.status.idle": "2026-11-11T12:23:55.088765Z", "shell.execute_reply": "2026-11-11T12:23:55.088538Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Z0 Z1 exact 0.957788 estimate 0.9580 ± 0.0045\n", "Z1 Z2 exact 0.978667 estimate 0.9850 ± 0.0027\n", "X0 X1 X2 exact 0.865765 estimate 0.8680 ± 0.0079\n", "exact estimate\n" ] } ], "source": [ "ghz = \"OPENQASM 3.0; qubit[3] q; bit[3] c; h q[0]; cx q[0], q[1]; cx q[1], q[2]; c = measure q;\"\n", "noise = {\"depolarizing_2q\": 0.02, \"dephasing\": 0.01, \"readout\": 0.01}\n", "exact = wq.run(ghz, observables=[\"Z0 Z1\", \"Z1 Z2\", \"X0 X1 X2\"], noise=noise, method=\"density_matrix\", key=key)\n", "estimate = wq.run(ghz, observables=[\"Z0 Z1\", \"Z1 Z2\", \"X0 X1 X2\"], noise=noise, method=\"trajectories\", shots=4000, seed=3, key=key)\n", "for e, t in zip(exact.result[\"expectations\"], estimate.result[\"expectations\"]):\n", " print(f\"{e['observable']:<9} exact {e['value']:.6f} estimate {t['value']:.4f} ± {t['stderr']:.4f}\")\n", "print(exact.accuracy, estimate.accuracy)" ] }, { "cell_type": "markdown", "id": "noisy-run-4", "metadata": {}, "source": [ "Each result says how it was made. The estimate's counts are samples of noisy shots:" ] }, { "cell_type": "code", "execution_count": 4, "id": "noisy-run-5", "metadata": { "execution": { "iopub.execute_input": "2026-11-11T12:23:55.089368Z", "iopub.status.busy": "2026-11-11T12:23:55.089295Z", "iopub.status.idle": "2026-11-11T12:23:55.135149Z", "shell.execute_reply": "2026-11-11T12:23:55.134826Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1719bebf8da14d69abc5f95030bcc389", "version_major": 2, "version_minor": 1 }, "text/html": [ "