Skip to content

Commit

Permalink
Move third_party to recirq/third_party (#361)
Browse files Browse the repository at this point in the history
* Move third_party to recirq
  • Loading branch information
fdmalone authored Jul 30, 2024
1 parent 3f68692 commit 7f4119a
Show file tree
Hide file tree
Showing 49 changed files with 75 additions and 89 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
python -m pip install --upgrade pip
python dev_tools/write-ci-requirements.py --relative-cirq-version=${{ matrix.cirq-version }} --all-extras
pip install -r ci-requirements.txt
pip install -e third_party/quaff
pip install --no-deps -e .
- name: Lint with flake8
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ install from source:

Documentation is available at https://quantumai.google/cirq/experiments.

To run code relevant for the [QCQMC experiment](https://www.nature.com/articles/s41586-021-04351-z)
you must also install `quaff` which is vendored with recirq. From the top level of
the recirq repository do:

pip install third_party/quaff

## See Also

This code leverages [Cirq](https://github.com/quantumlib/Cirq) as a
Expand Down
2 changes: 1 addition & 1 deletion docs/qcqmc/experimental_wavefunctions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"| 8896 | -1.954930 | -1.947458 | -1.913889 | -1.913068 |\n",
"| 15000 | -1.954356 | -1.948894 | -1.913894 | -1.913082 |\n",
"\n",
"Each column represents an independented partitioned shadow tomography experiment.\n"
"Each column represents an independent partitioned shadow tomography experiment.\n"
]
},
{
Expand Down
7 changes: 3 additions & 4 deletions docs/qcqmc/full_workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@
")\n",
"print(f\"Reconstructed shadow wavefunction energy: {ipie_data.variational_energy}\")\n",
"print(f\"Ideal trial wavefunction energy: {trial_wf.ansatz_energy}\")\n",
"print(f\"FCI energy: {trial_wf.fci_energy}\")\n",
"print(ipie_data)"
"print(f\"FCI energy: {trial_wf.fci_energy}\")"
]
},
{
Expand Down Expand Up @@ -372,9 +371,9 @@
"source": [
"# Next steps\n",
"\n",
"The results presented above are far worse than reported in the paper. In practice one needs to:\n",
"The results presented above are worse than reported in the paper. In practice one needs to:\n",
"\n",
"1. Optimize the trial wavefunction parameters\n",
"1. Carefully converge the trial wavefunction parameters by scanning over multiple random restarts.\n",
"2. Converge the reconstructed shadow wavefunction with respect to: `n_cliffords`\n",
"3. The AFQMC part of the simulations can be sped up using MPI parallelism. See [ipie](https://github.com/JoonhoLee-Group/ipie) for more information. The number of walkers should also be increased to obtain better statistics and reduce any population control biases. The number of samples (`num_blocks`) should also be increased (`ETotal_nsamp_ac` should be about 100 for statistically significant results.) "
]
Expand Down
2 changes: 1 addition & 1 deletion docs/qcqmc/high_level.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion recirq/qcqmc/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import attrs
import cirq
import numpy as np
import quaff
from recirq.third_party import quaff

from recirq.qcqmc import config, data, for_refactor, trial_wf

Expand Down
2 changes: 1 addition & 1 deletion recirq/qcqmc/blueprint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff

from recirq.qcqmc.blueprint import (BlueprintData, BlueprintParamsTrialWf,
_get_truncated_cliffords)
Expand Down
2 changes: 1 addition & 1 deletion recirq/qcqmc/shadow_tomography_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import cirq
import numpy as np
import quaff
from recirq.third_party import quaff

from recirq.qcqmc.bitstrings import get_bitstrings_a_b
from recirq.qcqmc.shadow_tomography import (
Expand Down
13 changes: 13 additions & 0 deletions recirq/third_party/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from quaff import indexing, json_serialization, linalg, random, testing
from recirq.third_party.quaff import indexing, json_serialization, linalg, random, testing

from .basis_change import BasisChangeGate, get_clearing_network, get_reversal_network
from .comb import binom, get_inversion_number, get_num_perms_with_inversion_number
Expand Down Expand Up @@ -66,8 +66,8 @@


def _register_resolver() -> None:
from quaff.json_resolver import json_resolver
from quaff.json_serialization import _internal_register_resolver
from recirq.third_party.quaff.json_resolver import json_resolver
from recirq.third_party.quaff.json_serialization import _internal_register_resolver

_internal_register_resolver(json_resolver)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cirq
import numpy as np
from quaff import indexing, linalg, random
from recirq.third_party.quaff import indexing, linalg, random


class BasisChangeGate(cirq.Gate):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


def test_get_num_perms_with_inversion_number():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import cirq
import numpy as np
from quaff import basis_change, gates, indexing, linalg
from recirq.third_party.quaff import basis_change, gates, indexing, linalg


def get_index_range(num_qubits: int, num_steps: int, i: int):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize(
Expand Down
10 changes: 10 additions & 0 deletions recirq/third_party/quaff/gates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from recirq.third_party.quaff.gates.fhf import FHFGate
from recirq.third_party.quaff.gates.hadamard_free import HadamardFreeGate
from recirq.third_party.quaff.gates.parameterized import (
get_parameterized_truncated_clifford_ops,
get_parameterized_truncated_cliffords_ops,
get_truncated_clifford_resolver,
get_truncated_cliffords_resolver,
)
from recirq.third_party.quaff.gates.single_qubit_layer import SingleQubitLayerGate
from recirq.third_party.quaff.gates.truncated_clifford import TruncatedCliffordGate
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import cirq
import numpy as np
from quaff import linalg, sampling, testing
from quaff.gates.hadamard_free import HadamardFreeGate
from quaff.gates.single_qubit_layer import SingleQubitLayerGate
from recirq.third_party.quaff import linalg, sampling, testing
from recirq.third_party.quaff.gates.hadamard_free import HadamardFreeGate
from recirq.third_party.quaff.gates.single_qubit_layer import SingleQubitLayerGate


def _recover_permutation(matrix: np.ndarray) -> Optional[np.ndarray]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize("n, seed", ((n, quaff.random_seed()) for n in range(1, 7)))
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import cirq
import numpy as np
from quaff import indexing, linalg, random, testing
from recirq.third_party.quaff import indexing, linalg, random, testing


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


def assert_hadamard_free_gate_unitary_is_good(n, gate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import cirq
import sympy
from quaff import cz_layer
from quaff.gates.truncated_clifford import TruncatedCliffordGate
from recirq.third_party.quaff import cz_layer
from recirq.third_party.quaff.gates.truncated_clifford import TruncatedCliffordGate


def get_truncated_clifford_resolver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize("n, seed", ((n, quaff.random_seed()) for n in range(1, 6)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


def test_single_qubit_layer_gate_bad():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import cirq
import numpy as np
from quaff import comb, cz_layer, indexing, linalg, sampling, testing
from quaff.gates.fhf import FHFGate
from quaff.gates.hadamard_free import HadamardFreeGate
from quaff.gates.single_qubit_layer import SingleQubitLayerGate
from quaff.linalg import BooleanMatrix, BooleanVector
from recirq.third_party.quaff import comb, cz_layer, indexing, linalg, sampling, testing
from recirq.third_party.quaff.gates.fhf import FHFGate
from recirq.third_party.quaff.gates.hadamard_free import HadamardFreeGate
from recirq.third_party.quaff.gates.single_qubit_layer import SingleQubitLayerGate
from recirq.third_party.quaff.linalg import BooleanMatrix, BooleanVector


@dataclass(eq=True, order=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cirq
import numpy as np
import pytest
from quaff import (
from recirq.third_party.quaff import (
DEFAULT_RESOLVERS,
HadamardFreeGate,
TruncatedCliffordGate,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize("n, big_endian", itertools.product(range(5), (0, 1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from cirq.protocols.json_serialization import ObjectFactory

from recirq.third_party import quaff


def json_resolver(quaff_type: str) -> Optional[ObjectFactory]:
if quaff_type.startswith("quaff."):
return cast(
ObjectFactory,
eval(f"__import__('quaff').{quaff_type.split('.', 1)[1]}", {}, {}),
getattr(quaff, quaff_type[6:])
)
return None
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Callable, Iterable, Optional, Tuple, Union

import numpy as np
from quaff import indexing
from recirq.third_party.quaff import indexing

DTYPE = np.uint8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cirq
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional, Tuple

import numpy as np
from quaff import indexing, linalg, sampling
from recirq.third_party.quaff import indexing, linalg, sampling

SEED = 2349230498
RNG = np.random.default_rng(SEED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
import quaff
from recirq.third_party import quaff


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from quaff import testing
from recirq.third_party.quaff import testing

from .boolean_sampler import BooleanSampler
from .clifford_sampler import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from typing import Any, Iterable, Optional, Tuple

import numpy as np
from quaff import linalg, testing
from quaff.sampling.sampler import Randomness, Sample, Sampler
from recirq.third_party.quaff import linalg, testing
from recirq.third_party.quaff.sampling.sampler import Randomness, Sample, Sampler


class BooleanSampler(Sampler):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import cirq
import numpy as np
from quaff import comb, indexing, linalg, testing
from quaff.sampling.sampler import SingleParameterSampler
from recirq.third_party.quaff import comb, indexing, linalg, testing
from recirq.third_party.quaff.sampling.sampler import SingleParameterSampler

QuantumMallowsSample = Tuple[Tuple[bool, ...], Tuple[int, ...]]
QuantumMallowsRandomness = Tuple[int, ...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, Iterable, Optional, Tuple, cast

import numpy as np
from quaff import comb, indexing, linalg
from quaff.sampling.sampler import SingleParameterSampler
from recirq.third_party.quaff import comb, indexing, linalg
from recirq.third_party.quaff.sampling.sampler import SingleParameterSampler

MallowsSample = Tuple[int, ...]
MallowsRandomness = Tuple[int, ...]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np
import scipy.stats
from quaff import json_serialization, random
from quaff.testing import assert_equivalent_repr
from recirq.third_party.quaff import json_serialization, random
from recirq.third_party.quaff.testing import assert_equivalent_repr


def assert_sampler_consistent(sampler_cls, *args, test_json=False, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cirq
import numpy as np
from quaff import linalg
from recirq.third_party.quaff import linalg


def assert_consistent_unitary_round_trip(num_qubits, gate_type, seed):
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ def _parse_requirements(path: pathlib.Path):
'hfvqe/molecular_data/hydrogen_chains/*/*/*',
# Needed for ftbbl docs
'otoc/loschmidt/tilted_square_lattice/*',
# Needed for qcqmc notebooks
'qcqmc/data/integrals/*/*',
]},
)
Loading

0 comments on commit 7f4119a

Please sign in to comment.