Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding AFQMC tutorial #1844

Merged
merged 122 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
5610636
adding afqmc tutorial
zohimchandani Jun 21, 2024
472da25
moving output files to source folder
zohimchandani Jun 21, 2024
e91d5b0
moving output files to source folder
zohimchandani Jun 21, 2024
7b280c3
removing the checkpoint files that are saved
zohimchandani Jun 21, 2024
203d840
minor changes for imports
sacpis Jul 18, 2024
402e7ed
formatting using yapf
sacpis Jul 18, 2024
57bb1d0
fix more formatting
sacpis Jul 18, 2024
20cba0b
fixing spellings
sacpis Jul 18, 2024
a41b6cc
sorting
sacpis Jul 18, 2024
78a7373
finally fixing sorting
sacpis Jul 18, 2024
fc75320
finally
sacpis Jul 18, 2024
1acc508
checking
sacpis Jul 18, 2024
d3d71ec
checking
sacpis Jul 18, 2024
1f8aaf0
cf
sacpis Jul 18, 2024
0446331
sort
sacpis Jul 18, 2024
2571e3b
checking if the script command for sorting works
sacpis Jul 18, 2024
11db2b1
adding a new line at the end of file
sacpis Jul 18, 2024
a69b2d7
keeping the sorted list as it was
sacpis Jul 18, 2024
79b6fd8
adding a few missing ones
sacpis Jul 18, 2024
7a91adc
running spellcheck
sacpis Jul 18, 2024
08b4082
manually sorting
sacpis Jul 18, 2024
f428ae0
one more
sacpis Jul 18, 2024
e8b38af
last one
sacpis Jul 18, 2024
ecc7b04
sorting in bash
sacpis Jul 18, 2024
0b17a0a
removing unwanted words from the spellcheck_allowlist which are used …
sacpis Jul 18, 2024
b6c39be
adding backticks to bypass some words from comments
sacpis Jul 18, 2024
88ca4dd
saving output, commenting out set_target
sacpis Jul 19, 2024
9897bec
adding required packages
sacpis Jul 19, 2024
c8d2f4b
fixing unclosed array
sacpis Jul 19, 2024
faca6c6
adding output
sacpis Jul 19, 2024
8e0ce59
commenting target to pass validation
sacpis Jul 19, 2024
eb40a42
fixing backticks and adding a new line
sacpis Jul 19, 2024
da5d1ce
adding pynb to tutorials
sacpis Jul 19, 2024
df91232
adding backtick
sacpis Jul 19, 2024
be384d6
Merge branch 'main' into main
sacpis Aug 5, 2024
eef783e
sorting
sacpis Aug 5, 2024
baab558
Merge branch 'main' into main
sacpis Aug 5, 2024
db8bc3c
adding missing dependencies, fixing warning in readme
sacpis Aug 5, 2024
76f0442
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 5, 2024
24ff4a0
adding dependencies in Linux variants wheels files
sacpis Aug 5, 2024
68aa755
Merge branch 'main' into main
sacpis Aug 5, 2024
8d3ee61
Merge branch 'main' into main
sacpis Aug 6, 2024
8feef19
skipping validation for utils_ipie.py
sacpis Aug 6, 2024
5d2a02d
skipping logic for afqmc.ipynb
sacpis Aug 6, 2024
31d54a5
ignoring a file for validation
sacpis Aug 6, 2024
c224d9f
fixing syntax error
sacpis Aug 6, 2024
0ace12b
indenting
sacpis Aug 6, 2024
7325316
Merge branch 'main' into main
sacpis Aug 6, 2024
1779d3e
Merge branch 'main' into main
sacpis Aug 6, 2024
ef07316
formatting inline string
sacpis Aug 6, 2024
82c9a72
Merge branch 'main' into main
sacpis Aug 6, 2024
e84e694
Merge branch 'main' into main
sacpis Aug 7, 2024
adb5778
removing third party libs
sacpis Aug 7, 2024
2e55785
minor changes
sacpis Aug 7, 2024
dbd556e
clearing output
sacpis Aug 7, 2024
c353840
Merge branch 'main' into main
sacpis Aug 7, 2024
89cc268
keeping output
sacpis Aug 7, 2024
54ff72d
Merge branch 'main' into main
sacpis Aug 8, 2024
9e9ee5e
adding cudaq version and formatting
sacpis Aug 8, 2024
f2fefff
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 8, 2024
fdfc01d
Merge branch 'main' into main
sacpis Aug 8, 2024
a3df618
adding new line character and removing space
sacpis Aug 8, 2024
52e8ed9
removing spaces
sacpis Aug 11, 2024
084aaff
Merge branch 'main' into main
sacpis Aug 11, 2024
fd2ef21
reverting changes
sacpis Aug 11, 2024
8bc7a38
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 11, 2024
90f9a64
making changes as requested
sacpis Aug 12, 2024
c637e18
removing output
sacpis Aug 12, 2024
d8d0e91
Merge branch 'main' into main
sacpis Aug 12, 2024
011476c
clearing output
sacpis Aug 12, 2024
1ee7b6a
Merge branch 'main' into main
sacpis Aug 12, 2024
dd1b2c8
adding a new code cell for packages
sacpis Aug 12, 2024
d06f8d8
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 12, 2024
3f4e60b
removing param, params from the allowlist
sacpis Aug 12, 2024
94bca81
Merge branch 'main' into main
sacpis Aug 12, 2024
f527313
upgrading pyscf to 2.6.2
sacpis Aug 12, 2024
9254d06
adding packages in docker_images in order to install it before valida…
sacpis Aug 13, 2024
aba1c8c
Merge branch 'main' into main
sacpis Aug 13, 2024
f3fba5b
reverting the change for accidental removal of code
sacpis Aug 13, 2024
567db30
removing packages as the core issue lies in unsetting UCX on the mach…
sacpis Aug 13, 2024
a0353e9
checking if unset OMPI_MCA_pml is being executed in CI
sacpis Aug 13, 2024
66cac58
checking OMPI_MCA_pml value before unsetting it
sacpis Aug 14, 2024
71c09a8
Merge branch 'main' into main
sacpis Aug 14, 2024
3d6bce7
removing print and unsetting value in shell script
sacpis Aug 14, 2024
b152d1a
checking OMPI_MCA_pml value
sacpis Aug 14, 2024
9acde4d
Merge branch 'main' into main
sacpis Aug 14, 2024
5d08aa8
removing env var from shell script
sacpis Aug 14, 2024
e4f8516
trying to build binaries from source in order to check the compatibil…
sacpis Aug 14, 2024
556ff5c
Merge branch 'main' into main
sacpis Aug 14, 2024
fd014c6
Revert "trying to build binaries from source in order to check the co…
sacpis Aug 14, 2024
20cb785
pip installing pyscf only
sacpis Aug 15, 2024
115e77c
trying to install only packages
sacpis Aug 15, 2024
5780cda
formatting
sacpis Aug 15, 2024
6879267
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 15, 2024
b544893
trying to import classes from a module after installing it
sacpis Aug 15, 2024
dfa99ba
adding pkg-config libhdf5-dev required for pyscf
sacpis Aug 15, 2024
4f0b6e3
adding apt-get update
sacpis Aug 15, 2024
c5e991d
adding sudo for apt-get
sacpis Aug 15, 2024
11a8a9d
Merge branch 'main' into main
sacpis Aug 15, 2024
43cad31
specifying the version of h5py lib
sacpis Aug 15, 2024
94bcd0a
using pip install to specify version
sacpis Aug 15, 2024
e94e690
Merge branch 'main' into main
sacpis Aug 16, 2024
f4bb383
Merge branch 'main' into main
sacpis Aug 17, 2024
4176dde
removing from module as it is already used in a separate cell
sacpis Aug 17, 2024
b97b01c
keeping only the necessary imports
sacpis Aug 19, 2024
54e0eed
clearing cell output
sacpis Aug 19, 2024
b7e0273
Merge branch 'main' into main
sacpis Aug 19, 2024
34912c8
Merge branch 'main' into main
sacpis Aug 20, 2024
9c4acf8
Merge branch 'main' into main
sacpis Aug 20, 2024
f5abcac
Merge branch 'main' into main
sacpis Aug 20, 2024
6d359ed
setting cudaq target to nvidia
sacpis Aug 20, 2024
4f9b384
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 20, 2024
cd63c41
Merge branch 'main' into main
sacpis Aug 20, 2024
85f596d
reverting changes to unrelevant files
sacpis Aug 20, 2024
446669b
setting h5py to be less than 3.11 rather than equal to 3.10.0
sacpis Aug 20, 2024
b2bdd18
Merge branch 'main' of https://github.com/zohimchandani/cuda-quantum
sacpis Aug 20, 2024
65d792b
Merge branch 'main' into main
sacpis Aug 20, 2024
49c42c8
Merge branch 'main' into main
sacpis Aug 20, 2024
a155bba
Merge branch 'main' into main
sacpis Aug 21, 2024
c7f379c
adding single quotes around h5py
sacpis Aug 21, 2024
c04381f
Fixing the error FromAsCasing: 'as' and 'FROM' keywords casing do not
sacpis Aug 21, 2024
5ebd250
Merge branch 'main' into main
sacpis Aug 21, 2024
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
13 changes: 13 additions & 0 deletions .github/workflows/config/spelling_allowlist.txt
sacpis marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ABI
AFQMC
sacpis marked this conversation as resolved.
Show resolved Hide resolved
API
APIs
AST
Expand Down Expand Up @@ -48,7 +49,9 @@ JupyterLab
Kagome
Kraus
LLVM
LPX
LSB
LXmn
Libraries
MCA
MLIR
Expand Down Expand Up @@ -153,6 +156,7 @@ coreset
cortex-cli
coupler
couplers
cpp
cuQuantum
cuTensor
cudaq
Expand Down Expand Up @@ -212,6 +216,7 @@ instantiations
interferometer
interoperational
intrinsics
ipie
iterable
iteratively
kets
Expand All @@ -230,13 +235,20 @@ namespace
namespaces
natively
normalization
np
nullary
nvidia
occa
occb
openfermion
sacpis marked this conversation as resolved.
Show resolved Hide resolved
optimizer
optimizers
parallelization
parallelize
parallelizing
param
parameterization
params
sacpis marked this conversation as resolved.
Show resolved Hide resolved
performant
photonic
precompute
Expand All @@ -246,6 +258,7 @@ preprocessor
probability
programmatically
pybind
pyscf
sacpis marked this conversation as resolved.
Show resolved Hide resolved
quantize
quantized
qubit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ jobs:
docker run --rm -dit --name wheel-validation-examples wheel_validation:local
status_sum=0

for ex in `find docs/sphinx/examples/python -name '*.py' -not -path '*/providers/*' -not -path '*/divisive_clustering_src/*'`; do
for ex in `find docs/sphinx/examples/python -name '*.py' -not -path '*/providers/*' -not -path '*/divisive_clustering_src/*' -not -path '*/utils_ipie.py' -not -path '*/vqe_cudaq_qnp.py'`; do
sacpis marked this conversation as resolved.
Show resolved Hide resolved
file="${ex#docs/sphinx/examples/python/}"
echo "__Example ${file}:__" >> /tmp/validation.out
(docker exec wheel-validation-examples bash -c "python${{ inputs.python_version }} /tmp/examples/$file" >> /tmp/validation.out) && success=true || success=false
Expand Down
4 changes: 4 additions & 0 deletions docs/notebook_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def validate(notebook_filename, available_backends):
match = re.search('--target ([^ ]+)', notebook_content)
if match and (match.group(1) not in available_backends):
return False
for notebook_content in lines:
match = re.search('(config.update_option)', notebook_content)
sacpis marked this conversation as resolved.
Show resolved Hide resolved
if match and match.group(1):
return False
return True


Expand Down
581 changes: 581 additions & 0 deletions docs/sphinx/examples/python/tutorials/afqmc.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 115 additions & 37 deletions docs/sphinx/examples/python/tutorials/readout_error_mitigation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,60 @@
"execution_count": 1,
"id": "04b58854-7dab-4f1b-8c59-d8b9506bce44",
"metadata": {},
"outputs": [],
"outputs": [
sacpis marked this conversation as resolved.
Show resolved Hide resolved
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: matplotlib==3.8.4 in /usr/local/lib/python3.10/dist-packages (3.8.4)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (1.4.5)\n",
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (24.0)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (3.1.2)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (0.12.1)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (1.2.1)\n",
"Requirement already satisfied: numpy>=1.21 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (1.26.4)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (2.9.0.post0)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (4.51.0)\n",
"Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.8.4) (10.3.0)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib==3.8.4) (1.16.0)\n",
"\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
"\u001b[0mRequirement already satisfied: pandas==2.2.2 in /usr/local/lib/python3.10/dist-packages (2.2.2)\n",
"Requirement already satisfied: numpy>=1.22.4 in /usr/local/lib/python3.10/dist-packages (from pandas==2.2.2) (1.26.4)\n",
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas==2.2.2) (2024.1)\n",
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas==2.2.2) (2024.1)\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas==2.2.2) (2.9.0.post0)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas==2.2.2) (1.16.0)\n",
"\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
"\u001b[0mCollecting scipy==1.13.1\n",
" Using cached scipy-1.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.6 MB)\n",
"Requirement already satisfied: numpy<2.3,>=1.22.4 in /usr/local/lib/python3.10/dist-packages (from scipy==1.13.1) (1.26.4)\n",
"Installing collected packages: scipy\n",
" Attempting uninstall: scipy\n",
" Found existing installation: scipy 1.13.0\n",
" Uninstalling scipy-1.13.0:\n",
" Successfully uninstalled scipy-1.13.0\n",
"Successfully installed scipy-1.13.1\n",
"\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
"\u001b[0mRequirement already satisfied: seaborn==0.13.2 in /usr/local/lib/python3.10/dist-packages (0.13.2)\n",
"Requirement already satisfied: numpy!=1.24.0,>=1.20 in /usr/local/lib/python3.10/dist-packages (from seaborn==0.13.2) (1.26.4)\n",
"Requirement already satisfied: matplotlib!=3.6.1,>=3.4 in /usr/local/lib/python3.10/dist-packages (from seaborn==0.13.2) (3.8.4)\n",
"Requirement already satisfied: pandas>=1.2 in /usr/local/lib/python3.10/dist-packages (from seaborn==0.13.2) (2.2.2)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (4.51.0)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (1.4.5)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (1.2.1)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (3.1.2)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (0.12.1)\n",
"Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (10.3.0)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (2.9.0.post0)\n",
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (24.0)\n",
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.2->seaborn==0.13.2) (2024.1)\n",
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.2->seaborn==0.13.2) (2024.1)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.4->seaborn==0.13.2) (1.16.0)\n",
"\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
"\u001b[0m"
]
}
],
"source": [
"# Install the relevant packages.\n",
"\n",
Expand Down Expand Up @@ -91,12 +144,13 @@
" Args:\n",
" n_qubits (int): The number of qubits in the quantum circuit.\n",
" probs (Union[float, list[float]]): Probabilities of a bit flip error occurring on each qubit.\n",
" If a single probability value is provided, it will be applied to all qubits. If a list of\n",
" probabilities is provided, each qubit will have its own probability.\n",
" If a single probability value is provided, it will be applied to all qubits. If a list of\n",
" probabilities is provided, each qubit will have its own probability.\n",
"\n",
" Returns:\n",
" cudaq noise model\n",
" \"\"\"\n",
" \n",
" noise = cudaq.NoiseModel()\n",
"\n",
" if not isinstance(probs, list):\n",
Expand Down Expand Up @@ -130,9 +184,7 @@
" for i, val in enumerate(state_label):\n",
" if val == 1:\n",
" x(qvector[i])\n",
" rx(\n",
" 0.0, qvector[i]\n",
" ) # Identity gate at the end on each qubit to model readout error\n",
" rx(0.0, qvector[i]) # Identity gate at the end on each qubit to model readout error\n",
" mz(qvector)"
]
},
Expand Down Expand Up @@ -229,8 +281,14 @@
"\n",
" # Constraint: all elements of p must be positive, and the distribution must sum to 1\n",
" cons = (\n",
" {\"type\": \"ineq\", \"fun\": lambda p: p},\n",
" {\"type\": \"eq\", \"fun\": lambda p: np.sum(p) - 1},\n",
" {\n",
" \"type\": \"ineq\",\n",
" \"fun\": lambda p: p\n",
" },\n",
" {\n",
" \"type\": \"eq\",\n",
" \"fun\": lambda p: np.sum(p) - 1\n",
" },\n",
" )\n",
" bnds = [(0, 1) for _ in range(len(empirical_dist))]\n",
" initial_value = np.random.uniform(size=len(empirical_dist))\n",
Expand Down Expand Up @@ -332,10 +390,14 @@
"\n",
"noise_1 = get_noise(n_qubits, p)\n",
"\n",
"ghz_result = cudaq.sample(ghz_kernel, n_qubits, shots_count=shots, noise_model=noise_1)\n",
"ghz_result = cudaq.sample(ghz_kernel,\n",
" n_qubits,\n",
" shots_count=shots,\n",
" noise_model=noise_1)\n",
"noisy_dict_1 = dict(list(ghz_result.items()))\n",
"\n",
"noisy_res_1 = np.array([noisy_dict_1.get(state, 0) for i, state in enumerate(states)])\n",
"noisy_res_1 = np.array(\n",
" [noisy_dict_1.get(state, 0) for i, state in enumerate(states)])\n",
"\n",
"noisy_dict_1"
]
Expand Down Expand Up @@ -378,10 +440,14 @@
"\n",
"noise_2 = get_noise(n_qubits, p)\n",
"\n",
"ghz_result = cudaq.sample(ghz_kernel, n_qubits, shots_count=shots, noise_model=noise_2)\n",
"ghz_result = cudaq.sample(ghz_kernel,\n",
" n_qubits,\n",
" shots_count=shots,\n",
" noise_model=noise_2)\n",
"noisy_dict_2 = dict(list(ghz_result.items()))\n",
"\n",
"noisy_res_2 = np.array([noisy_dict_2.get(state, 0) for i, state in enumerate(states)])\n",
"noisy_res_2 = np.array(\n",
" [noisy_dict_2.get(state, 0) for i, state in enumerate(states)])\n",
"\n",
"noisy_dict_2"
]
Expand Down Expand Up @@ -485,7 +551,8 @@
"source": [
"A = reduce(np.kron, [A_1] * n_qubits) # joint confusion matrix\n",
"A_pinv = np.linalg.pinv(A) # Generate pseudoinverse confusion matrix.\n",
"mitigated = np.array(np.dot(A_pinv, noisy_res_1), dtype=int) # Obtain mitigated counts\n",
"mitigated = np.array(np.dot(A_pinv, noisy_res_1),\n",
" dtype=int) # Obtain mitigated counts\n",
"print(f\"Mitigated counts:\\n{mitigated}\")\n",
"\n",
"if not np.all(mitigated >= 0):\n",
Expand All @@ -512,15 +579,16 @@
}
],
"source": [
"df = pd.DataFrame(\n",
" {\n",
" \"states\": states,\n",
" \"noisy\": np.around(noisy_res_1 / sum(noisy_res_1), 3),\n",
" \"mitigated_sg\": np.around(mitigated / sum(mitigated), 3),\n",
" }\n",
")\n",
"df = pd.DataFrame({\n",
" \"states\": states,\n",
" \"noisy\": np.around(noisy_res_1 / sum(noisy_res_1), 3),\n",
" \"mitigated_sg\": np.around(mitigated / sum(mitigated), 3),\n",
"})\n",
"\n",
"ax = df.plot(x=\"states\", y=[\"noisy\", \"mitigated_sg\"], kind=\"bar\", figsize=(8, 5))\n",
"ax = df.plot(x=\"states\",\n",
" y=[\"noisy\", \"mitigated_sg\"],\n",
" kind=\"bar\",\n",
" figsize=(8, 5))\n",
"ax.bar_label(ax.containers[0], labels=df[\"noisy\"])\n",
"ax.bar_label(ax.containers[1], labels=df[\"mitigated_sg\"])\n",
"ax.set_ylabel(\"probabilities\")\n",
Expand Down Expand Up @@ -561,8 +629,11 @@
"local_states = [\"0\" * n_qubits, \"1\" * n_qubits]\n",
"\n",
"results = [\n",
" cudaq.sample(kernel, n_qubits, label, shots_count=shots, noise_model=noise_2)\n",
" for label in local_labels\n",
" cudaq.sample(kernel,\n",
" n_qubits,\n",
" label,\n",
" shots_count=shots,\n",
" noise_model=noise_2) for label in local_labels\n",
"]\n",
"\n",
"for i, state in enumerate(local_states):\n",
Expand All @@ -585,7 +656,9 @@
"metadata": {},
"outputs": [],
"source": [
"counts = [dict(list(results[i].items())) for i, state in enumerate(local_states)]\n",
"counts = [\n",
" dict(list(results[i].items())) for i, state in enumerate(local_states)\n",
"]\n",
"matrices = []\n",
"\n",
"for k in range(n_qubits):\n",
Expand All @@ -600,7 +673,8 @@
" # matrix[i][j] is the probability of counting i for expected j\n",
" for i in range(2):\n",
" for j in range(2):\n",
" matrix[i][j] = marginalized_counts[j].get(str(i), 0) / total_shots[j]\n",
" matrix[i][j] = marginalized_counts[j].get(str(i),\n",
" 0) / total_shots[j]\n",
" matrices.append(matrix)"
]
},
Expand Down Expand Up @@ -697,15 +771,16 @@
}
],
"source": [
"df = pd.DataFrame(\n",
" {\n",
" \"states\": states,\n",
" \"noisy\": np.around(noisy_res_2 / sum(noisy_res_2), 3),\n",
" \"mitigated_k_local\": np.around(mitigated / sum(mitigated), 3),\n",
" }\n",
")\n",
"df = pd.DataFrame({\n",
" \"states\": states,\n",
" \"noisy\": np.around(noisy_res_2 / sum(noisy_res_2), 3),\n",
" \"mitigated_k_local\": np.around(mitigated / sum(mitigated), 3),\n",
"})\n",
"\n",
"ax = df.plot(x=\"states\", y=[\"noisy\", \"mitigated_k_local\"], kind=\"bar\", figsize=(8, 5))\n",
"ax = df.plot(x=\"states\",\n",
" y=[\"noisy\", \"mitigated_k_local\"],\n",
" kind=\"bar\",\n",
" figsize=(8, 5))\n",
"ax.bar_label(ax.containers[0], labels=df[\"noisy\"])\n",
"ax.bar_label(ax.containers[1], labels=df[\"mitigated_k_local\"])\n",
"ax.set_ylabel(\"probabilities\")\n",
Expand Down Expand Up @@ -745,8 +820,11 @@
],
"source": [
"results = [\n",
" cudaq.sample(kernel, n_qubits, label, shots_count=shots, noise_model=noise_2)\n",
" for label in labels\n",
" cudaq.sample(kernel,\n",
" n_qubits,\n",
" label,\n",
" shots_count=shots,\n",
" noise_model=noise_2) for label in labels\n",
"]\n",
"\n",
"for i, state in enumerate(states):\n",
Expand Down Expand Up @@ -866,7 +944,7 @@
" x=\"states\",\n",
" y=[\"noisy\", \"mitigated_k_local\", \"mitigated_full\"],\n",
" kind=\"bar\",\n",
" figsize=(12, 5),\n",
" figsize=(12, 5)\n",
")\n",
"ax.bar_label(ax.containers[0], labels=df[\"noisy\"])\n",
"ax.bar_label(ax.containers[1], labels=df[\"mitigated_k_local\"])\n",
Expand All @@ -892,7 +970,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
28 changes: 28 additions & 0 deletions docs/sphinx/examples/python/tutorials/src/geo_fenta.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
26
Energy = -2155.935897674
C -1.0290441 -0.9471117 -1.9865887
C -2.2505436 -0.7922495 0.1582250
C -0.2593185 -2.2544373 0.0162178
O -1.3454085 0.8783278 -3.5342318
O -1.1347371 1.1483476 1.0151618
O 0.8453748 -2.7999130 2.0922098
O -0.2780587 1.3040005 -1.6070564
O -3.2498211 0.8000765 1.6534429
C -0.9188318 0.5115628 -2.4417824
C -2.2565356 0.4618854 1.0159078
C 0.5342286 -1.9274094 1.2848894
N -0.9221422 -1.0235290 -0.5013883
Fe 0.2526900 0.4497192 0.0039380
O 1.8221685 -0.2815654 -1.0936915
H -1.9555949 -1.4065777 -2.3473606
H -0.1824638 -1.4867161 -2.4264081
H -2.5130292 -1.6526686 0.7833244
H -3.0320380 -0.6959329 -0.6040366
H 0.4617231 -2.6044401 -0.7316186
H -0.9840969 -3.0551564 0.1969690
H 2.1227503 0.3853924 -1.7373941
H 2.5891208 -0.4447721 -0.5150575
O 0.9052095 -0.6681693 1.3941789
O 1.4573655 1.9796179 0.5273073
H 1.0868407 2.8424014 0.2685815
H 1.5840897 2.0352695 1.4913642
5 changes: 5 additions & 0 deletions docs/sphinx/examples/python/tutorials/src/geo_o3.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
Energy
O 0.0000000 0.0000000 0.0000000
O 0.0000000 0.0000000 1.2717000
O 1.1383850 0.0000000 1.8385340
Loading
Loading