Skip to content

Commit

Permalink
Update Dice how-to (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-johnson authored Sep 25, 2024
1 parent 7791689 commit 12e4918
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions docs/how_tos/integrate_dice_solver.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
"\n",
"import numpy as np\n",
"from pyscf import ao2mo, tools\n",
"from qiskit_addon_dice_solver import solve_dice\n",
"from qiskit_addon_dice_solver import solve_fermion\n",
"from qiskit_addon_sqd.configuration_recovery import recover_configurations\n",
"from qiskit_addon_sqd.counts import counts_to_arrays, generate_counts_uniform\n",
"from qiskit_addon_sqd.fermion import (\n",
" bitstring_matrix_to_ci_strs,\n",
" flip_orbital_occupancies,\n",
")\n",
"from qiskit_addon_sqd.subsampling import postselect_and_subsample\n",
Expand All @@ -56,13 +55,12 @@
"# Convert counts into bitstring and probability arrays\n",
"bitstring_matrix_full, probs_arr_full = counts_to_arrays(counts_dict)\n",
"\n",
"# SQSD options\n",
"# SQD options\n",
"iterations = 5\n",
"\n",
"# Eigenstate solver options\n",
"n_batches = 5\n",
"samples_per_batch = 300\n",
"max_davidson_cycles = 200\n",
"\n",
"# Self-consistent configuration recovery loop\n",
"occupancies_bitwise = None # orbital i corresponds to column i in bitstring matrix\n",
Expand Down Expand Up @@ -99,18 +97,14 @@
" # Run eigenstate solvers in a loop. This loop should be parallelized for larger problems.\n",
" int_e = np.zeros(n_batches)\n",
" int_occs = np.zeros((n_batches, 2 * num_orbitals))\n",
" for j in range(n_batches):\n",
" ci_strs = bitstring_matrix_to_ci_strs(batches[j], open_shell=open_shell)\n",
" energy_sci, wf_mags, avg_occs = solve_dice(\n",
" ci_strs,\n",
" active_space_path,\n",
" os.path.abspath(\".\"),\n",
" spin_sq=spin_sq,\n",
" max_davidson=max_davidson_cycles,\n",
" clean_working_dir=True,\n",
" for j, batch in enumerate(batches):\n",
" energy_sci, wf_mags, avg_occs = solve_fermion(\n",
" batch,\n",
" hcore,\n",
" eri,\n",
" mpirun_options=[\"-n\", \"8\"],\n",
" )\n",
" int_e[j] = energy_sci\n",
" int_e[j] = energy_sci + nuclear_repulsion_energy\n",
" int_occs[j, :num_orbitals] = avg_occs[0]\n",
" int_occs[j, num_orbitals:] = avg_occs[1]\n",
"\n",
Expand All @@ -134,13 +128,13 @@
"output_type": "stream",
"text": [
"Exact energy: -109.10288938\n",
"Estimated energy: -109.06093312312994\n"
"Estimated energy: -109.03013363477585\n"
]
}
],
"source": [
"print(\"Exact energy: -109.10288938\")\n",
"print(f\"Estimated energy: {np.min(e_hist[-1]) + nuclear_repulsion_energy}\")"
"print(f\"Estimated energy: {np.min(e_hist[-1])}\")"
]
}
],
Expand All @@ -160,7 +154,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 12e4918

Please sign in to comment.