diff --git a/docs/qcqmc/high-level.ipynb b/docs/qcqmc/high-level.ipynb deleted file mode 100644 index 2cd21951..00000000 --- a/docs/qcqmc/high-level.ipynb +++ /dev/null @@ -1,286 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "679c5fd1", - "metadata": {}, - "source": [ - "# QCQMC\n", - "\n", - "This notebooks demonstrates the high-level code interface used to run the quantum part of https://arxiv.org/pdf/2106.16235.pdf.\n", - "\n", - "The code is organized into five steps, where the input of each step is specified by one or more `[Name]Params` dataclasses and the output of each step is an `attrs` dataclass named `[Name]Data` with a factory method `build_...`. Each of the steps are demonstrated below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "16e16876", - "metadata": {}, - "outputs": [], - "source": [ - "import attrs\n", - "\n", - "def print_fields(x):\n", - " \"\"\"Helper function to inspect returned objects' fields.\"\"\"\n", - " for k, v in attrs.asdict(x).items():\n", - " print(f'{k}: {type(v)}')" - ] - }, - { - "cell_type": "markdown", - "id": "00d220ee", - "metadata": {}, - "source": [ - "## Hamiltonian\n", - "\n", - "The first step is to pick a molecule and generate or load its relevant physical properties, namely the Hamiltonian. Here we specify a 2-electron Fermi-Hubbard Hamiltonian in the sto3g basis. Integral data is stored in the data/ file in this repository.\n", - "\n", - "The resulting data consists of the one- and two-body integrals and some energy quantities." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f003aaa5", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.hamiltonian import HamiltonianFileParams\n", - "hamiltonian_params = HamiltonianFileParams(\n", - " name='4q_pp',\n", - " integral_key='fh_sto3g',\n", - " n_orb=2,\n", - " n_elec=2,\n", - ")\n", - "hamiltonian_params" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3d0fc1f3", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.hamiltonian import HamiltonianData\n", - "hamiltonian_data = HamiltonianData.build_hamiltonian_from_file(hamiltonian_params)\n", - "print_fields(hamiltonian_data)" - ] - }, - { - "cell_type": "markdown", - "id": "74230882", - "metadata": {}, - "source": [ - "## Trial Wavefunction\n", - "\n", - "Next, we specify a trial wavefunction. Here: we request a perfect pairing trial (using the specialized Params class) and don't include any heuristic layers (to keep the example simple and the runtime short).\n", - "\n", - "The output data includes parameterized circuits and their parameters." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ef084640", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.trial_wf import PerfectPairingPlusTrialWavefunctionParams\n", - "trial_wf_params = PerfectPairingPlusTrialWavefunctionParams(\n", - " name='4q_pp',\n", - " hamiltonian_params=hamiltonian_params,\n", - " heuristic_layers=(),\n", - ")\n", - "trial_wf_params" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a942ca71", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.trial_wf import TrialWavefunctionData \n", - "trial_wf_data = TrialWavefunctionData.build_pp_plus_trial_from_dependencies(\n", - " trial_wf_params, \n", - " dependencies={\n", - " hamiltonian_params: hamiltonian_data\n", - " }\n", - ")\n", - "print('--'*20)\n", - "print_fields(trial_wf_data)" - ] - }, - { - "cell_type": "markdown", - "id": "f536a0d8", - "metadata": {}, - "source": [ - "## Blueprint\n", - "\n", - "Next, we configure the shadow tomography strategy for measuring the trial wavefunction. We specify how many cliffords and how to generate them, i.e. the qubit partition.\n", - "\n", - "The returned data is a compiled circuit with parameterized clifford suffixes and Cirq resolvers for efficient execution on a device." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f43b9a12", - "metadata": {}, - "outputs": [], - "source": [ - "qubits = trial_wf_params.qubits_linearly_connected" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b45591cc", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.blueprint import BlueprintParamsTrialWf\n", - "\n", - "blueprint_params = BlueprintParamsTrialWf(\n", - " name='4q_pp',\n", - " trial_wf_params=trial_wf_params,\n", - " n_cliffords=100,\n", - " qubit_partition=tuple((q,) for q in qubits),\n", - ")\n", - "blueprint_params" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d00ea516", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.blueprint import BlueprintData \n", - "blueprint_data = BlueprintData.build_blueprint_from_dependencies(\n", - " blueprint_params,\n", - " dependencies={\n", - " trial_wf_params: trial_wf_data\n", - " })\n", - "print_fields(blueprint_data)" - ] - }, - { - "cell_type": "markdown", - "id": "d34b627e", - "metadata": {}, - "source": [ - "## Experiment\n", - "\n", - "Now, we're ready to execute circuits and gather samples. The experiment step has two versions: simulated or on a real device. In either case, we configure how many samples to collect and any runtime-specific parameters.\n", - "\n", - "The returned data includes the experimental samples." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "86ef4223", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.experiment import SimulatedExperimentParams\n", - "expt_params = SimulatedExperimentParams(\n", - " name='4q_pp',\n", - " blueprint_params=blueprint_params,\n", - " n_samples_per_clifford=1_000,\n", - " noise_model_name='None',\n", - ")\n", - "expt_params" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a2e1a569", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "from recirq.qcqmc.experiment import ExperimentData \n", - "expt_data = ExperimentData.build_experiment_from_dependencies(\n", - " expt_params,\n", - " dependencies={\n", - " blueprint_params: blueprint_data\n", - "})\n", - "print_fields(expt_data)" - ] - }, - { - "cell_type": "markdown", - "id": "6d8278e5", - "metadata": {}, - "source": [ - "## Overlap Analysis\n", - "\n", - "Finally, we reconstruct the wavefunction from our experiment data.\n", - "\n", - "The returned data here are reconstructed wavefunctions suitable for exporting to iPie for classical QCQMC walker updates." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a938f2ef", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.analysis import OverlapAnalysisParams\n", - "analysis_params = OverlapAnalysisParams(\n", - " name='4q_pp',\n", - " experiment_params=expt_params,\n", - " k_to_calculate=(1, 2),\n", - ")\n", - "analysis_params" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "db222311", - "metadata": {}, - "outputs": [], - "source": [ - "from recirq.qcqmc.analysis import OverlapAnalysisData\n", - "analysis_data = OverlapAnalysisData.build_analysis_from_dependencies(analysis_params, dependencies={\n", - " expt_params: expt_data,\n", - " blueprint_params: blueprint_data,\n", - " trial_wf_params: trial_wf_data,\n", - "})\n", - "print_fields(analysis_data)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}