├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .readthedocs.yml ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.rst ├── check ├── doctest ├── format-incremental ├── misc ├── mypy ├── pylint ├── pytest ├── pytest-and-incremental-coverage └── pytest-changed-files ├── continuous-integration ├── check.sh └── simple_check.sh ├── dev_tools ├── __init__.py ├── all_checks.py ├── check.py ├── check_incremental_coverage.py ├── check_incremental_coverage_annotations.py ├── check_pylint.py ├── check_pytest_with_coverage.py ├── check_typecheck.py ├── conf │ ├── .coveragerc │ ├── .pylintrc │ ├── mypy.ini │ ├── pip-install-minimal-for-pytest-changed-files.sh │ ├── pip-list-dev-tools.txt │ └── pip-list-python2.7-test-tools.txt ├── env_tools.py ├── git_env_tools.py ├── github_repository.py ├── incremental_coverage.py ├── incremental_coverage_test.py ├── logo.svg ├── output_capture.py ├── packaging │ ├── produce-package.sh │ ├── publish-dev-package.sh │ └── verify-published-package.sh ├── prepared_env.py ├── run_checks.py ├── run_doctest.py ├── run_pytest_and_incremental_coverage.py ├── run_simple_checks.py ├── run_travis.py ├── shell_tools.py └── shell_tools_test.py ├── docs ├── Makefile ├── __init__.py ├── api.rst ├── conf.py ├── docs_coverage_test.py ├── index.rst └── requirements.txt ├── examples ├── examples_test.py ├── tutorial_1_basis_change.ipynb ├── tutorial_2_diagonal_coulomb_trotter.ipynb ├── tutorial_3_arbitrary_basis_trotter.ipynb └── tutorial_4_variational.ipynb ├── openfermioncirq ├── __init__.py ├── _compat.py ├── _compat_test.py ├── _version.py ├── contrib │ ├── __init__.py │ ├── contrib-requirements.txt │ └── contrib_test.py ├── experiments │ ├── __init__.py │ └── hfvqe │ │ ├── H3_plus_odd_qubit_example.ipynb │ │ ├── README.md │ │ ├── __init__.py │ │ ├── analysis.py │ │ ├── analysis_test.py │ │ ├── circuits.py │ │ ├── circuits_test.py │ │ ├── gradient_hf.py │ │ ├── gradient_hf_test.py │ │ ├── mfopt.py │ │ ├── molecular_data │ │ ├── __init__.py │ │ ├── hydrogen_chains │ │ │ ├── h_10_sto-3g │ │ │ │ ├── bond_distance_0.5 │ │ │ │ │ ├── H10_sto-3g_singlet_linear_r-0.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_0.9 │ │ │ │ │ ├── H10_sto-3g_singlet_linear_r-0.9.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.3 │ │ │ │ │ ├── H10_sto-3g_singlet_linear_r-1.3.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.7 │ │ │ │ │ ├── H10_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_2.1 │ │ │ │ │ ├── H10_sto-3g_singlet_linear_r-2.1.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ └── bond_distance_2.5 │ │ │ │ │ ├── H10_sto-3g_singlet_linear_r-2.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ ├── h_12_sto-3g │ │ │ │ ├── bond_distance_0.5 │ │ │ │ │ ├── H12_sto-3g_singlet_linear_r-0.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_0.9 │ │ │ │ │ ├── H12_sto-3g_singlet_linear_r-0.9.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.3 │ │ │ │ │ ├── H12_sto-3g_singlet_linear_r-1.3.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.7 │ │ │ │ │ ├── H12_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_2.1 │ │ │ │ │ ├── H12_sto-3g_singlet_linear_r-2.1.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ └── bond_distance_2.5 │ │ │ │ │ ├── H12_sto-3g_singlet_linear_r-2.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ ├── h_3_p_sto-3g │ │ │ │ └── bond_distance_2.5 │ │ │ │ │ ├── H3_plus_sto-3g_singlet_linear_r-2.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ ├── h_6_sto-3g │ │ │ │ ├── bond_distance_0.5 │ │ │ │ │ ├── H6_sto-3g_singlet_linear_r-0.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_0.9 │ │ │ │ │ ├── H6_sto-3g_singlet_linear_r-0.9.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.3 │ │ │ │ │ ├── H6_sto-3g_singlet_linear_r-1.3.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.7 │ │ │ │ │ ├── H6_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_2.1 │ │ │ │ │ ├── H6_sto-3g_singlet_linear_r-2.1.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ └── bond_distance_2.5 │ │ │ │ │ ├── H6_sto-3g_singlet_linear_r-2.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ ├── h_8_sto-3g │ │ │ │ ├── bond_distance_0.5 │ │ │ │ │ ├── H8_sto-3g_singlet_linear_r-0.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_0.9 │ │ │ │ │ ├── H8_sto-3g_singlet_linear_r-0.9.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.3 │ │ │ │ │ ├── H8_sto-3g_singlet_linear_r-1.3.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_1.7 │ │ │ │ │ ├── H8_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ ├── bond_distance_2.1 │ │ │ │ │ ├── H8_sto-3g_singlet_linear_r-2.1.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ │ └── bond_distance_2.5 │ │ │ │ │ ├── H8_sto-3g_singlet_linear_r-2.5.hdf5 │ │ │ │ │ ├── h_core.npy │ │ │ │ │ ├── overlap.npy │ │ │ │ │ ├── parameters.npy │ │ │ │ │ ├── tei.npy │ │ │ │ │ └── true_opdm.npy │ │ │ └── make_rhf_simulations.py │ │ ├── molecular_data_construction.py │ │ └── molecular_data_constructor_test.py │ │ ├── molecular_example.py │ │ ├── molecular_example_odd_qubits.py │ │ ├── objective.py │ │ ├── objective_test.py │ │ ├── opdm_functional_test.py │ │ ├── opdm_functionals.py │ │ ├── quickstart.ipynb │ │ ├── third_party │ │ ├── __init__.py │ │ ├── higham.py │ │ └── higham_test.py │ │ ├── util.py │ │ └── util_test.py ├── gates │ ├── __init__.py │ ├── common_gates.py │ ├── common_gates_test.py │ ├── fermionic_simulation.py │ ├── fermionic_simulation_test.py │ ├── four_qubit_gates.py │ ├── four_qubit_gates_test.py │ ├── three_qubit_gates.py │ └── three_qubit_gates_test.py ├── optimization │ ├── __init__.py │ ├── algorithm.py │ ├── algorithm_test.py │ ├── black_box.py │ ├── black_box_test.py │ ├── result.py │ ├── result_test.py │ ├── scipy.py │ └── scipy_test.py ├── primitives │ ├── __init__.py │ ├── bogoliubov_transform.py │ ├── bogoliubov_transform_test.py │ ├── ffft.py │ ├── ffft_test.py │ ├── optimal_givens_decomposition.py │ ├── optimal_givens_decomposition_test.py │ ├── state_preparation.py │ ├── state_preparation_test.py │ ├── swap_network.py │ └── swap_network_test.py ├── testing │ ├── __init__.py │ ├── example_classes.py │ ├── random.py │ ├── random_test.py │ └── wrapped.py ├── trotter │ ├── __init__.py │ ├── algorithms │ │ ├── __init__.py │ │ ├── linear_swap_network.py │ │ ├── low_rank.py │ │ └── split_operator.py │ ├── simulate_trotter.py │ ├── simulate_trotter_test.py │ ├── trotter_algorithm.py │ └── trotter_algorithm_test.py └── variational │ ├── __init__.py │ ├── ansatz.py │ ├── ansatz_test.py │ ├── ansatzes │ ├── __init__.py │ ├── default_initial_params_test.py │ ├── low_rank.py │ ├── low_rank_test.py │ ├── split_operator_trotter.py │ ├── split_operator_trotter_test.py │ ├── swap_network_trotter.py │ ├── swap_network_trotter_hubbard.py │ ├── swap_network_trotter_hubbard_test.py │ └── swap_network_trotter_test.py │ ├── hamiltonian_objective.py │ ├── hamiltonian_objective_test.py │ ├── letter_with_subscripts.py │ ├── letter_with_subscripts_test.py │ ├── objective.py │ ├── objective_test.py │ ├── study.py │ ├── study_test.py │ ├── variational_black_box.py │ └── variational_black_box_test.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore compiled python files 2 | __pycache__ 3 | *.pyc 4 | 5 | # ignore python egg files 6 | *.egg-info/ 7 | *.egg 8 | 9 | # ignore coverage files 10 | *.py,cover 11 | *.coverage 12 | *.coverage.* 13 | 14 | # Jupyter notebook checkpoints 15 | *.ipynb_checkpoints/ 16 | 17 | # ignore idea SDK 18 | .idea/* 19 | 20 | # ignore cache 21 | .cache/* 22 | *.pytest_cache/ 23 | *.mypy_cache/ 24 | 25 | # ignore Vim swap files 26 | *.swp 27 | 28 | # ignore Sphinx build 29 | docs/generated 30 | docs/_build 31 | 32 | # psi4 dat files 33 | *.dat 34 | 35 | # macfiles 36 | *.DS_Store 37 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | requirements_file: docs/requirements.txt 2 | build: 3 | image: latest 4 | python: 5 | version: 3.6 6 | pip_install: true 7 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements.txt 2 | include LICENSE 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Notice 2 | ====== 3 | 4 | OpenFermion-Cirq is deprecated and no longer maintained. Its functionality has been merged 5 | into OpenFermion_. Please use OpenFermion instead. 6 | 7 | .. _OpenFermion: https://github.com/quantumlib/OpenFermion 8 | 9 | Copyright 2018 The OpenFermion Developers. 10 | This is not an official Google product. 11 | -------------------------------------------------------------------------------- /check/doctest: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Runs python doctest on all python source files in the cirq directory. 5 | # 6 | # See also: 7 | # https://docs.python.org/3/library/doctest.html 8 | # 9 | # Usage: 10 | # check/doctest [-q] 11 | # 12 | # The -q argument suppresses all output except the final result line and any 13 | # error messages. 14 | ################################################################################ 15 | 16 | # Get the working directory to the repo root. 17 | cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 18 | cd "$(git rev-parse --show-toplevel)" 19 | 20 | PYTHONPATH="$(pwd)" python dev_tools/run_doctest.py "$@" 21 | -------------------------------------------------------------------------------- /check/misc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Runs misc custom checks on repistory. 5 | # 6 | # Usage: 7 | # check/misc 8 | ################################################################################ 9 | 10 | # Get the working directory to the repo root. 11 | cd "$( dirname "${BASH_SOURCE[0]}" )" 12 | cd "$(git rev-parse --show-toplevel)" 13 | 14 | # Check for non-contrib references to contrib. 15 | results=$(grep -Rl "\bopenfermioncirq\.contrib\b" openfermioncirq | grep -v "openfermioncirq/contrib" | grep -v "__") 16 | RESULT=$? 17 | if [ $RESULT -eq 0 ]; then 18 | echo -e "\033[31m'openfermioncirq.contrib' mentioned in non-contrib files:\033[0m" 19 | echo "${results}" 20 | echo 21 | echo -e "\033[31mSource files outside openfermioncirq.contrib must not reference openfermioncirq.contrib, as this can cause errors for users who 'pip install openfermioncirq' instead of 'pip install openfermioncirq[contrib]'.\033[0m" 22 | exit 1 23 | fi 24 | 25 | echo -e "\033[32mNo issues\033[0m." 26 | -------------------------------------------------------------------------------- /check/mypy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Runs mypy on the repository using a preconfigured mypy.ini file. 5 | # 6 | # Usage: 7 | # check/mypy [--flags] 8 | ################################################################################ 9 | 10 | # Get the working directory to the repo root. 11 | cd "$( dirname "${BASH_SOURCE[0]}" )" 12 | cd $(git rev-parse --show-toplevel) 13 | 14 | echo -e -n "\e[31m" 15 | mypy --config-file=dev_tools/conf/mypy.ini $@ . 16 | result=$? 17 | echo -e -n "\e[0m" 18 | 19 | exit ${result} 20 | -------------------------------------------------------------------------------- /check/pylint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Runs pylint on the repository using a preconfigured .pylintrc file. 5 | # 6 | # Usage: 7 | # check/pylint [--flags] 8 | ################################################################################ 9 | 10 | # Get the working directory to the repo root. 11 | cd "$( dirname "${BASH_SOURCE[0]}" )" 12 | cd $(git rev-parse --show-toplevel) 13 | 14 | pylint --rcfile=dev_tools/conf/.pylintrc $@ openfermioncirq dev_tools examples 15 | -------------------------------------------------------------------------------- /check/pytest: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Runs pytest on the repository. 5 | # 6 | # Usage: 7 | # check/pytest [--actually-quiet] [--flags for pytest] [file-paths-relative-to-repo-root] 8 | # 9 | # The --actually-quiet argument filters out any progress output from pytest. 10 | # 11 | # You may specify pytest flags and specific files to test. The file paths 12 | # must be relative to the repository root. If no files are specified, everything 13 | # is tested. 14 | ################################################################################ 15 | 16 | # Get the working directory to the repo root. 17 | cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 18 | cd "$(git rev-parse --show-toplevel)" 19 | 20 | PYTEST_ARGS=() 21 | ACTUALLY_QUIET="" 22 | for arg in $@; do 23 | if [[ "${arg}" == "--actually-quiet" ]]; then 24 | ACTUALLY_QUIET=1 25 | else 26 | PYTEST_ARGS+=("${arg}") 27 | fi 28 | done 29 | 30 | if [ -z "${ACTUALLY_QUIET}" ]; then 31 | pytest "${PYTEST_ARGS[@]}" 32 | else 33 | # Filter out lines like "...F....x... [ 42%]", with coloring. 34 | pytest -q --color=yes "${PYTEST_ARGS[@]}" | 35 | perl -nle'print if not m{^(.\[0m)?[\.FEsx]+(.\[36m)?\s+\[\s*\d+%\](.\[0m)?$}' 36 | exit "${PIPESTATUS[0]}" 37 | fi 38 | -------------------------------------------------------------------------------- /check/pytest-and-incremental-coverage: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Finds changed uncovered lines. 5 | # 6 | # Usage: 7 | # check/pytest-and-incremental-coverage [BASE_REVISION] 8 | # 9 | # You can specify a base git revision to compare against (i.e. to use when 10 | # determining whether or not a line is considered to have "changed"). To make 11 | # the tool more consistent, it actually diffs against the most recent common 12 | # ancestor of the specified id and HEAD. So if you choose 'origin/master' you're 13 | # actually diffing against the output of 'git merge-base origin/master HEAD'. 14 | # 15 | # If you don't specify a base revision, the following defaults will be tried, 16 | # in order, until one exists: 17 | # 18 | # 1. upstream/master 19 | # 2. origin/master 20 | # 3. master 21 | # 22 | # If none exists, the script fails. 23 | ################################################################################ 24 | 25 | # Get the working directory to the repo root. 26 | cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1 27 | cd "$(git rev-parse --show-toplevel)" || exit 1 28 | 29 | # Figure out which revision to compare against. 30 | if [ ! -z "$1" ] && [[ $1 != -* ]]; then 31 | if [ "$(git cat-file -t $1 2> /dev/null)" != "commit" ]; then 32 | echo -e "\033[31mNo revision '$1'.\033[0m" >&2 33 | exit 1 34 | fi 35 | rev=$1 36 | elif [ "$(git cat-file -t upstream/master 2> /dev/null)" == "commit" ]; then 37 | rev=upstream/master 38 | elif [ "$(git cat-file -t origin/master 2> /dev/null)" == "commit" ]; then 39 | rev=origin/master 40 | elif [ "$(git cat-file -t master 2> /dev/null)" == "commit" ]; then 41 | rev=master 42 | else 43 | echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/master' or 'HEAD~1').\033[0m" >&2 44 | exit 1 45 | fi 46 | base="$(git merge-base ${rev} HEAD)" 47 | if [ "$(git rev-parse ${rev})" == "${base}" ]; then 48 | echo -e "Comparing against revision '${rev}'." >&2 49 | else 50 | echo -e "Comparing against revision '${rev}' (merge base ${base})." >&2 51 | rev="${base}" 52 | fi 53 | 54 | # Run tests while producing coverage files. 55 | check/pytest . \ 56 | --actually-quiet \ 57 | --cov \ 58 | --cov-report=annotate \ 59 | --cov-config=dev_tools/conf/.coveragerc 60 | pytest_result=$? 61 | 62 | # Analyze coverage files. 63 | PYTHONPATH="$(pwd)" python dev_tools/check_incremental_coverage_annotations.py "${rev}" 64 | cover_result=$? 65 | 66 | # Clean up generated coverage files. 67 | find . | grep "\.py,cover$" | xargs rm -f 68 | 69 | # Report result. 70 | if [ "${pytest_result}" -ne "0" ] || [ "${cover_result}" -ne "0" ]; then 71 | exit 1 72 | fi 73 | exit 0 74 | -------------------------------------------------------------------------------- /check/pytest-changed-files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # Runs pytest on files that have been modified. 5 | # 6 | # Usage: 7 | # check/pytest-changed-files [BASE_REVISION] [--pytest-flags] 8 | # 9 | # This tool is not clever; it does not understand dependencies between all 10 | # files. If "x.py" or "x_test.py" have been modified, it will include 11 | # "x_test.py" in the arguments given to pytest. That's all it does. 12 | # 13 | # You can specify a base git revision to compare against (i.e. to use when 14 | # determining whether or not a file is considered to have "changed"). For 15 | # example, you can compare against 'origin/master' or 'HEAD~1'. 16 | # 17 | # If you don't specify a base revision, the following defaults will be tried, in 18 | # order, until one exists: 19 | # 20 | # 1. upstream/master 21 | # 2. origin/master 22 | # 3. master 23 | # 24 | # If none exists, the script fails. 25 | # 26 | # You can pass flags such as "-v" into pytest by placing them after the 27 | # comparison id. 28 | ################################################################################ 29 | 30 | # Get the working directory to the repo root. 31 | cd "$( dirname "${BASH_SOURCE[0]}" )" 32 | cd $(git rev-parse --show-toplevel) 33 | 34 | # Figure out which branch to compare against. 35 | rest=$@ 36 | if [ ! -z "$1" ] && [[ $1 != -* ]]; then 37 | if [ "$(git cat-file -t $1 2> /dev/null)" != "commit" ]; then 38 | echo -e "\e[31mNo revision '$1'.\e[0m" >&2 39 | exit 1 40 | fi 41 | rev=$1 42 | rest=${@:2} 43 | elif [ "$(git cat-file -t upstream/master 2> /dev/null)" == "commit" ]; then 44 | rev=upstream/master 45 | elif [ "$(git cat-file -t origin/master 2> /dev/null)" == "commit" ]; then 46 | rev=origin/master 47 | elif [ "$(git cat-file -t master 2> /dev/null)" == "commit" ]; then 48 | rev=master 49 | else 50 | echo -e "\e[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/master' or 'HEAD~1').\e[0m" >&2 51 | exit 1 52 | fi 53 | echo "Comparing against revision '${rev}'." >&2 54 | 55 | # Get the _test version of changed python files. 56 | changed=$(git diff --name-only ${rev} -- \ 57 | | grep "\.py$" \ 58 | | sed -e "s/\.py$/_test.py/" \ 59 | | sed -e "s/_test_test\.py$/_test.py/" \ 60 | | perl -ne 'chomp(); if (-e $_) {print "$_\n"}' \ 61 | | uniq \ 62 | ) 63 | num_changed=$(echo -e "${changed}" | wc -w) 64 | 65 | # Run it. 66 | echo "Found ${num_changed} differing files with associated tests." >&2 67 | if [ -z "${changed}" ]; then 68 | exit 0 69 | fi 70 | pytest ${rest} ${changed} 71 | -------------------------------------------------------------------------------- /continuous-integration/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Cirq Developers 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | # This script runs checks (e.g. pylint, pytest) against a pull request on 19 | # github or against local code. It is called as follows: 20 | # 21 | # bash continuous-integration/check.sh \ 22 | # [pull-request-number] \ 23 | # [access-token] \ 24 | # [--only=pylint|typecheck|pytest|incremental-coverage] \ 25 | # [--verbose] 26 | # 27 | # If no pull request number is given, the script will check files in its 28 | # own directory's github repo. If a pull request number is given, the script 29 | # will fetch the corresponding PR from github and run checks against it. 30 | # 31 | # If an access token is given, to go along with the pull request number, the 32 | # script will attempt to use this token to update the status checks shown on 33 | # github. 34 | # 35 | # In order to only run a subset of the checks, one can pass --only=X arguments. 36 | # It is allowed to specify multiple --only arguments, with the understanding 37 | # that this means to run each of the specified checks but not others. 38 | # 39 | # For debugging purposes, the --verbose argument can be included. This will 40 | # cause significantly more output to be produced (e.g. describing all the 41 | # packages that pip installed). 42 | 43 | 44 | set -e 45 | own_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 46 | 47 | cd ${own_directory} 48 | cirq_dir=$(git rev-parse --show-toplevel) 49 | cd ${cirq_dir} 50 | export PYTHONPATH=${cirq_dir} 51 | 52 | python3 ${cirq_dir}/dev_tools/run_checks.py $@ 53 | -------------------------------------------------------------------------------- /continuous-integration/simple_check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Cirq Developers 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | # This script is a lightweight version of check.sh. This script is not as 19 | # reliable as check.sh because it avoids using tools that require system setup. 20 | # In particular, this script DOES NOT: 21 | # 22 | # 1. Create fresh test environments with updated dependencies. 23 | # 2. Run tests against multiple versions of python. 24 | # 25 | # What this script DOES do is run pylint, mypy, pytest, and incremental code 26 | # coverage against your local python 3 dev copy of OpenFermion-Cirq. 27 | 28 | 29 | # Get the working directory to the repo root. 30 | own_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 31 | cd ${own_directory} 32 | repo_dir=$(git rev-parse --show-toplevel) 33 | cd ${repo_dir} 34 | 35 | # Run the checks. 36 | export PYTHONPATH=${repo_dir}:${PYTHONPATH} 37 | python3 ${repo_dir}/dev_tools/run_simple_checks.py $@ 38 | result=$? 39 | 40 | # Delete coverage files created by pytest during the checks. 41 | find . | grep "\.py,cover$" | xargs rm 42 | 43 | exit ${result} 44 | -------------------------------------------------------------------------------- /dev_tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Cirq Developers 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Tooling useful when developing (e.g. scripts to run tests). 16 | 17 | These tools use shell commands, and so are not portable between operating 18 | systems. Currently they assume that the system is based on Debian Linux. 19 | """ 20 | -------------------------------------------------------------------------------- /dev_tools/all_checks.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from dev_tools import ( 16 | check_incremental_coverage, 17 | check_pylint, 18 | check_pytest_with_coverage, 19 | check_typecheck, 20 | ) 21 | 22 | 23 | pylint = check_pylint.LintCheck() 24 | typecheck = check_typecheck.TypeCheck() 25 | pytest = check_pytest_with_coverage.TestAndPrepareCoverageCheck() 26 | incremental_coverage = check_incremental_coverage.IncrementalCoverageCheck( 27 | pytest) 28 | 29 | ALL_CHECKS = [ 30 | pylint, 31 | typecheck, 32 | pytest, 33 | incremental_coverage, 34 | ] 35 | -------------------------------------------------------------------------------- /dev_tools/check_incremental_coverage.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from dev_tools import env_tools, incremental_coverage, check 16 | 17 | 18 | class IncrementalCoverageCheck(check.Check): 19 | """Checks if touched lines are covered by tests. 20 | 21 | This check must run after the pytest check, because that check is what 22 | computes the coverage files used by this check. 23 | """ 24 | def command_line_switch(self): 25 | return 'incremental-coverage' 26 | 27 | def context(self): 28 | return 'incremental coverage' 29 | 30 | def perform_check(self, env: env_tools.PreparedEnv, verbose: bool): 31 | uncovered_count = incremental_coverage.check_for_uncovered_lines(env) 32 | if not uncovered_count: 33 | return True, 'All covered!' 34 | return False, '{} touched uncovered lines'.format(uncovered_count) 35 | -------------------------------------------------------------------------------- /dev_tools/check_incremental_coverage_annotations.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import os 18 | import sys 19 | 20 | from dev_tools import prepared_env, shell_tools 21 | 22 | from dev_tools.incremental_coverage import check_for_uncovered_lines 23 | 24 | 25 | def main(): 26 | if len(sys.argv) < 2: 27 | print( 28 | shell_tools.highlight( 29 | 'Must specify a comparison branch ' 30 | '(e.g. "origin/master" or "HEAD~1").', shell_tools.RED)) 31 | sys.exit(1) 32 | comparison_branch = sys.argv[1] 33 | 34 | env = prepared_env.PreparedEnv( 35 | github_repo=None, 36 | actual_commit_id=None, # local uncommitted files 37 | compare_commit_id=comparison_branch, 38 | destination_directory=os.getcwd(), 39 | virtual_env_path=None) 40 | 41 | uncovered_count = check_for_uncovered_lines(env) 42 | if uncovered_count: 43 | sys.exit(1) 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /dev_tools/check_pylint.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | from typing import cast 15 | 16 | import re 17 | 18 | import os.path 19 | import sys 20 | 21 | from dev_tools import env_tools, shell_tools, check 22 | 23 | 24 | class LintCheck(check.Check): 25 | """Checks if the code is up to snuff.""" 26 | 27 | def command_line_switch(self): 28 | return 'pylint' 29 | 30 | def context(self): 31 | return 'pylint' 32 | 33 | def perform_check(self, env: env_tools.PreparedEnv, verbose: bool): 34 | base_path = cast(str, env.destination_directory) 35 | rc_path = os.path.join(base_path, 36 | 'dev_tools', 37 | 'conf', 38 | '.pylintrc') 39 | files = list( 40 | env_tools.get_unhidden_ungenerated_python_files(base_path)) 41 | 42 | result = shell_tools.run_cmd( 43 | env.bin('pylint'), 44 | '--rcfile={}'.format(rc_path), 45 | *files, 46 | out=shell_tools.TeeCapture(sys.stdout), 47 | raise_on_fail=False, 48 | log_run_to_stderr=verbose, 49 | abbreviate_non_option_arguments=True) 50 | 51 | output = cast(str, result[0]) 52 | passed = result[2] == 0 53 | if passed: 54 | return True, 'No lint here!' 55 | file_line_count = len(re.findall(r'\*' * 10, output)) 56 | total_line_count = len([e for e in output.split('\n') if e.strip()]) 57 | issue_count = total_line_count - file_line_count 58 | 59 | return False, '{} issues'.format(issue_count) 60 | -------------------------------------------------------------------------------- /dev_tools/check_pytest_with_coverage.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | from typing import cast 15 | 16 | import os 17 | import re 18 | import sys 19 | 20 | from dev_tools import env_tools, shell_tools, check 21 | 22 | 23 | class TestAndPrepareCoverageCheck(check.Check): 24 | """Checks if the code passes unit tests. 25 | 26 | As a side effect, produces coverage files used by the coverage checks. 27 | """ 28 | 29 | def command_line_switch(self): 30 | return 'pytest' 31 | 32 | def context(self): 33 | return 'pytest' 34 | 35 | def perform_check(self, env: env_tools.PreparedEnv, verbose: bool): 36 | do_coverage = True 37 | base_path = cast(str, env.destination_directory) 38 | rc_path = os.path.join(base_path, 39 | 'dev_tools', 40 | 'conf', 41 | '.coveragerc') 42 | target_path = base_path 43 | result = shell_tools.run_cmd( 44 | env.bin('pytest'), 45 | target_path, 46 | None if verbose else '--quiet', 47 | *([ 48 | '--cov', 49 | '--cov-report=annotate', 50 | '--cov-config={}'.format(rc_path) 51 | ] if do_coverage else []), 52 | out=shell_tools.TeeCapture(sys.stdout), 53 | raise_on_fail=False, 54 | log_run_to_stderr=verbose) 55 | 56 | output = cast(str, result[0]) 57 | passed = result[2] == 0 58 | if passed: 59 | return True, 'Tests passed!' 60 | 61 | last_line = [e for e in output.split('\n') if e.strip()][-1] 62 | fail_match = re.match('.+=== (\d+) failed', last_line) 63 | if fail_match is None: 64 | return False, 'Tests failed.' 65 | return False, '{} tests failed.'.format(fail_match.group(1)) 66 | -------------------------------------------------------------------------------- /dev_tools/check_typecheck.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | from typing import cast 15 | 16 | import os.path 17 | import sys 18 | 19 | from dev_tools import env_tools, shell_tools, check 20 | 21 | 22 | class TypeCheck(check.Check): 23 | """Checks that the types specified in the code make sense.""" 24 | 25 | def command_line_switch(self): 26 | return 'typecheck' 27 | 28 | def context(self): 29 | return 'typecheck' 30 | 31 | def perform_check(self, env: env_tools.PreparedEnv, verbose: bool): 32 | base_path = cast(str, env.destination_directory) 33 | config_path = os.path.join(base_path, 34 | 'dev_tools', 35 | 'conf', 36 | 'mypy.ini') 37 | files = list(env_tools.get_unhidden_ungenerated_python_files( 38 | base_path)) 39 | 40 | result = shell_tools.run_cmd( 41 | env.bin('mypy'), 42 | '--config-file={}'.format(config_path), 43 | *files, 44 | out=shell_tools.TeeCapture(sys.stdout), 45 | raise_on_fail=False, 46 | log_run_to_stderr=verbose, 47 | abbreviate_non_option_arguments=True) 48 | 49 | output = cast(str, result[0]) 50 | passed = result[2] == 0 51 | if passed: 52 | return True, 'Types look good!' 53 | issue_count = len([e for e in output.split('\n') if e.strip()]) 54 | 55 | return False, '{} issues'.format(issue_count) 56 | -------------------------------------------------------------------------------- /dev_tools/conf/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | # Omit files outside the current working directory. 3 | # Note: this means coverage must be run from the repo root. 4 | # Failure to do so will result in false positives. 5 | include = ./* 6 | 7 | [report] 8 | exclude_lines = 9 | if TYPE_CHECKING: 10 | 11 | testpragma: no cover 12 | -------------------------------------------------------------------------------- /dev_tools/conf/.pylintrc: -------------------------------------------------------------------------------- 1 | [config] 2 | max-line-length=80 3 | disable=all 4 | ignore-patterns=.*_pb2\.py 5 | output-format=colorized 6 | score=no 7 | reports=no 8 | enable= 9 | assert-on-tuple, 10 | bad-indentation, 11 | bad-option-value, 12 | bad-reversed-sequence, 13 | bad-super-call, 14 | consider-merging-isinstance, 15 | continue-in-finally, 16 | dangerous-default-value, 17 | duplicate-argument-name, 18 | expression-not-assigned, 19 | function-redefined, 20 | inconsistent-mro, 21 | init-is-generator, 22 | line-too-long, 23 | lost-exception, 24 | missing-kwoa, 25 | mixed-indentation, 26 | mixed-line-endings, 27 | not-callable, 28 | no-value-for-parameter, 29 | nonexistent-operator, 30 | not-in-loop, 31 | pointless-statement, 32 | redefined-builtin, 33 | relative-import, 34 | return-arg-in-generator, 35 | return-in-init, 36 | return-outside-function, 37 | simplifiable-if-statement, 38 | syntax-error, 39 | too-many-function-args, 40 | trailing-whitespace, 41 | undefined-variable, 42 | unexpected-keyword-arg, 43 | unhashable-dict-key, 44 | unnecessary-pass, 45 | unreachable, 46 | unrecognized-inline-option, 47 | unused-import, 48 | unnecessary-semicolon, 49 | unused-variable, 50 | unused-wildcard-import, 51 | wildcard-import, 52 | wrong-import-order, 53 | wrong-import-position, 54 | yield-outside-function 55 | 56 | # Ignore long lines containing urls or pylint directives. 57 | ignore-long-lines=^(.*#\w*pylint: disable.*|\s*(# )??)$ 58 | 59 | known-third-party=cirq, numpy, openfermion, pytest, scipy, sympy 60 | -------------------------------------------------------------------------------- /dev_tools/conf/mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | 3 | [mypy-__main__] 4 | follow_imports = silent 5 | ignore_missing_imports = true 6 | 7 | # 3rd-party libs for which we don't have stubs 8 | [mypy-absl,apiclient.*,deprecation,google.protobuf.*,matplotlib.*,nbformat,numpy,oauth2client,pytest,scipy,scipy.*,pandas,sortedcontainers,setuptools,cirq.*,openfermion.*,sympy.*] 9 | follow_imports = silent 10 | ignore_missing_imports = True 11 | 12 | #Adding "sympy.* or mypy-sympy to the above list (3rd-party libs for which we don't have stubs) doesn't ignore "cannot find module 'sympy' error 13 | [mypy-sympy] 14 | ignore_missing_imports = True 15 | 16 | [mypy-openfermioncirq.experiments.hfvqe.*] 17 | ignore_errors = True 18 | 19 | -------------------------------------------------------------------------------- /dev_tools/conf/pip-install-minimal-for-pytest-changed-files.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Cirq Developers 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | 19 | # Get the working directory to the repo root. 20 | cd "$( dirname "${BASH_SOURCE[0]}" )" 21 | cd "$(git rev-parse --show-toplevel)" 22 | 23 | # Install usual requirements. 24 | pip install -r requirements.txt 25 | 26 | # Install pytest related dev requirements. 27 | cat dev_tools/conf/pip-list-dev-tools.txt | grep pytest | xargs pip install 28 | -------------------------------------------------------------------------------- /dev_tools/conf/pip-list-dev-tools.txt: -------------------------------------------------------------------------------- 1 | # For testing and analyzing code. 2 | mypy~=0.701.0 3 | pylint~=2.3.0 4 | pytest~=5.4.1 5 | pytest-cov==2.5.* 6 | yapf~=0.27.0 7 | 8 | # For uploading packages to pypi. 9 | twine 10 | 11 | # For verifying behavior of qasm output. 12 | qiskit==0.6.* 13 | 14 | # For testing example notebooks 15 | nbformat 16 | -------------------------------------------------------------------------------- /dev_tools/conf/pip-list-python2.7-test-tools.txt: -------------------------------------------------------------------------------- 1 | 3to2~=1.1 2 | mock~=2.0 3 | pytest~=3.2 4 | -------------------------------------------------------------------------------- /dev_tools/github_repository.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Cirq Developers 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Optional 16 | 17 | 18 | class GithubRepository: 19 | """Details how to access a repository on github.""" 20 | def __init__(self, 21 | organization: str, 22 | name: str, 23 | access_token: Optional[str]) -> None: 24 | """ 25 | Args: 26 | organization: The github organization the repository is under. 27 | name: The name of the github repository. 28 | access_token: If present, this token is used to authorize changes 29 | to the repository when calling the github API (e.g. set build 30 | status indicators). Avoid using access tokens with more 31 | permissions than necessary. 32 | """ 33 | self.organization = organization 34 | self.name = name 35 | self.access_token = access_token 36 | 37 | def as_remote(self) -> str: 38 | """Returns a string identifying the location of this repository.""" 39 | return 'git@github.com:{}/{}.git'.format(self.organization, 40 | self.name) 41 | -------------------------------------------------------------------------------- /dev_tools/incremental_coverage_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Cirq Developers 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from dev_tools import incremental_coverage 16 | 17 | 18 | def test_determine_ignored_lines(): 19 | f = incremental_coverage.determine_ignored_lines 20 | 21 | assert f("a = 0 # coverage: ignore") == {1} 22 | 23 | assert f(""" 24 | a = 0 # coverage: ignore 25 | b = 0 26 | """) == {2} 27 | 28 | assert f(""" 29 | a = 0 30 | b = 0 # coverage: ignore 31 | """) == {3} 32 | 33 | assert f(""" 34 | a = 0 # coverage: ignore 35 | b = 0 # coverage: ignore 36 | """) == {2, 3} 37 | 38 | assert f(""" 39 | if True: 40 | a = 0 # coverage: ignore 41 | 42 | b = 0 43 | """) == {3} 44 | 45 | assert f(""" 46 | if True: 47 | # coverage: ignore 48 | a = 0 49 | 50 | b = 0 51 | """) == {3, 4, 5, 6, 7} 52 | 53 | assert f(""" 54 | if True: 55 | # coverage: ignore 56 | a = 0 57 | 58 | b = 0 59 | stop = 1 60 | """) == {3, 4, 5, 6} 61 | 62 | assert f(""" 63 | if True: 64 | # coverage: ignore 65 | a = 0 66 | 67 | b = 0 68 | else: 69 | c = 0 70 | """) == {3, 4, 5, 6} 71 | 72 | assert f(""" 73 | if True: 74 | while False: 75 | # coverage: ignore 76 | a = 0 77 | 78 | b = 0 79 | else: 80 | c = 0 # coverage: ignore 81 | """) == {4, 5, 6, 9} 82 | 83 | assert f(""" 84 | a = 2#coverage:ignore 85 | a = 3 #coverage:ignore 86 | a = 4# coverage:ignore 87 | a = 5#coverage :ignore 88 | a = 6#coverage: ignore 89 | a = 7#coverage: ignore\t 90 | a = 8#coverage:\tignore\t 91 | 92 | b = 1 # no cover 93 | b = 2 # coverage: definitely 94 | b = 3 # lint: ignore 95 | """) == {2, 3, 4, 5, 6, 7, 8} 96 | -------------------------------------------------------------------------------- /dev_tools/output_capture.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Cirq Developers 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import sys 16 | import io 17 | 18 | 19 | class OutputCapture: 20 | """A context manager that captures stdout and stderr.""" 21 | 22 | def __init__(self): 23 | self.buffer = io.StringIO() 24 | self._cache = None 25 | 26 | def __enter__(self): 27 | self._cache = sys.stdout, sys.stderr 28 | sys.stdout, sys.stderr = self.buffer, self.buffer 29 | return None 30 | 31 | def __exit__(self, exc_type, exc_value, exc_traceback): 32 | sys.stdout, sys.stderr = self._cache 33 | 34 | def content(self) -> str: 35 | return self.buffer.getvalue() 36 | -------------------------------------------------------------------------------- /dev_tools/packaging/produce-package.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2018 The Cirq Developers 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | ################################################################################ 18 | # Produces wheels that can be uploaded to the pypi package repository. 19 | # 20 | # First argument must be the output directory. Second argument is an optional 21 | # version specifier. If not set, the version from `_version.py` is used. If set, 22 | # it overwrites `_version.py`. 23 | # 24 | # Usage: 25 | # dev_tools/packaging/produce-package.sh output_dir [version] 26 | ################################################################################ 27 | 28 | PROJECT_NAME=openfermioncirq 29 | 30 | set -e 31 | 32 | if [ -z "${1}" ]; then 33 | echo -e "\e[31mNo output directory given.\e[0m" 34 | exit 1 35 | fi 36 | out_dir=$(realpath "${1}") 37 | 38 | SPECIFIED_VERSION="${2}" 39 | 40 | # Get the working directory to the repo root. 41 | cd "$( dirname "${BASH_SOURCE[0]}" )" 42 | repo_dir=$(git rev-parse --show-toplevel) 43 | cd ${repo_dir} 44 | 45 | # Make a clean copy of HEAD, without files ignored by git (but potentially kept by setup.py). 46 | if [ ! -z "$(git status --short)" ]; then 47 | echo -e "\e[31mWARNING: You have uncommitted changes. They won't be included in the package.\e[0m" 48 | fi 49 | tmp_git_dir=$(mktemp -d "/tmp/produce-package-git.XXXXXXXXXXXXXXXX") 50 | trap "{ rm -rf ${tmp_git_dir}; }" EXIT 51 | cd "${tmp_git_dir}" 52 | git init --quiet 53 | git fetch ${repo_dir} HEAD --quiet --depth=1 54 | git checkout FETCH_HEAD -b work --quiet 55 | if [ ! -z "${SPECIFIED_VERSION}" ]; then 56 | echo '__version__ = "'"${SPECIFIED_VERSION}"'"' > "${tmp_git_dir}/${PROJECT_NAME}/_version.py" 57 | fi 58 | 59 | # Python 3 wheel. 60 | echo "Producing python 3 package files..." 61 | python3 setup.py -q bdist_wheel -d "${out_dir}" 62 | 63 | ls "${out_dir}" 64 | -------------------------------------------------------------------------------- /dev_tools/run_pytest_and_incremental_coverage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import os 18 | import sys 19 | 20 | from dev_tools import all_checks, prepared_env, shell_tools 21 | 22 | 23 | def main(): 24 | if len(sys.argv) < 2: 25 | print(shell_tools.highlight( 26 | 'Must specify a comparison branch ' 27 | '(e.g. "origin/master" or "HEAD~1").', 28 | shell_tools.RED)) 29 | sys.exit(1) 30 | comparison_branch = sys.argv[1] 31 | 32 | env = prepared_env.PreparedEnv( 33 | github_repo=None, 34 | actual_commit_id=None, # local uncommitted files 35 | compare_commit_id=comparison_branch, 36 | destination_directory=os.getcwd(), 37 | virtual_env_path=None) 38 | check_results = [ 39 | all_checks.pytest.run(env, False, set()), 40 | all_checks.incremental_coverage.run(env, False, set()), 41 | ] 42 | if any(not e.success for e in check_results): 43 | print(shell_tools.highlight( 44 | 'Failed.', 45 | shell_tools.RED)) 46 | sys.exit(1) 47 | 48 | 49 | if __name__ == '__main__': 50 | main() 51 | -------------------------------------------------------------------------------- /dev_tools/run_simple_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import os 18 | import sys 19 | 20 | from dev_tools import all_checks, prepared_env 21 | 22 | 23 | def main(): 24 | args = sys.argv 25 | verbose = True 26 | only = [e.split('--only=')[1] 27 | for e in args 28 | if e.startswith('--only=')] 29 | checks = [ 30 | all_checks.pylint, 31 | all_checks.typecheck, 32 | all_checks.pytest, 33 | all_checks.incremental_coverage, 34 | ] 35 | if only: 36 | checks = [e for e in checks if e.command_line_switch() in only] 37 | if len(checks) != len(only): 38 | print('Bad --only argument. Allowed values {!r}.'.format( 39 | [e.command_line_switch() for e in all_checks.ALL_CHECKS]), 40 | file=sys.stderr) 41 | sys.exit(1) 42 | 43 | env = prepared_env.PreparedEnv( 44 | github_repo=None, 45 | actual_commit_id=None, # local uncommitted files 46 | compare_commit_id='master', 47 | destination_directory=os.getcwd(), 48 | virtual_env_path=None) 49 | check_results = [] 50 | failures = set() 51 | for c in checks: 52 | print() 53 | result = c.run(env, verbose, failures) 54 | 55 | # Record results. 56 | check_results.append(result) 57 | if not result.success: 58 | failures.add(c) 59 | print() 60 | 61 | print() 62 | print("ALL CHECK RESULTS") 63 | for result in check_results: 64 | print(result) 65 | 66 | if any(not e.success for e in check_results): 67 | sys.exit(1) 68 | 69 | 70 | if __name__ == '__main__': 71 | main() 72 | -------------------------------------------------------------------------------- /dev_tools/run_travis.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import os 18 | import sys 19 | 20 | from dev_tools import shell_tools, all_checks, prepared_env 21 | 22 | 23 | def main(): 24 | verbose = True 25 | checks = [ 26 | all_checks.pylint, 27 | all_checks.typecheck, 28 | all_checks.pytest, 29 | all_checks.incremental_coverage, 30 | ] 31 | 32 | env = prepared_env.PreparedEnv(None, 'HEAD', 'master', os.getcwd(), None) 33 | results = [] 34 | for c in checks: 35 | print() 36 | print(shell_tools.highlight('Running ' + c.command_line_switch(), 37 | shell_tools.GREEN)) 38 | result = c.context(), c.perform_check(env, verbose=verbose) 39 | print(shell_tools.highlight( 40 | 'Finished ' + c.command_line_switch(), 41 | shell_tools.GREEN if result[1][0] else shell_tools.RED)) 42 | if verbose: 43 | print(result) 44 | print() 45 | results.append(result) 46 | 47 | print() 48 | print("ALL CHECK RESULTS") 49 | for result in results: 50 | print(result) 51 | 52 | if any(not e[1][0] for e in results): 53 | sys.exit(1) 54 | 55 | 56 | if __name__ == '__main__': 57 | main() 58 | -------------------------------------------------------------------------------- /dev_tools/shell_tools_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Cirq Developers 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import subprocess 16 | import os 17 | import sys 18 | 19 | import pytest 20 | 21 | from dev_tools import shell_tools 22 | 23 | 24 | def only_in_python3_on_posix(func): 25 | if os.name != 'posix': 26 | return None 27 | if sys.version_info.major < 3: 28 | return None 29 | return func 30 | 31 | 32 | def run_cmd(*args, **kwargs): 33 | return shell_tools.run_cmd(*args, log_run_to_stderr=False, **kwargs) 34 | 35 | 36 | def run_shell(*args, **kwargs): 37 | return shell_tools.run_shell(*args, log_run_to_stderr=False, **kwargs) 38 | 39 | 40 | @only_in_python3_on_posix 41 | def test_run_cmd_raise_on_fail(): 42 | assert run_cmd('true') == (None, None, 0) 43 | assert run_cmd('true', raise_on_fail=False) == (None, None, 0) 44 | 45 | with pytest.raises(subprocess.CalledProcessError): 46 | run_cmd('false') 47 | assert run_cmd('false', raise_on_fail=False) == (None, None, 1) 48 | 49 | 50 | @only_in_python3_on_posix 51 | def test_run_shell_raise_on_fail(): 52 | assert run_shell('true') == (None, None, 0) 53 | assert run_shell('true', raise_on_fail=False) == (None, None, 0) 54 | 55 | with pytest.raises(subprocess.CalledProcessError): 56 | run_shell('false') 57 | assert run_shell('false', raise_on_fail=False) == (None, None, 1) 58 | 59 | 60 | @only_in_python3_on_posix 61 | def test_run_cmd_capture(): 62 | assert run_cmd( 63 | 'echo', 'test', 64 | out=None) == (None, None, 0) 65 | assert run_cmd( 66 | 'echo', 'test', 67 | out=shell_tools.TeeCapture()) == ('test\n', None, 0) 68 | assert run_cmd( 69 | 'echo', 'test', 70 | out=None, 71 | err=shell_tools.TeeCapture()) == (None, '', 0) 72 | 73 | 74 | @only_in_python3_on_posix 75 | def test_run_shell_capture(): 76 | assert run_shell( 77 | 'echo test 1>&2', 78 | err=None) == (None, None, 0) 79 | assert run_shell( 80 | 'echo test 1>&2', 81 | err=shell_tools.TeeCapture()) == (None, 'test\n', 0) 82 | assert run_shell( 83 | 'echo test 1>&2', 84 | err=None, 85 | out=shell_tools.TeeCapture()) == ('', None, 0) 86 | 87 | 88 | @only_in_python3_on_posix 89 | def test_run_shell_does_not_deadlock_on_large_outputs(): 90 | assert run_shell( 91 | r"""python3 -c "import sys;""" 92 | r"""print((('o' * 99) + '\n') * 10000);""" 93 | r"""print((('e' * 99) + '\n') * 10000, file=sys.stderr)""" 94 | '"', 95 | out=None, 96 | err=None) == (None, None, 0) 97 | 98 | 99 | @only_in_python3_on_posix 100 | def test_output_of(): 101 | assert shell_tools.output_of('true') == '' 102 | with pytest.raises(subprocess.CalledProcessError): 103 | _ = shell_tools.output_of('false') 104 | assert shell_tools.output_of('echo', 'test') == 'test' 105 | assert shell_tools.output_of('pwd', cwd='/tmp') in ['/tmp', '/private/tmp'] 106 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = OpenFermion-Cirq 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | 22 | clean: 23 | -rm -rf generated 24 | -rm -rf _build 25 | -------------------------------------------------------------------------------- /docs/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The OpenFermion-Cirq Developers 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | API Reference 2 | ============= 3 | 4 | 5 | Gates 6 | -------- 7 | 8 | Two-Qubit Gates 9 | ^^^^^^^^^^^^^^^ 10 | 11 | .. autosummary:: 12 | :toctree: generated/ 13 | 14 | openfermioncirq.FSWAP 15 | openfermioncirq.XXYY 16 | openfermioncirq.YXXY 17 | openfermioncirq.rot11 18 | openfermioncirq.FSwapPowGate 19 | openfermioncirq.Rxxyy 20 | openfermioncirq.Ryxxy 21 | openfermioncirq.Rzz 22 | openfermioncirq.XXYYPowGate 23 | openfermioncirq.YXXYPowGate 24 | 25 | Three-Qubit Gates 26 | ^^^^^^^^^^^^^^^^^ 27 | 28 | .. autosummary:: 29 | :toctree: generated/ 30 | 31 | openfermioncirq.CXXYY 32 | openfermioncirq.CYXXY 33 | openfermioncirq.rot111 34 | openfermioncirq.CRxxyy 35 | openfermioncirq.CRyxxy 36 | openfermioncirq.CXXYYPowGate 37 | openfermioncirq.CYXXYPowGate 38 | 39 | Four-Qubit Gates 40 | ^^^^^^^^^^^^^^^^^ 41 | 42 | .. autosummary:: 43 | :toctree: generated/ 44 | 45 | openfermioncirq.DoubleExcitation 46 | openfermioncirq.DoubleExcitationGate 47 | 48 | Fermionic Simulation Gates 49 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 50 | 51 | .. autosummary:: 52 | :toctree: generated/ 53 | 54 | openfermioncirq.fermionic_simulation_gates_from_interaction_operator 55 | openfermioncirq.CubicFermionicSimulationGate 56 | openfermioncirq.ParityPreservingFermionicGate 57 | openfermioncirq.QuadraticFermionicSimulationGate 58 | openfermioncirq.QuarticFermionicSimulationGate 59 | 60 | 61 | Primitives 62 | ---------- 63 | 64 | .. autosummary:: 65 | :toctree: generated/ 66 | 67 | openfermioncirq.bogoliubov_transform 68 | openfermioncirq.ffft 69 | openfermioncirq.prepare_gaussian_state 70 | openfermioncirq.prepare_slater_determinant 71 | openfermioncirq.swap_network 72 | 73 | 74 | Hamiltonian Simulation 75 | ---------------------- 76 | 77 | .. autosummary:: 78 | :toctree: generated/ 79 | 80 | openfermioncirq.simulate_trotter 81 | openfermioncirq.trotter.LINEAR_SWAP_NETWORK 82 | openfermioncirq.trotter.LOW_RANK 83 | openfermioncirq.trotter.SPLIT_OPERATOR 84 | openfermioncirq.trotter.TrotterAlgorithm 85 | openfermioncirq.trotter.TrotterStep 86 | 87 | Trotter Algorithms 88 | ^^^^^^^^^^^^^^^^^^ 89 | 90 | .. autosummary:: 91 | :toctree: generated/ 92 | 93 | openfermioncirq.trotter.LinearSwapNetworkTrotterAlgorithm 94 | openfermioncirq.trotter.LowRankTrotterAlgorithm 95 | openfermioncirq.trotter.SplitOperatorTrotterAlgorithm 96 | 97 | 98 | Variational Algorithms 99 | ---------------------- 100 | 101 | .. autosummary:: 102 | :toctree: generated/ 103 | 104 | openfermioncirq.HamiltonianObjective 105 | openfermioncirq.VariationalAnsatz 106 | openfermioncirq.VariationalObjective 107 | openfermioncirq.VariationalStudy 108 | 109 | Variational Ansatzes 110 | ^^^^^^^^^^^^^^^^^^^^ 111 | 112 | .. autosummary:: 113 | :toctree: generated/ 114 | 115 | openfermioncirq.LowRankTrotterAnsatz 116 | openfermioncirq.SplitOperatorTrotterAnsatz 117 | openfermioncirq.SwapNetworkTrotterAnsatz 118 | openfermioncirq.SwapNetworkTrotterHubbardAnsatz 119 | 120 | 121 | Optimization 122 | ------------ 123 | 124 | .. autosummary:: 125 | :toctree: generated/ 126 | 127 | openfermioncirq.optimization.COBYLA 128 | openfermioncirq.optimization.L_BFGS_B 129 | openfermioncirq.optimization.NELDER_MEAD 130 | openfermioncirq.optimization.SLSQP 131 | openfermioncirq.optimization.BlackBox 132 | openfermioncirq.optimization.OptimizationAlgorithm 133 | openfermioncirq.optimization.OptimizationParams 134 | openfermioncirq.optimization.OptimizationResult 135 | openfermioncirq.optimization.OptimizationTrialResult 136 | openfermioncirq.optimization.ScipyOptimizationAlgorithm 137 | openfermioncirq.optimization.StatefulBlackBox 138 | -------------------------------------------------------------------------------- /docs/docs_coverage_test.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | from pathlib import Path 3 | from typing import Set, Dict, Tuple, Any, List 4 | 5 | import openfermioncirq as ofc 6 | 7 | 8 | def _all_public() -> Set[str]: 9 | module_scopes = [ 10 | (ofc, 'openfermioncirq'), 11 | (ofc.optimization, 'openfermioncirq.optimization'), 12 | (ofc.trotter, 'openfermioncirq.trotter'), 13 | ] 14 | 15 | by_name: Dict[str, Tuple[str, Any]] = {} 16 | result: Set[str] = set() 17 | for module, scope in module_scopes: 18 | for name, obj in inspect.getmembers(module): 19 | if name.startswith('_') or inspect.ismodule(obj): 20 | continue 21 | 22 | full_name = f'{scope}.{name}' 23 | if name in by_name: 24 | old_full_name, old_obj = by_name[name] 25 | if obj is not old_obj: 26 | # coverage: ignore 27 | raise ValueError(f'Ambiguous name:\n' 28 | f'{old_full_name}\n' 29 | f'{full_name}\n') 30 | if len(full_name) > len(old_full_name): 31 | continue 32 | 33 | # coverage: ignore 34 | result.remove(old_full_name) 35 | 36 | by_name[name] = (full_name, obj) 37 | result.add(full_name) 38 | return result 39 | 40 | 41 | def _api_rst_fullnames_per_section() -> List[List[str]]: 42 | result: List[List[str]] = [] 43 | section: List[str] = [] 44 | seen: Set[str] = set() 45 | with open(Path(__file__).parent / 'api.rst', mode='r') as f: 46 | for line in f.readlines(): 47 | if line.strip() == '.. autosummary::': 48 | if section: 49 | result.append(section) 50 | section = [] 51 | elif line.startswith(' openfermioncirq.'): 52 | fullname = line.strip() 53 | if fullname in seen: 54 | # coverage: ignore 55 | raise ValueError(f'{fullname} appears twice in api.rst') 56 | section.append(fullname) 57 | seen.add(fullname) 58 | if section: 59 | result.append(section) 60 | return result 61 | 62 | 63 | def test_public_values_equals_documented_values(): 64 | in_actual_api = _all_public() 65 | in_api_reference = { 66 | fullname for section in _api_rst_fullnames_per_section() 67 | for fullname in section 68 | } 69 | unlisted = in_actual_api - in_api_reference 70 | hidden = {fullname for fullname in in_api_reference - in_actual_api} 71 | assert not unlisted, ( 72 | 'Public class/method/value not listed in docs/api.rst:' 73 | '\n ' + '\n '.join(sorted(unlisted))) 74 | assert not hidden, ( 75 | 'Private or non-existent class/method/value listed in docs/api.rst:' 76 | '\n ' + '\n '.join(sorted(hidden))) 77 | 78 | 79 | def test_api_rst_sorted(): 80 | 81 | def order(fullname: str) -> Any: 82 | name = fullname.split('.')[-1] 83 | start = fullname[:-len(name)] 84 | return ( 85 | # First sort by package. 86 | start, 87 | # Then by tiny-ness (len=1 then len=2 then other). 88 | min(len(name), 3), 89 | # Then by type (constants then methods then classes). 90 | name != name.upper(), 91 | name != name.lower(), 92 | # Then by name. 93 | fullname) 94 | 95 | for section in _api_rst_fullnames_per_section(): 96 | sorted_section = sorted(section, key=order) 97 | assert section == sorted_section, ( 98 | f"A section in api.rst is not sorted. Should be:\n " + 99 | '\n '.join(sorted_section)) 100 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. OpenFermion-Cirq documentation master file, created by 2 | sphinx-quickstart on Mon Jul 16 00:40:07 2018. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to OpenFermion-Cirq's documentation! 7 | ============================================ 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | api 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx 2 | sphinx_rtd_theme 3 | -------------------------------------------------------------------------------- /examples/examples_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import os 14 | 15 | import pytest 16 | 17 | import nbformat 18 | 19 | 20 | def find_examples_jupyter_notebook_paths(): 21 | examples_folder = os.path.dirname(__file__) 22 | for filename in os.listdir(examples_folder): 23 | if not filename.endswith('.ipynb'): 24 | continue 25 | yield os.path.join(examples_folder, filename) 26 | 27 | 28 | @pytest.mark.parametrize('path', find_examples_jupyter_notebook_paths()) 29 | def test_can_run_examples_jupyter_notebook(path): 30 | notebook = nbformat.read(path, nbformat.NO_CONVERT) 31 | state = {} # type: Dict[str, Any] 32 | 33 | for cell in notebook.cells: 34 | if cell.cell_type == 'code' and not is_matplotlib_cell(cell): 35 | try: 36 | exec(strip_magics_and_shows(cell.source), state) 37 | # coverage: ignore 38 | except: 39 | print('Failed to run {}.'.format(path)) 40 | raise 41 | 42 | 43 | def is_matplotlib_cell(cell): 44 | return "%matplotlib" in cell.source 45 | 46 | 47 | def strip_magics_and_shows(text): 48 | """Remove Jupyter magics and pyplot show commands.""" 49 | lines = [line for line in text.split('\n') 50 | if not contains_magic_or_show(line)] 51 | return '\n'.join(lines) 52 | 53 | 54 | def contains_magic_or_show(line): 55 | return (line.strip().startswith('%') or 56 | 'pyplot.show(' in line or 57 | 'plt.show(' in line) 58 | -------------------------------------------------------------------------------- /openfermioncirq/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | # pylint: disable=wrong-import-position 14 | 15 | import warnings 16 | 17 | warnings.warn( 18 | 'OpenFermion-Cirq is deprecated and no longer maintained. ' 19 | 'Its functionality has been merged into OpenFermion. ' 20 | 'To uninstall OpenFermion-Cirq and upgrade to the latest version of ' 21 | 'OpenFermion using pip, execute ' 22 | '`pip uninstall openfermioncirq` followed by ' 23 | '`pip install --upgrade openfermion`.', 24 | DeprecationWarning, 25 | stacklevel=2) 26 | 27 | from openfermioncirq.gates import ( 28 | CRxxyy, 29 | CRyxxy, 30 | CXXYYPowGate, 31 | CYXXYPowGate, 32 | DoubleExcitation, 33 | DoubleExcitationGate, 34 | FSWAP, 35 | FSwapPowGate, 36 | Rxxyy, 37 | Ryxxy, 38 | Rzz, 39 | rot11, 40 | rot111, 41 | XXYYPowGate, 42 | YXXYPowGate, 43 | fermionic_simulation_gates_from_interaction_operator, 44 | ParityPreservingFermionicGate, 45 | QuadraticFermionicSimulationGate, 46 | CubicFermionicSimulationGate, 47 | QuarticFermionicSimulationGate, 48 | ) 49 | 50 | from openfermioncirq.primitives import ( 51 | ffft, 52 | prepare_gaussian_state, 53 | prepare_slater_determinant, 54 | ) 55 | 56 | from openfermioncirq.primitives.bogoliubov_transform import bogoliubov_transform 57 | 58 | from openfermioncirq.primitives.swap_network import swap_network 59 | 60 | from openfermioncirq.trotter import simulate_trotter 61 | 62 | from openfermioncirq.variational import ( 63 | HamiltonianObjective, 64 | LowRankTrotterAnsatz, 65 | SplitOperatorTrotterAnsatz, 66 | SwapNetworkTrotterAnsatz, 67 | SwapNetworkTrotterHubbardAnsatz, 68 | VariationalAnsatz, 69 | VariationalObjective, 70 | VariationalStudy, 71 | ) 72 | 73 | # Import modules last to avoid circular dependencies 74 | from openfermioncirq import ( 75 | gates, 76 | optimization, 77 | primitives, 78 | trotter, 79 | variational, 80 | testing, 81 | ) 82 | 83 | from openfermioncirq._version import __version__ 84 | 85 | # Deprecated 86 | # pylint: disable=wrong-import-order 87 | import sys as _sys 88 | import warnings as _warnings 89 | from openfermioncirq._compat import wrap_module as _wrap_module 90 | with _warnings.catch_warnings(): 91 | _warnings.simplefilter('ignore') 92 | from openfermioncirq.gates.common_gates import ( 93 | XXYY, 94 | YXXY, 95 | ) 96 | from openfermioncirq.gates.three_qubit_gates import ( 97 | CXXYY, 98 | CYXXY, 99 | ) 100 | _deprecated_constants = { 101 | 'XXYY': ('v0.5.0', 'Use cirq.ISWAP with negated exponent, instead'), 102 | 'YXXY': ('v0.5.0', 'Use cirq.PhasedISwapPowGate, instead.'), 103 | 'CXXYY': ('v0.5.0', 'Use cirq.ControlledGate and cirq.ISWAP with ' 104 | 'negated exponent, instead'), 105 | 'CYXXY': ('v0.5.0', 'Use cirq.ControlledGate and ' 106 | 'cirq.PhasedISwapPowGate, instead.'), 107 | } 108 | _sys.modules[__name__] = _wrap_module(_sys.modules[__name__], 109 | _deprecated_constants) 110 | -------------------------------------------------------------------------------- /openfermioncirq/_compat.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | from typing import Dict, Tuple 13 | from types import ModuleType 14 | import warnings 15 | 16 | 17 | def wrap_module(module: ModuleType, 18 | deprecated_attributes: Dict[str, Tuple[str, str]]): 19 | """Wrap a module with deprecated attributes. 20 | 21 | Args: 22 | module: The module to wrap. 23 | deprecated_attributes: A dictionary from attribute name to pair of 24 | strings, where the first string gives the version that the attribute 25 | will be removed in, and the second string describes what the user 26 | should do instead of accessing this deprecated attribute. 27 | 28 | Returns: 29 | Wrapped module with deprecated attributes. 30 | """ 31 | 32 | class Wrapped(ModuleType): 33 | 34 | __dict__ = module.__dict__ 35 | 36 | def __getattr__(self, name): 37 | if name in deprecated_attributes: 38 | version, fix = deprecated_attributes[name] 39 | warnings.warn( 40 | f'{name} was used but is deprecated.\n' 41 | f'It will be removed in ' 42 | f'openfermioncirq {version}.\n' 43 | f'{fix}\n', 44 | DeprecationWarning, 45 | stacklevel=2) 46 | return getattr(module, name) 47 | 48 | return Wrapped(module.__name__, module.__doc__) 49 | -------------------------------------------------------------------------------- /openfermioncirq/_compat_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | from typing import Any, Callable 13 | import functools 14 | import warnings 15 | 16 | import pytest 17 | import deprecation 18 | 19 | import openfermioncirq as ofc 20 | from openfermioncirq._compat import wrap_module 21 | 22 | 23 | def deprecated_test(test: Callable) -> Callable: 24 | """Marks a test as using deprecated functionality. 25 | 26 | Ensures the test is executed within the `pytest.deprecated_call()` context. 27 | 28 | Args: 29 | test: The test. 30 | 31 | Returns: 32 | The decorated test. 33 | """ 34 | 35 | @functools.wraps(test) 36 | def decorated_test(*args, **kwargs) -> Any: 37 | with pytest.deprecated_call(): 38 | test(*args, **kwargs) 39 | 40 | return decorated_test 41 | 42 | 43 | @deprecation.deprecated() 44 | def f(): 45 | pass 46 | 47 | 48 | def test_deprecated_test(): 49 | 50 | @deprecated_test 51 | def test(): 52 | f() 53 | 54 | with warnings.catch_warnings(record=True) as w: 55 | warnings.simplefilter('ignore') 56 | warnings.simplefilter('default', DeprecationWarning) 57 | test() 58 | assert len(w) == 0 59 | 60 | 61 | def test_wrap_module(): 62 | ofc.deprecated_attribute = None 63 | wrapped_ofc = wrap_module(ofc, {'deprecated_attribute': ('', '')}) 64 | with pytest.deprecated_call(): 65 | _ = wrapped_ofc.deprecated_attribute 66 | -------------------------------------------------------------------------------- /openfermioncirq/_version.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Define version number here and read it from setup.py automatically""" 14 | 15 | __version__ = "0.4.1.dev" 16 | -------------------------------------------------------------------------------- /openfermioncirq/contrib/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Package for contributions. 14 | 15 | Any contributions not ready for full production can be put in a subdirectory in 16 | this package. 17 | """ 18 | -------------------------------------------------------------------------------- /openfermioncirq/contrib/contrib-requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/contrib/contrib-requirements.txt -------------------------------------------------------------------------------- /openfermioncirq/contrib/contrib_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | def test_contrib_is_a_module(): 15 | from openfermioncirq import contrib 16 | assert contrib is not None 17 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/__init__.py -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/README.md: -------------------------------------------------------------------------------- 1 | Hartree-Fock on a superconducting qubit quantum processor 2 | --------------------------------------------------------- 3 | 4 | This module contains the necessary code to run 5 | the Hartree-Fock VQE experiment described in [arXiv:2004.04174](https://arxiv.org/abs/2004.04174). The goal in providing this code is 6 | transparency of the experiment and so other researchers can 7 | use this as a basis for molecular simulations. This is a living code base 8 | and various pieces may be integrated into OpenFermion over time. 9 | 10 | Quickstart 11 | ---------- 12 | An [ipython notebook](quickstart.ipynb) provided with this module describes how to initialize and run 13 | a Hartree-Fock VQE calculation. It steps through estimating the 1-RDM 14 | given a set of parameters for the basis transformation unitary and then provides an example of 15 | variational relaxation of the parameters. 16 | 17 | Utilities for estimating all quantities described in [arXiv:2004.04174](https://arxiv.org/abs/2004.04174) such as fidelities, 18 | fidelity witness values, absolute errors, and error bars are also provided. 19 | 20 | All software for running the experiment is in the `openfermioncirq.experiments.hfvqe` subfolder. The 21 | molecular data used in the experiment can be found in the 22 | `openfermioncirq.experiments.hfvqe.molecular_data` directory. 23 | 24 | Molecular Data 25 | -------------- 26 | The paper describes the performance of VQE-HF for four Hydrogen chain systems and Diazene. We provide 27 | molecular data files and utilities for generating the Hydrogen chain inputs using OpenFermion, 28 | OpenFermion-Psi4. and Psi4. The Diazene data can be found in the 29 | [openfermion-cloud](https://github.com/quantumlib/OpenFermion/tree/master/cloud_library) repository. 30 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/__init__.py -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/gradient_hf.py: -------------------------------------------------------------------------------- 1 | """ 2 | An implementation of gradient based Restricted-Hartree-Fock 3 | 4 | This uses a bunch of the infrastructure already used in the experiment 5 | should only need an RHF_object. 6 | """ 7 | # pylint: disable=C 8 | from typing import Optional, Union 9 | import numpy as np 10 | import scipy as sp 11 | 12 | from openfermioncirq.experiments.hfvqe.circuits import rhf_params_to_matrix 13 | from openfermioncirq.experiments.hfvqe.objective import RestrictedHartreeFockObjective 14 | 15 | 16 | def rhf_func_generator(rhf_objective: RestrictedHartreeFockObjective, 17 | initial_occ_vec: Optional[Union[None, np.ndarray]] = None, 18 | get_opdm_func: Optional[bool] = False): 19 | """ 20 | Generate the energy, gradient, and unitary functions 21 | 22 | :param rhf_objective: objective function object 23 | :param initial_occ_vec: (optional) vector for occupation numbers of the alpha-opdm 24 | :return: functions for unitary, energy, gradient (in that order) 25 | """ 26 | if initial_occ_vec is None: 27 | initial_opdm = np.diag([1] * rhf_objective.nocc + [0] * rhf_objective.nvirt) 28 | else: 29 | initial_opdm = np.diag(initial_occ_vec) 30 | 31 | def energy(params): 32 | u = unitary(params) 33 | final_opdm_aa = u @ initial_opdm @ np.conjugate(u).T 34 | tenergy = rhf_objective.energy_from_opdm(final_opdm_aa) 35 | return tenergy 36 | 37 | def gradient(params): 38 | u = unitary(params) 39 | final_opdm_aa = u @ initial_opdm @ np.conjugate(u).T 40 | return rhf_objective.global_gradient_opdm(params, final_opdm_aa).real 41 | 42 | def unitary(params): 43 | kappa = rhf_params_to_matrix(params, 44 | len(rhf_objective.occ) + len(rhf_objective.virt), 45 | rhf_objective.occ, rhf_objective.virt) 46 | return sp.linalg.expm(kappa) 47 | 48 | def get_opdm(params): 49 | u = unitary(params) 50 | return u @ initial_opdm @ np.conjugate(u).T 51 | 52 | if get_opdm_func: 53 | return unitary, energy, gradient, get_opdm 54 | return unitary, energy, gradient 55 | 56 | 57 | def rhf_minimization(rhf_object, method='CG', initial_guess=None, verbose=True): 58 | """ 59 | Perform Hartree-Fock energy minimization 60 | 61 | :param rhf_object: RestrictedHartreeFockObject 62 | :param method: (optional sp opt method) 63 | :return: sp result object 64 | """ 65 | _, energy, gradient = rhf_func_generator(rhf_object) 66 | if initial_guess is None: 67 | init_guess = np.zeros(rhf_object.nocc * rhf_object.nvirt) 68 | else: 69 | init_guess = initial_guess.flatten() 70 | 71 | return sp.optimize.minimize(energy, init_guess, jac=gradient, method=method, 72 | options={'disp': verbose}) 73 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/gradient_hf_test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from openfermioncirq.experiments.hfvqe.gradient_hf import (rhf_func_generator, 3 | rhf_minimization) 4 | from openfermioncirq.experiments.hfvqe.molecular_example import make_h6_1_3 5 | 6 | 7 | def test_rhf_func_gen(): 8 | rhf_objective, molecule, parameters, _, _ = make_h6_1_3() 9 | ansatz, energy, _ = rhf_func_generator(rhf_objective) 10 | assert np.isclose(molecule.hf_energy, energy(parameters)) 11 | 12 | ansatz, energy, _, opdm_func = rhf_func_generator( 13 | rhf_objective, initial_occ_vec=[1] * 3 + [0] * 3, get_opdm_func=True) 14 | assert np.isclose(molecule.hf_energy, energy(parameters)) 15 | test_opdm = opdm_func(parameters) 16 | u = ansatz(parameters) 17 | initial_opdm = np.diag([1] * 3 + [0] * 3) 18 | final_odpm = u @ initial_opdm @ u.T 19 | assert np.allclose(test_opdm, final_odpm) 20 | 21 | result = rhf_minimization(rhf_objective, initial_guess=parameters) 22 | assert np.allclose(result.x, parameters) 23 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/__init__.py -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/H10_sto-3g_singlet_linear_r-0.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/H10_sto-3g_singlet_linear_r-0.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/H10_sto-3g_singlet_linear_r-0.9.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/H10_sto-3g_singlet_linear_r-0.9.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_0.9/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/H10_sto-3g_singlet_linear_r-1.3.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/H10_sto-3g_singlet_linear_r-1.3.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.3/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/H10_sto-3g_singlet_linear_r-1.7000000000000002.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/H10_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_1.7/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/H10_sto-3g_singlet_linear_r-2.1.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/H10_sto-3g_singlet_linear_r-2.1.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.1/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/H10_sto-3g_singlet_linear_r-2.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/H10_sto-3g_singlet_linear_r-2.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_10_sto-3g/bond_distance_2.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/H12_sto-3g_singlet_linear_r-0.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/H12_sto-3g_singlet_linear_r-0.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/H12_sto-3g_singlet_linear_r-0.9.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/H12_sto-3g_singlet_linear_r-0.9.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_0.9/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/H12_sto-3g_singlet_linear_r-1.3.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/H12_sto-3g_singlet_linear_r-1.3.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.3/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/H12_sto-3g_singlet_linear_r-1.7000000000000002.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/H12_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_1.7/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/H12_sto-3g_singlet_linear_r-2.1.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/H12_sto-3g_singlet_linear_r-2.1.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.1/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/H12_sto-3g_singlet_linear_r-2.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/H12_sto-3g_singlet_linear_r-2.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_12_sto-3g/bond_distance_2.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/H3_plus_sto-3g_singlet_linear_r-2.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/H3_plus_sto-3g_singlet_linear_r-2.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/H6_sto-3g_singlet_linear_r-0.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/H6_sto-3g_singlet_linear_r-0.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/H6_sto-3g_singlet_linear_r-0.9.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/H6_sto-3g_singlet_linear_r-0.9.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_0.9/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/H6_sto-3g_singlet_linear_r-1.3.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/H6_sto-3g_singlet_linear_r-1.3.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/H6_sto-3g_singlet_linear_r-1.7000000000000002.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/H6_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.7/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/H6_sto-3g_singlet_linear_r-2.1.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/H6_sto-3g_singlet_linear_r-2.1.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.1/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/H6_sto-3g_singlet_linear_r-2.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/H6_sto-3g_singlet_linear_r-2.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_2.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/H8_sto-3g_singlet_linear_r-0.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/H8_sto-3g_singlet_linear_r-0.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/H8_sto-3g_singlet_linear_r-0.9.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/H8_sto-3g_singlet_linear_r-0.9.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_0.9/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/H8_sto-3g_singlet_linear_r-1.3.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/H8_sto-3g_singlet_linear_r-1.3.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.3/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/H8_sto-3g_singlet_linear_r-1.7000000000000002.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/H8_sto-3g_singlet_linear_r-1.7000000000000002.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_1.7/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/H8_sto-3g_singlet_linear_r-2.1.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/H8_sto-3g_singlet_linear_r-2.1.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.1/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/H8_sto-3g_singlet_linear_r-2.5.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/H8_sto-3g_singlet_linear_r-2.5.hdf5 -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/h_core.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/h_core.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/overlap.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/overlap.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/parameters.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/parameters.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/tei.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/tei.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/true_opdm.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/h_8_sto-3g/bond_distance_2.5/true_opdm.npy -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/hydrogen_chains/make_rhf_simulations.py: -------------------------------------------------------------------------------- 1 | # coverage: ignore 2 | """ 3 | Implement the H2-experiment with OpenFermion and OpenFermion-Cirq 4 | """ 5 | # Numerical Imports 6 | import numpy 7 | 8 | import scipy 9 | 10 | import os 11 | 12 | from openfermion.ops import general_basis_change 13 | 14 | from openfermioncirq.experiments.hfvqe.molecular_data.molecular_data_construction import (h6_linear_molecule, 15 | h8_linear_molecule, 16 | h10_linear_molecule, 17 | h12_linear_molecule, 18 | get_ao_integrals 19 | ) 20 | 21 | from openfermioncirq.experiments.hfvqe.gradient_hf import rhf_minimization, rhf_func_generator 22 | from openfermioncirq.experiments.hfvqe.objective import \ 23 | RestrictedHartreeFockObjective, generate_hamiltonian 24 | 25 | 26 | def make_rhf_objective(molecule): 27 | # coverage: ignore 28 | S, Hcore, TEI = get_ao_integrals(molecule) 29 | evals, X = scipy.linalg.eigh(Hcore, S) 30 | 31 | molecular_hamiltonian = generate_hamiltonian( 32 | general_basis_change(Hcore, X, (1, 0)), 33 | numpy.einsum('psqr', general_basis_change(TEI, X, (1, 0, 1, 0)), 34 | molecule.nuclear_repulsion) 35 | ) 36 | 37 | rhf_objective = RestrictedHartreeFockObjective(molecular_hamiltonian, 38 | molecule.n_electrons) 39 | return rhf_objective, S, Hcore, TEI 40 | 41 | 42 | if __name__ == "__main__": 43 | # coverage: ignore 44 | # make simulations 45 | molecule_generator = {6: h6_linear_molecule, 46 | 8: h8_linear_molecule, 47 | 10: h10_linear_molecule, 48 | 12: h12_linear_molecule} 49 | 50 | for n in range(6, 13, 2): 51 | name = "h_{}_sto-3g".format(n) 52 | print(name) 53 | # now make a dirctory with the name 54 | os.mkdir(name) 55 | os.chdir(name) 56 | # # now make a separate folder for each of 50 points along a line 57 | bond_distances = numpy.linspace(0.5, 2.5, 6) 58 | for bb in bond_distances: 59 | print(bb) 60 | local_dir = 'bond_distance_{:.1f}'.format(bb) 61 | os.mkdir(local_dir) 62 | os.chdir(local_dir) 63 | molecule = molecule_generator[n](bb) 64 | 65 | rhf_objective, S, HCore, TEI = make_rhf_objective(molecule) 66 | 67 | numpy.save("overlap.npy", S) 68 | numpy.save("h_core.npy", HCore) 69 | numpy.save("tei.npy", TEI) 70 | 71 | ansatz, energy, gradient = rhf_func_generator(rhf_objective) 72 | scipy_result = rhf_minimization(rhf_objective) 73 | print(molecule.hf_energy) 74 | print(scipy_result.fun) 75 | assert numpy.isclose(molecule.hf_energy, scipy_result.fun) 76 | 77 | numpy.save("parameters.npy", numpy.asarray(scipy_result.x)) 78 | initial_opdm = numpy.diag([1] * rhf_objective.nocc + [0] * rhf_objective.nvirt) 79 | unitary = ansatz(scipy_result.x) 80 | final_opdm = unitary @ initial_opdm @ numpy.conjugate(unitary).T 81 | assert numpy.isclose(rhf_objective.energy_from_opdm(final_opdm), scipy_result.fun) 82 | numpy.save("true_opdm.npy", numpy.asarray(final_opdm)) 83 | 84 | molecule.filename = os.path.join(os.getcwd(), molecule.name) 85 | molecule.save() 86 | 87 | os.chdir('../') 88 | os.chdir('../') 89 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_data/molecular_data_constructor_test.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=C 2 | # coverage: ignore 3 | import pytest 4 | from openfermioncirq.experiments.hfvqe.molecular_data.molecular_data_construction import h_n_linear_molecule 5 | 6 | 7 | def test_negative_n_hydrogen_chain(): 8 | # coverage: ignore 9 | with pytest.raises(ValueError): 10 | h_n_linear_molecule(1.3, 0) -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_example.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import Tuple 3 | 4 | import numpy as np 5 | import openfermion as of 6 | import scipy as sp 7 | 8 | from openfermioncirq.experiments.hfvqe.gradient_hf import rhf_minimization 9 | from openfermioncirq.experiments.hfvqe.objective import ( 10 | RestrictedHartreeFockObjective, generate_hamiltonian) 11 | 12 | 13 | def make_h6_1_3() -> Tuple[RestrictedHartreeFockObjective, 14 | of.MolecularData, 15 | np.ndarray, 16 | np.ndarray, 17 | np.ndarray]: 18 | # load the molecule from moelcular data 19 | import openfermioncirq.experiments.hfvqe as hfvqe 20 | h6_1_3_path = os.path.join( 21 | hfvqe.__path__[0], 22 | 'molecular_data/hydrogen_chains/h_6_sto-3g/bond_distance_1.3') 23 | 24 | molfile = os.path.join(h6_1_3_path, 'H6_sto-3g_singlet_linear_r-1.3.hdf5') 25 | molecule = of.MolecularData(filename=molfile) 26 | molecule.load() 27 | 28 | S = np.load(os.path.join(h6_1_3_path, 'overlap.npy')) 29 | Hcore = np.load(os.path.join(h6_1_3_path, 'h_core.npy')) 30 | TEI = np.load(os.path.join(h6_1_3_path, 'tei.npy')) 31 | 32 | _, X = sp.linalg.eigh(Hcore, S) 33 | obi = of.general_basis_change(Hcore, X, (1, 0)) 34 | tbi = np.einsum('psqr', of.general_basis_change(TEI, X, (1, 0, 1, 0))) 35 | molecular_hamiltonian = generate_hamiltonian(obi, tbi, 36 | molecule.nuclear_repulsion) 37 | 38 | rhf_objective = RestrictedHartreeFockObjective(molecular_hamiltonian, 39 | molecule.n_electrons) 40 | 41 | scipy_result = rhf_minimization(rhf_objective) 42 | 43 | return rhf_objective, molecule, scipy_result.x, obi, tbi 44 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/molecular_example_odd_qubits.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import Tuple 3 | 4 | import numpy as np 5 | import openfermion as of 6 | import scipy as sp 7 | import openfermioncirq.experiments.hfvqe as hfvqe 8 | 9 | from openfermioncirq.experiments.hfvqe.gradient_hf import rhf_minimization 10 | from openfermioncirq.experiments.hfvqe.objective import ( 11 | RestrictedHartreeFockObjective, generate_hamiltonian) 12 | 13 | 14 | def make_h3_2_5() -> Tuple[RestrictedHartreeFockObjective, of.MolecularData, np. 15 | ndarray, np.ndarray, np.ndarray]: 16 | # load the molecule from moelcular data 17 | h3_2_5_path = os.path.join( 18 | hfvqe.__path__[0], 19 | 'molecular_data/hydrogen_chains/h_3_p_sto-3g/bond_distance_2.5') 20 | 21 | molfile = os.path.join(h3_2_5_path, 22 | 'H3_plus_sto-3g_singlet_linear_r-2.5.hdf5') 23 | molecule = of.MolecularData(filename=molfile) 24 | molecule.load() 25 | 26 | S = np.load(os.path.join(h3_2_5_path, 'overlap.npy')) 27 | Hcore = np.load(os.path.join(h3_2_5_path, 'h_core.npy')) 28 | TEI = np.load(os.path.join(h3_2_5_path, 'tei.npy')) 29 | 30 | _, X = sp.linalg.eigh(Hcore, S) 31 | obi = of.general_basis_change(Hcore, X, (1, 0)) 32 | tbi = np.einsum('psqr', of.general_basis_change(TEI, X, (1, 0, 1, 0))) 33 | molecular_hamiltonian = generate_hamiltonian(obi, tbi, 34 | molecule.nuclear_repulsion) 35 | 36 | rhf_objective = RestrictedHartreeFockObjective(molecular_hamiltonian, 37 | molecule.n_electrons) 38 | 39 | scipy_result = rhf_minimization(rhf_objective) 40 | return rhf_objective, molecule, scipy_result.x, obi, tbi 41 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/opdm_functional_test.py: -------------------------------------------------------------------------------- 1 | import cirq 2 | 3 | import numpy as np 4 | 5 | import pytest 6 | 7 | from openfermioncirq.experiments.hfvqe.opdm_functionals import (RDMGenerator, 8 | OpdmFunctional) 9 | from openfermioncirq.experiments.hfvqe.analysis import compute_opdm 10 | from openfermioncirq.experiments.hfvqe.molecular_example import make_h6_1_3 11 | 12 | 13 | @pytest.mark.skip(reason='long-running systems test') 14 | def test_opdm_func_vals(): 15 | # coverage: ignore 16 | rhf_objective, molecule, parameters, obi, tbi = make_h6_1_3() 17 | qubits = [cirq.GridQubit(0, x) for x in range(molecule.n_orbitals)] 18 | np.random.seed(43) 19 | sampler = cirq.Simulator(dtype=np.complex128) 20 | opdm_func = OpdmFunctional(qubits=qubits, 21 | sampler=sampler, 22 | constant=molecule.nuclear_repulsion, 23 | one_body_integrals=obi, 24 | two_body_integrals=tbi, 25 | num_electrons=molecule.n_electrons // 2) 26 | 27 | assert isinstance(opdm_func, OpdmFunctional) 28 | 29 | data = opdm_func.calculate_data(parameters) 30 | assert isinstance(data, dict) 31 | assert list(data.keys()) == ['z', 'xy_even', 'xy_odd', 'qubits', 32 | 'qubit_permutations', 'circuits', 33 | 'circuits_with_measurement'] 34 | 35 | opdm_from_data = compute_opdm(data, return_variance=False) 36 | 37 | opdm_from_obj, var_dict = opdm_func.calculate_rdm(parameters) 38 | assert isinstance(var_dict, dict) 39 | assert np.linalg.norm(opdm_from_data - opdm_from_obj) < 1.0E-2 40 | 41 | assert np.isclose(opdm_func.energy_from_opdm(opdm_from_data), 42 | rhf_objective.energy_from_opdm(opdm_from_data)) 43 | 44 | rdm_gen = RDMGenerator(opdm_func) 45 | rdm_gen.opdm_generator(parameters) 46 | assert len(rdm_gen.noisy_opdms) == 1 47 | assert len(rdm_gen.variance_dicts) == 1 48 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/third_party/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quantumlib/OpenFermion-Cirq/655b00fee21c94cc96c343c63f7c52ea1aa329dc/openfermioncirq/experiments/hfvqe/third_party/__init__.py -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/util.py: -------------------------------------------------------------------------------- 1 | from typing import Iterable, Optional, List, Tuple 2 | import copy 3 | import numpy as np 4 | from scipy.linalg import expm 5 | 6 | 7 | def generate_permutations(n_orbitals: int, 8 | no_truncation: Optional[bool] = False): 9 | qubit_orderings = [list(range(n_orbitals))] 10 | if n_orbitals % 2 == 0: 11 | perm_order = n_orbitals // 2 12 | else: 13 | perm_order = n_orbitals // 2 + 1 14 | for _ in range(perm_order): 15 | qubit_orderings.append(swap_forward(qubit_orderings[-1], 16 | starting_index=0)) 17 | qubit_orderings.append(swap_forward(qubit_orderings[-1], 18 | starting_index=1)) 19 | if no_truncation: 20 | return qubit_orderings 21 | else: 22 | return qubit_orderings[::2][:-1] 23 | 24 | 25 | def swap_forward(iterable_item: Iterable, 26 | starting_index: Optional[int] = 0): 27 | new_sequence = copy.deepcopy(iterable_item) 28 | for i in range(starting_index, len(iterable_item) - 1, 2): 29 | new_sequence[i + 1], new_sequence[i] = \ 30 | new_sequence[i], new_sequence[i + 1] 31 | return new_sequence 32 | 33 | 34 | def generate_fswap_pairs(depth: int, dimension: int): 35 | swap_list = [] 36 | for i in range(0, depth): 37 | if i % 2 == 0: 38 | swap_list.append([(i, i + 1) for i in range(0, dimension - 1, 2)]) 39 | else: 40 | swap_list.append([(i, i + 1) for i in range(1, dimension - 1, 2)]) 41 | return swap_list 42 | 43 | 44 | def generate_fswap_unitaries(swap_pairs: List[List[Tuple]], dimension: int): 45 | swap_unitaries = [] 46 | for swap_tuples in swap_pairs: 47 | generator = np.zeros((dimension, dimension), dtype=np.complex128) 48 | for i, j in swap_tuples: 49 | generator[i, i] = -1 50 | generator[j, j] = -1 51 | generator[i, j] = 1 52 | generator[j, i] = 1 53 | swap_unitaries.append(expm(-1j * np.pi * generator / 2)) 54 | return swap_unitaries 55 | -------------------------------------------------------------------------------- /openfermioncirq/experiments/hfvqe/util_test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy as sp 3 | from openfermioncirq.experiments.hfvqe.util import (generate_permutations, 4 | swap_forward, 5 | generate_fswap_pairs, 6 | generate_fswap_unitaries) 7 | 8 | 9 | def test_swap_forward(): 10 | list_to_swap = list(range(6)) 11 | test_swapped_list = swap_forward(list_to_swap, starting_index=0) 12 | assert test_swapped_list == [1, 0, 3, 2, 5, 4] 13 | 14 | test_swapped_list = swap_forward(list_to_swap, starting_index=1) 15 | assert test_swapped_list == [0, 2, 1, 4, 3, 5] 16 | 17 | 18 | def test_generate_fswap_pairs(): 19 | swap_set = generate_fswap_pairs(2, 6) 20 | assert swap_set[0] == [(0, 1), (2, 3), (4, 5)] 21 | assert swap_set[1] == [(1, 2), (3, 4)] 22 | 23 | swap_set = generate_fswap_pairs(1, 4) 24 | assert swap_set[0] == [(0, 1), (2, 3)] 25 | 26 | 27 | def test_gen_fswap_unitaries(): 28 | fswapu = generate_fswap_unitaries([((0, 1), (2, 3))], 4) 29 | true_generator = np.zeros((4, 4), dtype=np.complex128) 30 | true_generator[0, 0], true_generator[1, 1] = -1, -1 31 | true_generator[0, 1], true_generator[1, 0] = 1, 1 32 | true_generator[2, 2], true_generator[3, 3] = -1, -1 33 | true_generator[2, 3], true_generator[3, 2] = 1, 1 34 | true_u = sp.linalg.expm(-1j * np.pi * true_generator / 2) 35 | assert np.allclose(true_u, fswapu[0]) 36 | 37 | 38 | def test_permutation_generator(): 39 | perms = generate_permutations(3) 40 | assert len(perms) == 2 # N//2+1 circuits 41 | assert perms[0] == [0, 1, 2] 42 | assert perms[1] == [1, 2, 0] 43 | 44 | perms = generate_permutations(4) 45 | assert len(perms) == 2 # N/2 circuits 46 | assert perms[0] == [0, 1, 2, 3] 47 | assert perms[1] == [1, 3, 0, 2] 48 | 49 | perms = generate_permutations(6) 50 | assert len(perms) == 3 # N/2 circuits 51 | assert perms[0] == [0, 1, 2, 3, 4, 5] 52 | assert perms[1] == [1, 3, 0, 5, 2, 4] 53 | assert perms[2] == [3, 5, 1, 4, 0, 2] 54 | 55 | perms = generate_permutations(4, no_truncation=True) 56 | assert len(perms) == 5 57 | assert perms[1] == [1, 0, 3, 2] 58 | assert perms[3] == [3, 1, 2, 0] 59 | -------------------------------------------------------------------------------- /openfermioncirq/gates/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | """Gates useful for simulating fermions.""" 13 | 14 | from openfermioncirq.gates.common_gates import ( 15 | FSWAP, 16 | FSwapPowGate, 17 | Rxxyy, 18 | Ryxxy, 19 | Rzz, 20 | rot11, 21 | XXYY, 22 | XXYYPowGate, 23 | YXXY, 24 | YXXYPowGate, 25 | ) 26 | 27 | from openfermioncirq.gates.three_qubit_gates import ( 28 | CRxxyy, 29 | CRyxxy, 30 | CXXYY, 31 | CYXXY, 32 | CXXYYPowGate, 33 | CYXXYPowGate, 34 | rot111, 35 | ) 36 | 37 | from openfermioncirq.gates.fermionic_simulation import ( 38 | fermionic_simulation_gates_from_interaction_operator, 39 | ParityPreservingFermionicGate, 40 | QuadraticFermionicSimulationGate, 41 | CubicFermionicSimulationGate, 42 | QuarticFermionicSimulationGate, 43 | ) 44 | 45 | from openfermioncirq.gates.four_qubit_gates import ( 46 | DoubleExcitation, 47 | DoubleExcitationGate, 48 | ) 49 | 50 | # Deprecated 51 | # pylint: disable=wrong-import-order 52 | import sys as _sys 53 | from openfermioncirq._compat import wrap_module as _wrap_module 54 | _deprecated_constants = { 55 | 'XXYY': ('v0.5.0', 'Use cirq.ISWAP with negated exponent, instead'), 56 | 'YXXY': ('v0.5.0', 'Use cirq.PhasedISwapPowGate, instead.'), 57 | 'CXXYY': ('v0.5.0', 'Use cirq.ControlledGate and cirq.ISWAP with ' 58 | 'negated exponent, instead'), 59 | 'CYXXY': ('v0.5.0', 'Use cirq.ControlledGate and ' 60 | 'cirq.PhasedISwapPowGate, instead.'), 61 | } 62 | _sys.modules[__name__] = _wrap_module(_sys.modules[__name__], 63 | _deprecated_constants) 64 | -------------------------------------------------------------------------------- /openfermioncirq/optimization/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Optimization algorithms and related classes.""" 14 | 15 | from openfermioncirq.optimization.algorithm import ( 16 | OptimizationAlgorithm, 17 | OptimizationParams) 18 | 19 | from openfermioncirq.optimization.black_box import ( 20 | BlackBox, 21 | StatefulBlackBox) 22 | 23 | from openfermioncirq.optimization.result import ( 24 | OptimizationResult, 25 | OptimizationTrialResult) 26 | 27 | from openfermioncirq.optimization.scipy import ( 28 | COBYLA, 29 | L_BFGS_B, 30 | NELDER_MEAD, 31 | SLSQP, 32 | ScipyOptimizationAlgorithm) 33 | -------------------------------------------------------------------------------- /openfermioncirq/optimization/algorithm_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import pytest 15 | 16 | from openfermioncirq.optimization import OptimizationAlgorithm 17 | from openfermioncirq.testing import ExampleAlgorithm, ExampleBlackBox 18 | 19 | 20 | def test_optimization_algorithm_options(): 21 | algorithm = ExampleAlgorithm() 22 | assert algorithm.options == {} 23 | 24 | 25 | def test_optimization_algorithm_optimize(): 26 | black_box = ExampleBlackBox() 27 | algorithm = ExampleAlgorithm() 28 | result = algorithm.optimize(black_box) 29 | 30 | assert isinstance(result.optimal_value, float) 31 | assert isinstance(result.optimal_parameters, numpy.ndarray) 32 | 33 | 34 | def test_optimization_algorithm_name(): 35 | algorithm = ExampleAlgorithm() 36 | assert algorithm.name == 'ExampleAlgorithm' 37 | 38 | 39 | def test_optimization_algorithm_is_abstract_cant_instantiate(): 40 | with pytest.raises(TypeError): 41 | _ = OptimizationAlgorithm() 42 | 43 | 44 | def test_optimization_algorithm_is_abstract_must_implement(): 45 | class Missing(OptimizationAlgorithm): 46 | pass 47 | 48 | with pytest.raises(TypeError): 49 | _ = Missing() 50 | 51 | 52 | def test_optimization_algorithm_is_abstract_can_implement(): 53 | class Included(OptimizationAlgorithm): 54 | def optimize(self): 55 | pass 56 | 57 | assert isinstance(Included(), OptimizationAlgorithm) 58 | -------------------------------------------------------------------------------- /openfermioncirq/optimization/scipy.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """A wrapper around the local optimization routines implemented in Scipy.""" 14 | 15 | from typing import Dict, Optional 16 | 17 | import numpy 18 | import scipy.optimize 19 | 20 | from openfermioncirq.optimization import (BlackBox, 21 | OptimizationResult, 22 | OptimizationAlgorithm) 23 | 24 | 25 | class ScipyOptimizationAlgorithm(OptimizationAlgorithm): 26 | """An optimization algorithm from the scipy.optimize module.""" 27 | 28 | def __init__(self, 29 | options: Optional[Dict]=None, 30 | kwargs: Optional[Dict]=None, 31 | uses_bounds: bool=True) -> None: 32 | """ 33 | Args: 34 | options: The `options` dictionary passed to scipy.optimize.minimize. 35 | kwargs: Other keyword arguments passed to scipy.optimize.minimize. 36 | This should NOT include the `bounds` or `options` keyword 37 | arguments. 38 | uses_bounds: Whether the algorithm uses bounds on the input 39 | variables. Set this to False to prevent scipy.optimize.minimize 40 | from raising a warning if the chosen method does not use bounds. 41 | """ 42 | self.kwargs = kwargs or {} 43 | self.uses_bounds = uses_bounds 44 | super().__init__(options) 45 | 46 | def optimize(self, 47 | black_box: BlackBox, 48 | initial_guess: Optional[numpy.ndarray]=None, 49 | initial_guess_array: Optional[numpy.ndarray]=None 50 | ) -> OptimizationResult: 51 | if initial_guess is None: 52 | raise ValueError('The chosen optimization algorithm requires an ' 53 | 'initial guess.') 54 | bounds = black_box.bounds if self.uses_bounds else None 55 | result = scipy.optimize.minimize(black_box.evaluate, 56 | initial_guess, 57 | bounds=bounds, 58 | options=self.options, 59 | **self.kwargs) 60 | return OptimizationResult(optimal_value=result.fun, 61 | optimal_parameters=result.x, 62 | num_evaluations=result.nfev, 63 | status=result.status, 64 | message=result.message) 65 | 66 | @property 67 | def name(self) -> str: 68 | return self.kwargs.get('method', 'ScipyOptimizationAlgorithm') 69 | 70 | 71 | COBYLA = ScipyOptimizationAlgorithm( 72 | kwargs={'method': 'COBYLA'}, 73 | uses_bounds=False) 74 | 75 | L_BFGS_B = ScipyOptimizationAlgorithm( 76 | kwargs={'method': 'L-BFGS-B'}) 77 | 78 | NELDER_MEAD = ScipyOptimizationAlgorithm( 79 | kwargs={'method': 'Nelder-Mead'}, 80 | uses_bounds=False) 81 | 82 | SLSQP = ScipyOptimizationAlgorithm( 83 | kwargs={'method': 'SLSQP'}) 84 | -------------------------------------------------------------------------------- /openfermioncirq/optimization/scipy_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import pytest 15 | 16 | from openfermioncirq.optimization.scipy import ( 17 | COBYLA, 18 | L_BFGS_B, 19 | NELDER_MEAD, 20 | SLSQP, 21 | ScipyOptimizationAlgorithm) 22 | from openfermioncirq.testing import ExampleBlackBox 23 | 24 | 25 | @pytest.mark.parametrize('algorithm', [COBYLA, L_BFGS_B, NELDER_MEAD, SLSQP]) 26 | def test_scipy_algorithm(algorithm): 27 | black_box = ExampleBlackBox() 28 | initial_guess = numpy.zeros(black_box.dimension) 29 | result = algorithm.optimize(black_box, initial_guess) 30 | 31 | assert isinstance(result.optimal_value, float) 32 | assert isinstance(result.optimal_parameters, numpy.ndarray) 33 | assert isinstance(result.num_evaluations, int) 34 | assert isinstance(result.status, int) 35 | assert isinstance(result.message, (str, bytes)) 36 | 37 | 38 | def test_scipy_algorithm_requires_initial_guess(): 39 | black_box = ExampleBlackBox() 40 | with pytest.raises(ValueError): 41 | _ = COBYLA.optimize(black_box) 42 | 43 | def test_scipy_algorithm_name(): 44 | assert ScipyOptimizationAlgorithm().name == 'ScipyOptimizationAlgorithm' 45 | assert COBYLA.name == 'COBYLA' 46 | assert L_BFGS_B.name == 'L-BFGS-B' 47 | assert NELDER_MEAD.name == 'Nelder-Mead' 48 | assert SLSQP.name == 'SLSQP' 49 | -------------------------------------------------------------------------------- /openfermioncirq/primitives/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Building blocks of algorithms for quantum simulation.""" 14 | 15 | from openfermioncirq.primitives.bogoliubov_transform import bogoliubov_transform 16 | 17 | from openfermioncirq.primitives.ffft import ffft 18 | 19 | from openfermioncirq.primitives.optimal_givens_decomposition import ( 20 | optimal_givens_decomposition) 21 | 22 | from openfermioncirq.primitives.state_preparation import ( 23 | prepare_gaussian_state, 24 | prepare_slater_determinant) 25 | 26 | from openfermioncirq.primitives.swap_network import swap_network 27 | -------------------------------------------------------------------------------- /openfermioncirq/primitives/swap_network_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import cirq 14 | 15 | from openfermioncirq import swap_network 16 | 17 | 18 | def test_swap_network(): 19 | n_qubits = 4 20 | qubits = cirq.LineQubit.range(n_qubits) 21 | 22 | circuit = cirq.Circuit( 23 | swap_network(qubits, lambda i, j, q0, q1: cirq.ISWAP(q0, q1)**-1)) 24 | cirq.testing.assert_has_diagram(circuit, """ 25 | 0: ───iSwap──────×──────────────────iSwap──────×────────────────── 26 | │ │ │ │ 27 | 1: ───iSwap^-1───×───iSwap──────×───iSwap^-1───×───iSwap──────×─── 28 | │ │ │ │ 29 | 2: ───iSwap──────×───iSwap^-1───×───iSwap──────×───iSwap^-1───×─── 30 | │ │ │ │ 31 | 3: ───iSwap^-1───×──────────────────iSwap^-1───×────────────────── 32 | """) 33 | 34 | circuit = cirq.Circuit( 35 | swap_network(qubits, lambda i, j, q0, q1: cirq.ISWAP(q0, q1)**-1, 36 | fermionic=True, offset=True)) 37 | cirq.testing.assert_has_diagram(circuit, """ 38 | 0 1 2 3 39 | │ │ │ │ 40 | │ iSwap────iSwap^-1 │ 41 | │ │ │ │ 42 | │ ×ᶠ───────×ᶠ │ 43 | │ │ │ │ 44 | iSwap─iSwap^-1 iSwap────iSwap^-1 45 | │ │ │ │ 46 | ×ᶠ────×ᶠ ×ᶠ───────×ᶠ 47 | │ │ │ │ 48 | │ iSwap────iSwap^-1 │ 49 | │ │ │ │ 50 | │ ×ᶠ───────×ᶠ │ 51 | │ │ │ │ 52 | iSwap─iSwap^-1 iSwap────iSwap^-1 53 | │ │ │ │ 54 | ×ᶠ────×ᶠ ×ᶠ───────×ᶠ 55 | │ │ │ │ 56 | """, transpose=True) 57 | 58 | n_qubits = 5 59 | qubits = cirq.LineQubit.range(n_qubits) 60 | 61 | circuit = cirq.Circuit( 62 | swap_network(qubits, lambda i, j, q0, q1: (), 63 | fermionic=True), 64 | strategy=cirq.InsertStrategy.EARLIEST) 65 | cirq.testing.assert_has_diagram(circuit, """ 66 | 0: ───×ᶠ────────×ᶠ────────×ᶠ─── 67 | │ │ │ 68 | 1: ───×ᶠ───×ᶠ───×ᶠ───×ᶠ───×ᶠ─── 69 | │ │ 70 | 2: ───×ᶠ───×ᶠ───×ᶠ───×ᶠ───×ᶠ─── 71 | │ │ │ 72 | 3: ───×ᶠ───×ᶠ───×ᶠ───×ᶠ───×ᶠ─── 73 | │ │ 74 | 4: ────────×ᶠ────────×ᶠ──────── 75 | """) 76 | 77 | circuit = cirq.Circuit( 78 | swap_network(qubits, lambda i, j, q0, q1: (), 79 | offset=True), 80 | strategy=cirq.InsertStrategy.EARLIEST) 81 | cirq.testing.assert_has_diagram(circuit, """ 82 | 0 1 2 3 4 83 | │ │ │ │ │ 84 | │ ×─× ×─× 85 | │ │ │ │ │ 86 | ×─× ×─× │ 87 | │ │ │ │ │ 88 | │ ×─× ×─× 89 | │ │ │ │ │ 90 | ×─× ×─× │ 91 | │ │ │ │ │ 92 | │ ×─× ×─× 93 | │ │ │ │ │ 94 | """, transpose=True) 95 | 96 | 97 | def test_reusable(): 98 | ops = swap_network(cirq.LineQubit.range(5)) 99 | assert list(ops) == list(ops) 100 | -------------------------------------------------------------------------------- /openfermioncirq/testing/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | from openfermioncirq.testing.example_classes import ( 14 | ExampleAlgorithm, 15 | ExampleAnsatz, 16 | ExampleBlackBox, 17 | ExampleBlackBoxNoisy, 18 | ExampleStatefulBlackBox, 19 | ExampleVariationalObjective, 20 | ExampleVariationalObjectiveNoisy, 21 | LazyAlgorithm, 22 | ) 23 | 24 | from openfermioncirq.testing.random import ( 25 | random_interaction_operator_term, 26 | ) 27 | 28 | from openfermioncirq.testing.wrapped import ( 29 | assert_eigengate_implements_consistent_protocols, 30 | assert_equivalent_repr, 31 | assert_implements_consistent_protocols, 32 | ) 33 | -------------------------------------------------------------------------------- /openfermioncirq/testing/random.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import itertools 14 | from typing import Optional 15 | 16 | import openfermion 17 | from openfermion.utils._testing_utils import random_interaction_operator 18 | 19 | 20 | def random_interaction_operator_term( 21 | order: int, 22 | real: bool = True, 23 | seed: Optional[int] = None, 24 | ) -> openfermion.InteractionOperator: 25 | """Generates a random interaction operator with non-zero coefficients only 26 | on terms corresponding to the given number of unique orbitals. 27 | 28 | The number of orbitals is equal to the given order. 29 | 30 | Args: 31 | order: How many unique orbitals the non-zero terms should correspond to. 32 | real: Whether or not the coefficients should be real. Defaults to True. 33 | seed: The seed. If None (default), uses np.random. 34 | """ 35 | 36 | n_orbitals = order 37 | 38 | if order > 4: 39 | return openfermion.InteractionOperator.zero(order) 40 | 41 | operator = random_interaction_operator(n_orbitals, real=real, seed=seed) 42 | operator.constant = 0 43 | 44 | for indices in itertools.product(range(n_orbitals), repeat=2): 45 | if len(set(indices)) != order: 46 | operator.one_body_tensor[indices] = 0 47 | 48 | for indices in itertools.product(range(n_orbitals), repeat=4): 49 | if len(set(indices)) != order: 50 | operator.two_body_tensor[indices] = 0 51 | 52 | return operator 53 | -------------------------------------------------------------------------------- /openfermioncirq/testing/random_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import random 14 | 15 | import numpy as np 16 | import openfermion 17 | import pytest 18 | 19 | import openfermioncirq.testing.random as ofctr 20 | 21 | 22 | @pytest.mark.parametrize('order,real,seed', [(k, r, random.randrange(2<<30)) 23 | for k in [1, 2, 3, 4, 5] for r in [0, 1] for _ in range(5)]) 24 | def test_random_interaction_operator_term(order, real, seed): 25 | op = ofctr.random_interaction_operator_term(order, real, seed) 26 | 27 | assert openfermion.is_hermitian(op) 28 | 29 | assert op.constant == 0 30 | assert op.one_body_tensor.shape == (order,) * 2 31 | assert op.two_body_tensor.shape == (order,) * 4 32 | 33 | for tensor in (op.one_body_tensor, op.two_body_tensor): 34 | for indices in np.argwhere(tensor): 35 | assert len(set(indices)) == order 36 | 37 | op_2 = ofctr.random_interaction_operator_term(order, real, seed) 38 | assert op == op_2 39 | 40 | if order == 1: 41 | assert op.one_body_tensor != 0 42 | assert op.two_body_tensor != 0 43 | elif order == 2: 44 | assert np.all((op.one_body_tensor == 0) == np.eye(2)) 45 | elif order == 3: 46 | assert np.all(op.one_body_tensor == 0) 47 | elif order == 4: 48 | assert np.all(op.one_body_tensor == 0) 49 | else: 50 | assert np.all(op.one_body_tensor == 0) 51 | assert np.all(op.two_body_tensor == 0) 52 | -------------------------------------------------------------------------------- /openfermioncirq/testing/wrapped.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | from typing import Any, Dict, Optional, Sequence, Type, Union 15 | 16 | import sympy 17 | 18 | import cirq 19 | 20 | 21 | _setup_code = ('import cirq\n' 22 | 'import numpy as np\n' 23 | 'import sympy\n' 24 | 'import openfermioncirq as ofc\n' 25 | 'import openfermion as of\n') 26 | 27 | 28 | def assert_equivalent_repr( 29 | value: Any, 30 | *, 31 | setup_code: str = _setup_code) -> None: 32 | """Checks that eval(repr(v)) == v. 33 | 34 | Args: 35 | value: A value whose repr should be evaluatable python 36 | code that produces an equivalent value. 37 | setup_code: Code that must be executed before the repr can be evaluated. 38 | Ideally this should just be a series of 'import' lines. 39 | """ 40 | cirq.testing.assert_equivalent_repr(value, setup_code=setup_code) 41 | 42 | 43 | def assert_implements_consistent_protocols( 44 | val: Any, 45 | *, 46 | exponents: Sequence[Any] = ( 47 | 0, 1, -1, 0.5, 0.25, -0.5, 0.1, sympy.Symbol('s')), 48 | qubit_count: Optional[int] = None, 49 | ignoring_global_phase: bool=False, 50 | setup_code: str = _setup_code, 51 | global_vals: Optional[Dict[str, Any]] = None, 52 | local_vals: Optional[Dict[str, Any]] = None 53 | ) -> None: 54 | """Checks that a value is internally consistent and has a good __repr__.""" 55 | 56 | cirq.testing.assert_implements_consistent_protocols( 57 | val, 58 | exponents=exponents, 59 | qubit_count=qubit_count, 60 | ignoring_global_phase=ignoring_global_phase, 61 | setup_code=setup_code, 62 | global_vals=global_vals, 63 | local_vals=local_vals) 64 | 65 | 66 | def assert_eigengate_implements_consistent_protocols( 67 | eigen_gate_type: Type[cirq.EigenGate], 68 | *, 69 | exponents: Sequence[Union[sympy.Basic, float]] = ( 70 | 0, 1, -1, 0.25, -0.5, 0.1, sympy.Symbol('s')), 71 | global_shifts: Sequence[float] = (0, -0.5, 0.1), 72 | qubit_count: Optional[int] = None, 73 | ignoring_global_phase: bool=False, 74 | setup_code: str = _setup_code, 75 | global_vals: Optional[Dict[str, Any]] = None, 76 | local_vals: Optional[Dict[str, Any]] = None) -> None: 77 | """Checks that an EigenGate subclass is internally consistent and has a 78 | good __repr__.""" 79 | 80 | cirq.testing.assert_eigengate_implements_consistent_protocols( 81 | eigen_gate_type, 82 | exponents=exponents, 83 | global_shifts=global_shifts, 84 | qubit_count=qubit_count, 85 | ignoring_global_phase=ignoring_global_phase, 86 | setup_code=setup_code, 87 | global_vals=global_vals, 88 | local_vals=local_vals) 89 | -------------------------------------------------------------------------------- /openfermioncirq/trotter/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Hamiltonian simulation via Trotter-Suzuki product formulas.""" 14 | 15 | from openfermioncirq.trotter.simulate_trotter import simulate_trotter 16 | 17 | from openfermioncirq.trotter.algorithms import ( 18 | LINEAR_SWAP_NETWORK, 19 | LinearSwapNetworkTrotterAlgorithm, 20 | LOW_RANK, 21 | LowRankTrotterAlgorithm, 22 | SPLIT_OPERATOR, 23 | SplitOperatorTrotterAlgorithm) 24 | 25 | from openfermioncirq.trotter.trotter_algorithm import ( 26 | TrotterStep, 27 | TrotterAlgorithm) 28 | -------------------------------------------------------------------------------- /openfermioncirq/trotter/algorithms/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Algorithms for performing Trotter steps.""" 14 | 15 | from openfermioncirq.trotter.algorithms.linear_swap_network import ( 16 | LINEAR_SWAP_NETWORK, 17 | LinearSwapNetworkTrotterAlgorithm) 18 | 19 | from openfermioncirq.trotter.algorithms.low_rank import ( 20 | LOW_RANK, 21 | LowRankTrotterAlgorithm) 22 | 23 | from openfermioncirq.trotter.algorithms.split_operator import ( 24 | SPLIT_OPERATOR, 25 | SplitOperatorTrotterAlgorithm) 26 | -------------------------------------------------------------------------------- /openfermioncirq/trotter/trotter_algorithm_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | from openfermion import FermionOperator 14 | 15 | import pytest 16 | 17 | from openfermioncirq.trotter import TrotterStep 18 | 19 | 20 | def test_trotter_algorithm_is_abstract_cant_instantiate(): 21 | with pytest.raises(TypeError): 22 | _ = TrotterStep(FermionOperator()) 23 | 24 | 25 | def test_trotter_algorithm_is_abstract_must_implement(): 26 | class Missing(TrotterStep): 27 | pass 28 | 29 | with pytest.raises(TypeError): 30 | _ = Missing(FermionOperator()) 31 | 32 | 33 | def test_trotter_algorithm_is_abstract_can_implement(): 34 | class Included(TrotterStep): 35 | def trotter_step(self, qubits, time, control_qubit): 36 | pass 37 | 38 | assert isinstance(Included(FermionOperator()), TrotterStep) 39 | -------------------------------------------------------------------------------- /openfermioncirq/variational/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Types for constructing and optimizing variational quantum algorithms.""" 14 | 15 | from openfermioncirq.variational.ansatz import VariationalAnsatz 16 | 17 | from openfermioncirq.variational.ansatzes import ( 18 | LowRankTrotterAnsatz, 19 | SplitOperatorTrotterAnsatz, 20 | SwapNetworkTrotterAnsatz, 21 | SwapNetworkTrotterHubbardAnsatz) 22 | 23 | from openfermioncirq.variational.hamiltonian_objective import ( 24 | HamiltonianObjective) 25 | 26 | from openfermioncirq.variational.objective import VariationalObjective 27 | 28 | from openfermioncirq.variational.study import VariationalStudy 29 | -------------------------------------------------------------------------------- /openfermioncirq/variational/ansatz_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import pytest 15 | 16 | from openfermioncirq import VariationalAnsatz 17 | from openfermioncirq.testing import ExampleAnsatz 18 | 19 | 20 | def test_variational_ansatz_circuit(): 21 | ansatz = ExampleAnsatz() 22 | assert ansatz.circuit.to_text_diagram().strip() == """ 23 | 0: ───X^theta0───@───X^theta0───M('all')─── 24 | │ │ 25 | 1: ───X^theta1───@───X^theta1───M────────── 26 | """.strip() 27 | 28 | 29 | def test_variational_ansatz_param_bounds(): 30 | ansatz = ExampleAnsatz() 31 | assert ansatz.param_bounds() is None 32 | 33 | 34 | def test_variational_ansatz_param_resolver(): 35 | ansatz = ExampleAnsatz() 36 | resolver = ansatz.param_resolver(numpy.arange(2, dtype=float)) 37 | assert resolver['theta0'] == 0 38 | assert resolver['theta1'] == 1 39 | 40 | 41 | def test_variational_ansatz_default_initial_params(): 42 | ansatz = ExampleAnsatz() 43 | numpy.testing.assert_allclose(ansatz.default_initial_params(), 44 | numpy.zeros(len(list(ansatz.params())))) 45 | 46 | 47 | def test_variational_ansatz_is_abstract_cant_instantiate(): 48 | with pytest.raises(TypeError): 49 | _ = VariationalAnsatz() 50 | 51 | 52 | def test_variational_ansatz_is_abstract_must_implement(): 53 | class Missing1(VariationalAnsatz): 54 | def params(self): 55 | return [] # coverage: ignore 56 | def _generate_qubits(self): 57 | pass 58 | class Missing2(VariationalAnsatz): 59 | def _generate_qubits(self): 60 | pass 61 | def operations(self, qubits): 62 | pass 63 | class Missing3(VariationalAnsatz): 64 | def operations(self, qubits): 65 | pass 66 | def params(self): 67 | return [] # coverage: ignore 68 | 69 | with pytest.raises(TypeError): 70 | _ = Missing1() 71 | with pytest.raises(TypeError): 72 | _ = Missing2() 73 | with pytest.raises(TypeError): 74 | _ = Missing3() 75 | 76 | 77 | def test_variational_ansatz_is_abstract_can_implement(): 78 | class Included(VariationalAnsatz): 79 | def params(self): 80 | return [] # coverage: ignore 81 | def _generate_qubits(self): 82 | pass 83 | def operations(self, qubits): 84 | return () 85 | 86 | assert isinstance(Included(), VariationalAnsatz) 87 | -------------------------------------------------------------------------------- /openfermioncirq/variational/ansatzes/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | """Variational ansatzes.""" 14 | 15 | from openfermioncirq.variational.ansatzes.low_rank import LowRankTrotterAnsatz 16 | 17 | from openfermioncirq.variational.ansatzes.split_operator_trotter import ( 18 | SplitOperatorTrotterAnsatz) 19 | 20 | from openfermioncirq.variational.ansatzes.swap_network_trotter import ( 21 | SwapNetworkTrotterAnsatz) 22 | 23 | from openfermioncirq.variational.ansatzes.swap_network_trotter_hubbard import ( 24 | SwapNetworkTrotterHubbardAnsatz) 25 | -------------------------------------------------------------------------------- /openfermioncirq/variational/ansatzes/low_rank_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import sympy 14 | 15 | import openfermion 16 | 17 | from openfermioncirq.variational.ansatzes import LowRankTrotterAnsatz 18 | 19 | 20 | # 4-qubit LiH 2-2 with bond length 1.45 21 | bond_length = 1.45 22 | geometry = [('Li', (0., 0., 0.)), ('H', (0., 0., bond_length))] 23 | lih_hamiltonian = openfermion.load_molecular_hamiltonian( 24 | geometry, 'sto-3g', 1, format(bond_length), 2, 2) 25 | 26 | 27 | def test_low_rank_trotter_ansatz_params(): 28 | 29 | n = openfermion.count_qubits(lih_hamiltonian) 30 | final_rank = 2 31 | ansatz = LowRankTrotterAnsatz( 32 | lih_hamiltonian, 33 | final_rank=final_rank, 34 | include_all_cz=True, 35 | include_all_z=True) 36 | assert len(list(ansatz.params())) == n + final_rank*(n + n*(n-1)//2) 37 | 38 | ansatz = LowRankTrotterAnsatz(lih_hamiltonian, final_rank=2) 39 | assert set(ansatz.params()) == { 40 | sympy.Symbol(name) for name in { 41 | 'U_0_0', 'U_0_0_0', 'U_0_1_0', 'U_1_0', 42 | 'U_1_0_0', 'U_1_1_0', 'U_2_0', 'U_2_0_0', 43 | 'U_2_1_0', 'U_3_0', 'U_3_0_0', 'U_3_1_0', 44 | 'V_0_1_0_0', 'V_0_1_1_0', 'V_0_2_0_0', 'V_0_2_1_0', 45 | 'V_0_3_0_0', 'V_0_3_1_0', 'V_1_2_0_0', 'V_1_2_1_0', 46 | 'V_1_3_0_0', 'V_1_3_1_0', 'V_2_3_0_0', 'V_2_3_1_0' 47 | } 48 | } 49 | 50 | 51 | def test_low_rank_trotter_ansatz_param_bounds(): 52 | 53 | ansatz = LowRankTrotterAnsatz(lih_hamiltonian, final_rank=2) 54 | assert ansatz.param_bounds() == [(-1.0, 1.0)] * len(list(ansatz.params())) 55 | 56 | 57 | def test_swap_network_trotter_ansatz_default_initial_params_length(): 58 | 59 | ansatz = LowRankTrotterAnsatz(lih_hamiltonian) 60 | assert len(ansatz.default_initial_params()) == len(list(ansatz.params())) 61 | -------------------------------------------------------------------------------- /openfermioncirq/variational/ansatzes/split_operator_trotter_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import sympy 15 | 16 | import openfermion 17 | 18 | from openfermioncirq.variational.ansatzes import SplitOperatorTrotterAnsatz 19 | 20 | 21 | # Construct a Hubbard model Hamiltonian 22 | hubbard_model = openfermion.fermi_hubbard(2, 2, 1., 4.) 23 | hubbard_hamiltonian = openfermion.get_diagonal_coulomb_hamiltonian( 24 | hubbard_model) 25 | 26 | # Construct a jellium model Hamiltonian 27 | grid = openfermion.Grid(2, 2, 1.0) 28 | jellium = openfermion.jellium_model(grid, spinless=True, plane_wave=False) 29 | jellium_hamiltonian = openfermion.get_diagonal_coulomb_hamiltonian(jellium) 30 | 31 | # Construct a Hamiltonian of ones 32 | ones_hamiltonian = openfermion.DiagonalCoulombHamiltonian( 33 | one_body=numpy.ones((5, 5)), 34 | two_body=numpy.ones((5, 5))) 35 | 36 | 37 | def test_split_operator_trotter_ansatz_params(): 38 | 39 | ansatz = SplitOperatorTrotterAnsatz(hubbard_hamiltonian) 40 | assert (set(ansatz.params()) == 41 | {sympy.Symbol(name) for name in 42 | {'U_0_0', 'U_1_0', 'U_6_0', 'U_7_0', 43 | 'V_0_1_0', 'V_2_3_0', 'V_4_5_0', 'V_6_7_0'}}) 44 | 45 | ansatz = SplitOperatorTrotterAnsatz(hubbard_hamiltonian, iterations=2) 46 | assert (set(ansatz.params()) == 47 | {sympy.Symbol(name) for name in 48 | {'U_0_0', 'U_1_0', 'U_6_0', 'U_7_0', 49 | 'V_0_1_0', 'V_2_3_0', 'V_4_5_0', 'V_6_7_0', 50 | 'U_0_1', 'U_1_1', 'U_6_1', 'U_7_1', 51 | 'V_0_1_1', 'V_2_3_1', 'V_4_5_1', 'V_6_7_1'}}) 52 | 53 | 54 | def test_split_operator_trotter_ansatz_param_bounds(): 55 | 56 | ansatz = SplitOperatorTrotterAnsatz(hubbard_hamiltonian) 57 | assert list(symbol.name for symbol in ansatz.params()) == [ 58 | 'U_0_0', 'U_1_0', 'U_6_0', 'U_7_0', 59 | 'V_0_1_0', 'V_2_3_0', 'V_4_5_0', 'V_6_7_0'] 60 | assert ansatz.param_bounds() == [ 61 | (-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0), 62 | (-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0)] 63 | 64 | 65 | def test_split_operator_trotter_ansatz_default_initial_params_length(): 66 | 67 | ansatz = SplitOperatorTrotterAnsatz(hubbard_hamiltonian) 68 | assert len(ansatz.default_initial_params()) == len(list(ansatz.params())) 69 | -------------------------------------------------------------------------------- /openfermioncirq/variational/ansatzes/swap_network_trotter_hubbard_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | from openfermioncirq.variational.ansatzes import SwapNetworkTrotterHubbardAnsatz 15 | 16 | 17 | def test_swap_network_trotter_hubbard_ansatz_param_bounds(): 18 | ansatz = SwapNetworkTrotterHubbardAnsatz(3, 1, 1.0, 4.0, periodic=False) 19 | assert list(symbol.name for symbol in ansatz.params()) == [ 20 | 'Th_0', 'V_0',] 21 | assert ansatz.param_bounds() == [ 22 | (-2.0, 2.0), (-1.0, 1.0)] 23 | 24 | ansatz = SwapNetworkTrotterHubbardAnsatz(1, 4, 1.0, 4.0, periodic=False) 25 | assert list(symbol.name for symbol in ansatz.params()) == [ 26 | 'Tv_0', 'V_0',] 27 | assert ansatz.param_bounds() == [ 28 | (-2.0, 2.0), (-1.0, 1.0)] 29 | 30 | ansatz = SwapNetworkTrotterHubbardAnsatz(3, 2, 1.0, 4.0) 31 | assert list(symbol.name for symbol in ansatz.params()) == [ 32 | 'Th_0', 'Tv_0', 'V_0',] 33 | assert ansatz.param_bounds() == [ 34 | (-2.0, 2.0), (-2.0, 2.0), (-1.0, 1.0)] 35 | -------------------------------------------------------------------------------- /openfermioncirq/variational/ansatzes/swap_network_trotter_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import sympy 15 | 16 | import openfermion 17 | 18 | from openfermioncirq.variational.ansatzes import SwapNetworkTrotterAnsatz 19 | 20 | 21 | # Construct a Hubbard model Hamiltonian 22 | hubbard_model = openfermion.fermi_hubbard(2, 2, 1., 4.) 23 | hubbard_hamiltonian = openfermion.get_diagonal_coulomb_hamiltonian( 24 | hubbard_model) 25 | 26 | # Construct an empty Hamiltonian 27 | zero_hamiltonian = openfermion.DiagonalCoulombHamiltonian( 28 | one_body=numpy.zeros((4, 4)), 29 | two_body=numpy.zeros((4, 4))) 30 | 31 | 32 | def test_swap_network_trotter_ansatz_params(): 33 | 34 | ansatz = SwapNetworkTrotterAnsatz(hubbard_hamiltonian) 35 | assert (set(ansatz.params()) == 36 | {sympy.Symbol(name) for name in 37 | {'T_0_2_0', 'T_4_6_0', 'T_1_3_0', 'T_5_7_0', 38 | 'T_0_4_0', 'T_2_6_0', 'T_1_5_0', 'T_3_7_0', 39 | 'V_0_1_0', 'V_2_3_0', 'V_4_5_0', 'V_6_7_0'}}) 40 | 41 | ansatz = SwapNetworkTrotterAnsatz(hubbard_hamiltonian, iterations=2) 42 | assert (set(ansatz.params()) == 43 | {sympy.Symbol(name) for name in 44 | {'T_0_2_0', 'T_4_6_0', 'T_1_3_0', 'T_5_7_0', 45 | 'T_0_4_0', 'T_2_6_0', 'T_1_5_0', 'T_3_7_0', 46 | 'V_0_1_0', 'V_2_3_0', 'V_4_5_0', 'V_6_7_0', 47 | 'T_0_2_1', 'T_4_6_1', 'T_1_3_1', 'T_5_7_1', 48 | 'T_0_4_1', 'T_2_6_1', 'T_1_5_1', 'T_3_7_1', 49 | 'V_0_1_1', 'V_2_3_1', 'V_4_5_1', 'V_6_7_1'}}) 50 | 51 | 52 | def test_swap_network_trotter_ansatz_param_bounds(): 53 | 54 | ansatz = SwapNetworkTrotterAnsatz(hubbard_hamiltonian) 55 | assert list(symbol.name for symbol in ansatz.params()) == [ 56 | 'V_0_1_0', 'T_0_2_0', 'T_0_4_0', 'T_1_3_0', 57 | 'T_1_5_0', 'V_2_3_0', 'T_2_6_0', 'T_3_7_0', 58 | 'V_4_5_0', 'T_4_6_0', 'T_5_7_0', 'V_6_7_0'] 59 | assert ansatz.param_bounds() == [ 60 | (-1.0, 1.0), (-2.0, 2.0), (-2.0, 2.0), (-2.0, 2.0), 61 | (-2.0, 2.0), (-1.0, 1.0), (-2.0, 2.0), (-2.0, 2.0), 62 | (-1.0, 1.0), (-2.0, 2.0), (-2.0, 2.0), (-1.0, 1.0)] 63 | 64 | 65 | def test_swap_network_trotter_ansatz_default_initial_params_length(): 66 | 67 | ansatz = SwapNetworkTrotterAnsatz(hubbard_hamiltonian, 68 | include_all_yxxy=True, 69 | include_all_z=True) 70 | assert len(ansatz.default_initial_params()) == len(list(ansatz.params())) 71 | -------------------------------------------------------------------------------- /openfermioncirq/variational/hamiltonian_objective_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import cirq 15 | import openfermion 16 | from openfermion import random_diagonal_coulomb_hamiltonian 17 | import pytest 18 | 19 | from openfermioncirq import HamiltonianObjective 20 | 21 | 22 | # Construct a Hamiltonian for testing 23 | test_hamiltonian = random_diagonal_coulomb_hamiltonian(4, real=True, seed=26191) 24 | test_fermion_op = openfermion.get_fermion_operator(test_hamiltonian) 25 | 26 | 27 | def test_hamiltonian_objective_value(): 28 | 29 | obj = HamiltonianObjective(test_hamiltonian) 30 | obj_linear_op = HamiltonianObjective(test_hamiltonian, use_linear_op=True) 31 | hamiltonian_sparse = openfermion.get_sparse_operator(test_hamiltonian) 32 | 33 | simulator = cirq.Simulator() 34 | qubits = cirq.LineQubit.range(4) 35 | numpy.random.seed(10581) 36 | result = simulator.simulate( 37 | cirq.testing.random_circuit(qubits, 5, 0.8), 38 | qubit_order=qubits) 39 | correct_val = openfermion.expectation(hamiltonian_sparse, 40 | result.final_state) 41 | 42 | numpy.testing.assert_allclose( 43 | obj.value(result), correct_val, atol=1e-5) 44 | numpy.testing.assert_allclose( 45 | obj.value(result.final_state), correct_val, 1e-5) 46 | numpy.testing.assert_allclose( 47 | obj_linear_op.value(result), correct_val, 1e-5) 48 | numpy.testing.assert_allclose( 49 | obj_linear_op.value(result.final_state), correct_val, 1e-5) 50 | 51 | 52 | def test_hamiltonian_objective_noise(): 53 | 54 | obj = HamiltonianObjective(test_hamiltonian) 55 | 56 | numpy.random.seed(10821) 57 | assert (abs(obj.noise()) < abs(obj.noise(1e6)) < abs(obj.noise(1e5)) < 58 | abs(obj.noise(1e4)) < abs(obj.noise(1e3))) 59 | 60 | 61 | def test_hamiltonian_objective_noise_bounds(): 62 | 63 | obj = HamiltonianObjective(test_hamiltonian) 64 | 65 | numpy.random.seed(38017) 66 | 67 | a, b = obj.noise_bounds(1e4) 68 | c, d = obj.noise_bounds(1e2) 69 | 70 | numpy.testing.assert_allclose(10 * a, c) 71 | numpy.testing.assert_allclose(10 * b, d) 72 | 73 | a, b = obj.noise_bounds(1e4, confidence=0.95) 74 | c, d = obj.noise_bounds(1e2, confidence=0.95) 75 | 76 | numpy.testing.assert_allclose(10 * a, c) 77 | numpy.testing.assert_allclose(10 * b, d) 78 | 79 | numpy.testing.assert_allclose(obj.noise_bounds(1e2), 80 | obj.noise_bounds(1e2, 0.99)) 81 | 82 | with pytest.raises(ValueError): 83 | _ = obj.noise_bounds(1.0, 1.0) 84 | 85 | with pytest.raises(ValueError): 86 | _ = obj.noise_bounds(1.0, -1.0) 87 | 88 | 89 | def test_hamiltonian_objective_value_not_implemented(): 90 | obj = HamiltonianObjective(test_hamiltonian) 91 | trial_result = cirq.TrialResult( 92 | params=cirq.ParamResolver({}), 93 | measurements={}) 94 | with pytest.raises(NotImplementedError): 95 | _ = obj.value(trial_result) 96 | 97 | 98 | def test_hamiltonian_objective_init_qubit_operator(): 99 | 100 | obj = HamiltonianObjective(openfermion.QubitOperator((0, 'X'))) 101 | assert obj.hamiltonian == openfermion.QubitOperator((0, 'X')) 102 | -------------------------------------------------------------------------------- /openfermioncirq/variational/letter_with_subscripts.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | from typing import Union 14 | 15 | import sympy 16 | 17 | 18 | def _name(letter: str, *subscripts: Union[str, int]) -> str: 19 | return letter + ''.join('_{}'.format(subscript) 20 | for subscript in subscripts) 21 | 22 | 23 | class LetterWithSubscripts(sympy.Symbol): 24 | 25 | def __new__(cls, letter: str, *subscripts: Union[str, int]): 26 | return super().__new__(cls, _name(letter, *subscripts)) 27 | 28 | def __init__(self, 29 | letter: str, 30 | *subscripts: Union[str, int]) -> None: 31 | self.letter = letter 32 | self.subscripts = subscripts 33 | super().__init__() 34 | 35 | def __eq__(self, other): 36 | if not isinstance(other, sympy.Symbol): 37 | return NotImplemented 38 | return str(self) == str(other) 39 | 40 | def __ne__(self, other): 41 | return not self == other 42 | 43 | def __hash__(self): 44 | return hash(sympy.Symbol(str(self))) 45 | 46 | def __repr__(self): 47 | return ( 48 | 'ofc.variational.letter_with_subscripts.' 49 | 'LetterWithSubscripts({!r}, {})'.format( 50 | self.letter, 51 | ', '.join(str(e) for e in self.subscripts))) 52 | 53 | def _subs(self, old, new, **hints): 54 | # HACK: work around sympy not recognizing child classes as symbols. 55 | if old == self: 56 | return new 57 | return super()._subs(old, new, **hints) 58 | -------------------------------------------------------------------------------- /openfermioncirq/variational/letter_with_subscripts_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import sympy 14 | 15 | import cirq 16 | import openfermioncirq as ofc 17 | 18 | from openfermioncirq.variational.letter_with_subscripts import ( 19 | LetterWithSubscripts) 20 | 21 | 22 | def test_letter_with_subscripts_init(): 23 | symbol = LetterWithSubscripts('T', 0, 1) 24 | assert symbol.letter == 'T' 25 | assert symbol.subscripts == (0, 1) 26 | assert str(symbol) == 'T_0_1' 27 | 28 | 29 | def test_equality(): 30 | eq = cirq.testing.EqualsTester() 31 | eq.add_equality_group(LetterWithSubscripts('T', 0, 1), 32 | LetterWithSubscripts('T', 0, 1), 33 | sympy.Symbol('T_0_1')) 34 | eq.add_equality_group(LetterWithSubscripts('S', 0)) 35 | eq.add_equality_group(LetterWithSubscripts('T', 0, 2)) 36 | 37 | 38 | def test_substitute_works(): 39 | assert LetterWithSubscripts('T', 1, 2).subs({'T_1_2': 5}) == 5 40 | 41 | 42 | def test_repr(): 43 | ofc.testing.assert_equivalent_repr(LetterWithSubscripts('T', 1, 2)) 44 | -------------------------------------------------------------------------------- /openfermioncirq/variational/objective.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | from typing import Optional, Tuple, Union 14 | 15 | import abc 16 | 17 | import numpy 18 | 19 | import cirq 20 | 21 | 22 | class VariationalObjective(metaclass=abc.ABCMeta): 23 | """An objective function for a variational algorithm. 24 | 25 | A variational objective is a way of assigning a numerical value, or score, 26 | to the output from executing a circuit. The goal of a variational 27 | algorithm is to find a setting of parameters that minimizes the value 28 | of the resulting circuit output. 29 | 30 | The VariationalObjective class supports the option to provide a noise 31 | and cost model for the value. This is useful for modeling situations 32 | in which the value can be determined only approximately and there is a 33 | tradeoff between the accuracy of the evaluation and the cost of the 34 | evaluation. 35 | """ 36 | 37 | @abc.abstractmethod 38 | def value(self, 39 | circuit_output: Union[cirq.TrialResult, 40 | cirq.SimulationTrialResult, 41 | numpy.ndarray] 42 | ) -> float: 43 | """The evaluation function for a circuit output. 44 | 45 | A variational quantum algorithm will attempt to minimize this value over 46 | possible settings of the parameters. 47 | """ 48 | 49 | def noise(self, cost: Optional[float]=None) -> float: 50 | """Artificial noise that may be added to the true objective value. 51 | 52 | The `cost` argument is used to model situations in which it is possible 53 | to reduce the magnitude of the noise at some cost. 54 | """ 55 | # Default: no noise 56 | return 0.0 57 | 58 | def noise_bounds(self, 59 | cost: float, 60 | confidence: Optional[float]=None 61 | ) -> Tuple[float, float]: 62 | """Exact or approximate bounds on noise. 63 | 64 | Returns a tuple (a, b) such that when `noise` is called with the given 65 | cost, the returned value lies between a and b. It should be the case 66 | that a <= 0 <= b. 67 | 68 | This function takes an optional `confidence` parameter which is a real 69 | number strictly between 0 and 1 that gives the probability of the bounds 70 | being correct. This is used for situations in which exact bounds on the 71 | noise cannot be guaranteed. 72 | """ 73 | return -numpy.inf, numpy.inf 74 | -------------------------------------------------------------------------------- /openfermioncirq/variational/objective_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import numpy 14 | import cirq 15 | import pytest 16 | 17 | from openfermioncirq import VariationalObjective 18 | from openfermioncirq.testing import ( 19 | ExampleVariationalObjective, 20 | ExampleVariationalObjectiveNoisy) 21 | 22 | 23 | test_objective = ExampleVariationalObjective() 24 | test_objective_noisy = ExampleVariationalObjectiveNoisy() 25 | 26 | 27 | def test_variational_objective_value(): 28 | simulator = cirq.Simulator() 29 | qubits = cirq.LineQubit.range(4) 30 | circuit = cirq.Circuit( 31 | cirq.X.on_each(*qubits[:3]), 32 | cirq.measure(*qubits, key='all')) 33 | result = simulator.simulate(circuit) 34 | 35 | numpy.testing.assert_allclose(test_objective.value(result), 3) 36 | 37 | 38 | def test_variational_objective_noise(): 39 | numpy.testing.assert_allclose(test_objective.noise(2.0), 0.0) 40 | 41 | numpy.random.seed(26347) 42 | assert -0.6 < test_objective_noisy.noise(2.0) < 0.6 43 | 44 | 45 | def test_variational_objective_noise_bounds(): 46 | assert test_objective.noise_bounds(100) == (-numpy.inf, numpy.inf) 47 | 48 | 49 | def test_variational_objective_is_abstract_cant_instantiate(): 50 | with pytest.raises(TypeError): 51 | _ = VariationalObjective() 52 | 53 | 54 | def test_variational_objective_is_abstract_must_implement(): 55 | class Missing(VariationalObjective): 56 | pass 57 | with pytest.raises(TypeError): 58 | _ = Missing() 59 | 60 | 61 | def test_variational_objective_is_abstract_can_implement(): 62 | class Included(VariationalObjective): 63 | def value(self): 64 | pass 65 | assert isinstance(Included(), VariationalObjective) 66 | -------------------------------------------------------------------------------- /openfermioncirq/variational/variational_black_box_test.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import pytest 14 | 15 | from openfermioncirq.testing import ExampleAnsatz, ExampleVariationalObjective 16 | from openfermioncirq.variational.variational_black_box import ( 17 | VariationalBlackBox) 18 | 19 | 20 | def test_variational_black_box_is_abstract_cant_instantiate(): 21 | with pytest.raises(TypeError): 22 | _ = VariationalBlackBox(ExampleAnsatz(), ExampleVariationalObjective()) 23 | 24 | 25 | def test_variational_black_box_is_abstract_must_implement(): 26 | class Missing(VariationalBlackBox): 27 | pass 28 | 29 | with pytest.raises(TypeError): 30 | _ = Missing(ExampleAnsatz(), ExampleVariationalObjective()) 31 | 32 | 33 | def test_variational_black_box_is_abstract_can_implement(): 34 | class Included(VariationalBlackBox): 35 | def evaluate_noiseless(self, x): 36 | pass 37 | 38 | assert isinstance(Included(ExampleAnsatz(), ExampleVariationalObjective()), 39 | VariationalBlackBox) 40 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | deprecation 2 | numpy 3 | pandas 4 | scipy 5 | sympy 6 | joblib 7 | 8 | # NOTE: switch to non-dev versions when releasing! 9 | cirq==0.7.0 10 | openfermion==0.11.0 11 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # https://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | import io 14 | from setuptools import find_packages, setup 15 | 16 | # This reads the __version__ variable from openfermioncirq/_version.py 17 | __version__ = None 18 | exec(open('openfermioncirq/_version.py').read()) 19 | 20 | # Readme file as long_description: 21 | long_description = ('================\n' + 22 | 'OpenFermion-Cirq\n' + 23 | '================\n') 24 | stream = io.open('README.rst', encoding='utf-8') 25 | stream.readline() 26 | long_description += stream.read() 27 | description = ('Quantum circuits for simulations ' + 28 | 'of quantum chemistry and materials.') 29 | 30 | # Read in requirements.txt 31 | requirements = open('requirements.txt').readlines() 32 | requirements = [r.strip() for r in requirements] 33 | 34 | # install_requires should not be overly specific. 35 | # Change any == pinned deps to >=. 36 | # https://packaging.python.org/discussions/install-requires-vs-requirements/ 37 | requirements = [r.replace('==', '>=') for r in requirements] 38 | 39 | openfermioncirq_packages = ['openfermioncirq'] + [ 40 | 'openfermioncirq.' + package 41 | for package in find_packages(where='openfermioncirq') 42 | ] 43 | 44 | setup( 45 | name='openfermioncirq', 46 | version=__version__, 47 | url='https://github.com/quantumlib/OpenFermion-Cirq', 48 | author='The OpenFermion Developers', 49 | author_email='openfermioncirq@googlegroups.com', 50 | python_requires=('>=3.6.5'), 51 | install_requires=requirements, 52 | license='Apache 2', 53 | description=description, 54 | long_description=long_description, 55 | packages=openfermioncirq_packages) 56 | --------------------------------------------------------------------------------