From d661d69f08554e1e0b0ed7e98cb9f45b63065055 Mon Sep 17 00:00:00 2001 From: Tanuj Khattar Date: Thu, 26 Sep 2024 20:36:54 +0200 Subject: [PATCH] Update black and reformat files (#1422) * Update black and reformat files * Update pyproject.toml --- dev_tools/requirements/deps/format.txt | 2 +- dev_tools/requirements/envs/dev.env.txt | 33 ++++---- dev_tools/requirements/envs/docs.env.txt | 18 ++--- dev_tools/requirements/envs/format.env.txt | 18 +++-- dev_tools/requirements/envs/pylint.env.txt | 21 +++-- dev_tools/requirements/envs/pytest.env.txt | 21 +++-- dev_tools/requirements/envs/runtime.env.txt | 14 ++-- pyproject.toml | 2 +- qualtran/_infra/bloq_example.py | 6 +- qualtran/_infra/composite_bloq.py | 6 +- qualtran/_infra/controlled.py | 3 +- qualtran/_infra/gate_with_registers.py | 8 +- qualtran/_infra/single_qubit_controlled.py | 3 +- qualtran/bloqs/arithmetic/comparison_test.py | 4 +- qualtran/bloqs/arithmetic/subtraction_test.py | 2 +- qualtran/bloqs/basic_gates/identity.py | 1 + qualtran/bloqs/basic_gates/rotation.py | 2 + qualtran/bloqs/basic_gates/s_gate.py | 1 + .../qubitization/select_hubbard.py | 4 +- .../pbc/first_quantization/prepare.py | 1 + .../pbc/first_quantization/prepare_nu.py | 6 ++ .../pbc/first_quantization/prepare_t.py | 1 + .../pbc/first_quantization/prepare_uv.py | 1 + .../pbc/first_quantization/prepare_zeta.py | 1 + .../projectile/prepare_nu.py | 2 + .../projectile/prepare_nu_test.py | 4 +- .../projectile/prepare_t.py | 1 + .../projectile/prepare_uv.py | 1 + .../projectile/select_and_prepare.py | 1 + .../first_quantization/projectile/select_t.py | 1 + .../first_quantization/select_and_prepare.py | 2 + .../pbc/first_quantization/select_t.py | 1 + .../chemistry/quad_fermion/givens_bloq.py | 1 + .../trotter/grid_ham/inverse_sqrt_test.py | 8 +- .../bloqs/chemistry/trotter/grid_ham/qvr.py | 1 + .../chemistry/trotter/hubbard/hopping_test.py | 4 +- .../chemistry/trotter/ising/unitaries.py | 2 + qualtran/bloqs/data_loading/qroam_clean.py | 8 +- .../bloqs/data_loading/select_swap_qrom.py | 6 +- qualtran/bloqs/mcmt/multi_control_pauli.py | 2 + .../mod_arithmetic/mod_multiplication.py | 2 + .../multiplexers/apply_gate_to_lth_target.py | 1 + qualtran/bloqs/multiplexers/select_base.py | 9 +-- .../bloqs/multiplexers/select_pauli_lcu.py | 1 + .../phase_estimation/qpe_window_state.py | 3 +- .../bloqs/rotations/hamming_weight_phasing.py | 3 +- .../rotations/phasing_via_cost_function.py | 1 + .../phasing_via_cost_function_test.py | 5 +- .../programmable_ancilla_rotation.py | 1 + .../rotations/quantum_variable_rotation.py | 6 +- .../rotations/zpow_via_phase_gradient.py | 1 + .../bloqs/state_preparation/prepare_base.py | 3 +- .../sparse_state_preparation_via_rotations.py | 1 + .../state_preparation_alias_sampling.py | 1 + .../bloqs/swap_network/multiplexed_cswap.py | 1 + qualtran/cirq_interop/_cirq_to_bloq.py | 9 +-- .../t_complexity_protocol_test.py | 3 +- qualtran/drawing/_show_funcs.py | 6 +- qualtran/linalg/lcu_util.py | 6 +- qualtran/surface_code/ccz2t_factory_test.py | 4 +- qualtran/symbolics/math_funcs.py | 78 +++++++------------ qualtran/symbolics/types.py | 6 +- 62 files changed, 179 insertions(+), 196 deletions(-) diff --git a/dev_tools/requirements/deps/format.txt b/dev_tools/requirements/deps/format.txt index c2161118a..13c83c1e3 100644 --- a/dev_tools/requirements/deps/format.txt +++ b/dev_tools/requirements/deps/format.txt @@ -1,3 +1,3 @@ flynt~=0.60 -black~=22.3.0 +black~=24.8.0 isort~=5.10.1 diff --git a/dev_tools/requirements/envs/dev.env.txt b/dev_tools/requirements/envs/dev.env.txt index bd383f47b..109d11252 100644 --- a/dev_tools/requirements/envs/dev.env.txt +++ b/dev_tools/requirements/envs/dev.env.txt @@ -12,7 +12,7 @@ alabaster==1.0.0 # via sphinx annotated-types==0.7.0 # via pydantic -anyio==4.5.0 +anyio==4.6.0 # via # httpx # jupyter-server @@ -60,7 +60,7 @@ beautifulsoup4==4.12.3 # via # nbconvert # pydata-sphinx-theme -black==22.3.0 +black==24.8.0 # via -r deps/format.txt bleach==6.1.0 # via nbconvert @@ -115,7 +115,7 @@ dash-html-components==2.0.0 # via dash dash-table==5.0.0 # via dash -debugpy==1.8.5 +debugpy==1.8.6 # via ipykernel decorator==5.1.1 # via ipython @@ -155,7 +155,7 @@ flask==3.0.3 # via dash flynt==0.78 # via -r deps/format.txt -fonttools==4.53.1 +fonttools==4.54.1 # via matplotlib fqdn==1.5.1 # via jsonschema @@ -163,7 +163,7 @@ fxpmath==0.4.9 # via -r deps/runtime.txt graphviz==0.20.3 # via qref -greenlet==3.1.0 +greenlet==3.1.1 # via sqlalchemy grpcio==1.66.1 # via grpcio-tools @@ -171,7 +171,7 @@ grpcio-tools==1.66.1 # via -r deps/packaging.txt h11==0.14.0 # via httpcore -h5py==3.11.0 +h5py==3.12.1 # via # openfermion # pyscf @@ -298,7 +298,7 @@ jupyterlab-server==2.27.3 # notebook jupyterlab-widgets==3.0.13 # via ipywidgets -keyring==25.4.0 +keyring==25.4.1 # via twine kiwisolver==1.4.7 # via matplotlib @@ -351,7 +351,7 @@ mypy-extensions==1.0.0 # mypy mypy-protobuf==3.6.0 # via -r deps/mypy.txt -myst-nb==1.1.1 +myst-nb==1.1.2 # via -r deps/docs.txt myst-parser==4.0.0 # via myst-nb @@ -410,7 +410,6 @@ numpy==1.26.4 # ml-dtypes # numba # openfermion - # opt-einsum # pandas # pyscf # quimb @@ -419,12 +418,13 @@ openfermion[resources]==1.6.1 # via # -r deps/pylint.txt # -r deps/pytest.txt -opt-einsum==3.3.0 +opt-einsum==3.4.0 # via jax overrides==7.7.0 # via jupyter-server packaging==24.1 # via + # black # build # deprecation # ipykernel @@ -465,9 +465,9 @@ plotly==5.24.1 # dash pluggy==1.5.0 # via pytest -prometheus-client==0.20.0 +prometheus-client==0.21.0 # via jupyter-server -prompt-toolkit==3.0.47 +prompt-toolkit==3.0.48 # via ipython protobuf==5.28.2 # via @@ -499,7 +499,7 @@ pydantic-core==2.23.4 # via pydantic pydata-sphinx-theme==0.15.4 # via -r deps/docs.txt -pydot==3.0.1 +pydot==3.0.2 # via -r deps/runtime.txt pygments==2.18.0 # via @@ -521,7 +521,7 @@ pyproject-hooks==1.1.0 # via # build # pip-tools -pyscf==2.6.2 +pyscf==2.7.0 # via openfermion pytest==8.3.3 # via @@ -722,7 +722,7 @@ traitlets==5.14.3 # nbformat twine==5.1.1 # via -r deps/packaging.txt -types-protobuf==5.27.0.20240920 +types-protobuf==5.28.0.20240924 # via mypy-protobuf types-python-dateutil==2.9.0.20240906 # via arrow @@ -733,6 +733,7 @@ typing-extensions==4.12.2 # anywidget # astroid # async-lru + # black # cirq-core # dash # ipython @@ -742,7 +743,7 @@ typing-extensions==4.12.2 # pydantic-core # pydata-sphinx-theme # sqlalchemy -tzdata==2024.1 +tzdata==2024.2 # via pandas uri-template==1.3.0 # via jsonschema diff --git a/dev_tools/requirements/envs/docs.env.txt b/dev_tools/requirements/envs/docs.env.txt index ee6cf7f2f..5296c6f19 100644 --- a/dev_tools/requirements/envs/docs.env.txt +++ b/dev_tools/requirements/envs/docs.env.txt @@ -20,7 +20,7 @@ annotated-types==0.7.0 # via # -c envs/dev.env.txt # pydantic -anyio==4.5.0 +anyio==4.6.0 # via # -c envs/dev.env.txt # httpx @@ -153,7 +153,7 @@ dash-table==5.0.0 # via # -c envs/dev.env.txt # dash -debugpy==1.8.5 +debugpy==1.8.6 # via # -c envs/dev.env.txt # ipykernel @@ -192,7 +192,7 @@ flask==3.0.3 # via # -c envs/dev.env.txt # dash -fonttools==4.53.1 +fonttools==4.54.1 # via # -c envs/dev.env.txt # matplotlib @@ -208,7 +208,7 @@ graphviz==0.20.3 # via # -c envs/dev.env.txt # qref -greenlet==3.1.0 +greenlet==3.1.1 # via # -c envs/dev.env.txt # sqlalchemy @@ -402,7 +402,7 @@ mpmath==1.3.0 # via # -c envs/dev.env.txt # sympy -myst-nb==1.1.1 +myst-nb==1.1.2 # via # -c envs/dev.env.txt # -r deps/docs.txt @@ -513,11 +513,11 @@ plotly==5.24.1 # -c envs/dev.env.txt # -r deps/runtime.txt # dash -prometheus-client==0.20.0 +prometheus-client==0.21.0 # via # -c envs/dev.env.txt # jupyter-server -prompt-toolkit==3.0.47 +prompt-toolkit==3.0.48 # via # -c envs/dev.env.txt # ipython @@ -561,7 +561,7 @@ pydata-sphinx-theme==0.15.4 # via # -c envs/dev.env.txt # -r deps/docs.txt -pydot==3.0.1 +pydot==3.0.2 # via # -c envs/dev.env.txt # -r deps/runtime.txt @@ -814,7 +814,7 @@ typing-extensions==4.12.2 # pydantic-core # pydata-sphinx-theme # sqlalchemy -tzdata==2024.1 +tzdata==2024.2 # via # -c envs/dev.env.txt # pandas diff --git a/dev_tools/requirements/envs/format.env.txt b/dev_tools/requirements/envs/format.env.txt index 3e22123c2..f8bb281d1 100644 --- a/dev_tools/requirements/envs/format.env.txt +++ b/dev_tools/requirements/envs/format.env.txt @@ -8,7 +8,7 @@ annotated-types==0.7.0 # via # -c envs/dev.env.txt # pydantic -anyio==4.5.0 +anyio==4.6.0 # via # -c envs/dev.env.txt # httpx @@ -65,7 +65,7 @@ beautifulsoup4==4.12.3 # via # -c envs/dev.env.txt # nbconvert -black==22.3.0 +black==24.8.0 # via # -c envs/dev.env.txt # -r deps/format.txt @@ -141,7 +141,7 @@ dash-table==5.0.0 # via # -c envs/dev.env.txt # dash -debugpy==1.8.5 +debugpy==1.8.6 # via # -c envs/dev.env.txt # ipykernel @@ -178,7 +178,7 @@ flynt==0.78 # via # -c envs/dev.env.txt # -r deps/format.txt -fonttools==4.53.1 +fonttools==4.54.1 # via # -c envs/dev.env.txt # matplotlib @@ -421,6 +421,7 @@ overrides==7.7.0 packaging==24.1 # via # -c envs/dev.env.txt + # black # ipykernel # jupyter-server # jupyterlab @@ -462,11 +463,11 @@ plotly==5.24.1 # -c envs/dev.env.txt # -r deps/runtime.txt # dash -prometheus-client==0.20.0 +prometheus-client==0.21.0 # via # -c envs/dev.env.txt # jupyter-server -prompt-toolkit==3.0.47 +prompt-toolkit==3.0.48 # via # -c envs/dev.env.txt # ipython @@ -505,7 +506,7 @@ pydantic-core==2.23.4 # via # -c envs/dev.env.txt # pydantic -pydot==3.0.1 +pydot==3.0.2 # via # -c envs/dev.env.txt # -r deps/runtime.txt @@ -696,12 +697,13 @@ typing-extensions==4.12.2 # anyio # anywidget # async-lru + # black # cirq-core # dash # ipython # pydantic # pydantic-core -tzdata==2024.1 +tzdata==2024.2 # via # -c envs/dev.env.txt # pandas diff --git a/dev_tools/requirements/envs/pylint.env.txt b/dev_tools/requirements/envs/pylint.env.txt index 8b182f40b..d8f95d15c 100644 --- a/dev_tools/requirements/envs/pylint.env.txt +++ b/dev_tools/requirements/envs/pylint.env.txt @@ -16,7 +16,7 @@ annotated-types==0.7.0 # via # -c envs/dev.env.txt # pydantic -anyio==4.5.0 +anyio==4.6.0 # via # -c envs/dev.env.txt # httpx @@ -154,7 +154,7 @@ dash-table==5.0.0 # via # -c envs/dev.env.txt # dash -debugpy==1.8.5 +debugpy==1.8.6 # via # -c envs/dev.env.txt # ipykernel @@ -204,7 +204,7 @@ flask==3.0.3 # via # -c envs/dev.env.txt # dash -fonttools==4.53.1 +fonttools==4.54.1 # via # -c envs/dev.env.txt # matplotlib @@ -224,7 +224,7 @@ h11==0.14.0 # via # -c envs/dev.env.txt # httpcore -h5py==3.11.0 +h5py==3.12.1 # via # -c envs/dev.env.txt # openfermion @@ -479,7 +479,6 @@ numpy==1.26.4 # ml-dtypes # numba # openfermion - # opt-einsum # pandas # pyscf # quimb @@ -488,7 +487,7 @@ openfermion[resources]==1.6.1 # via # -c envs/dev.env.txt # -r deps/pylint.txt -opt-einsum==3.3.0 +opt-einsum==3.4.0 # via # -c envs/dev.env.txt # jax @@ -543,11 +542,11 @@ pluggy==1.5.0 # via # -c envs/dev.env.txt # pytest -prometheus-client==0.20.0 +prometheus-client==0.21.0 # via # -c envs/dev.env.txt # jupyter-server -prompt-toolkit==3.0.47 +prompt-toolkit==3.0.48 # via # -c envs/dev.env.txt # ipython @@ -591,7 +590,7 @@ pydantic-core==2.23.4 # via # -c envs/dev.env.txt # pydantic -pydot==3.0.1 +pydot==3.0.2 # via # -c envs/dev.env.txt # -r deps/runtime.txt @@ -611,7 +610,7 @@ pyparsing==3.1.4 # bartiq # matplotlib # pydot -pyscf==2.6.2 +pyscf==2.7.0 # via # -c envs/dev.env.txt # openfermion @@ -851,7 +850,7 @@ typing-extensions==4.12.2 # ipython # pydantic # pydantic-core -tzdata==2024.1 +tzdata==2024.2 # via # -c envs/dev.env.txt # pandas diff --git a/dev_tools/requirements/envs/pytest.env.txt b/dev_tools/requirements/envs/pytest.env.txt index 20a2fc135..c64afb2e8 100644 --- a/dev_tools/requirements/envs/pytest.env.txt +++ b/dev_tools/requirements/envs/pytest.env.txt @@ -8,7 +8,7 @@ annotated-types==0.7.0 # via # -c envs/dev.env.txt # pydantic -anyio==4.5.0 +anyio==4.6.0 # via # -c envs/dev.env.txt # httpx @@ -141,7 +141,7 @@ dash-table==5.0.0 # via # -c envs/dev.env.txt # dash -debugpy==1.8.5 +debugpy==1.8.6 # via # -c envs/dev.env.txt # ipykernel @@ -187,7 +187,7 @@ flask==3.0.3 # via # -c envs/dev.env.txt # dash -fonttools==4.53.1 +fonttools==4.54.1 # via # -c envs/dev.env.txt # matplotlib @@ -207,7 +207,7 @@ h11==0.14.0 # via # -c envs/dev.env.txt # httpcore -h5py==3.11.0 +h5py==3.12.1 # via # -c envs/dev.env.txt # openfermion @@ -444,7 +444,6 @@ numpy==1.26.4 # ml-dtypes # numba # openfermion - # opt-einsum # pandas # pyscf # quimb @@ -453,7 +452,7 @@ openfermion[resources]==1.6.1 # via # -c envs/dev.env.txt # -r deps/pytest.txt -opt-einsum==3.3.0 +opt-einsum==3.4.0 # via # -c envs/dev.env.txt # jax @@ -506,11 +505,11 @@ pluggy==1.5.0 # via # -c envs/dev.env.txt # pytest -prometheus-client==0.20.0 +prometheus-client==0.21.0 # via # -c envs/dev.env.txt # jupyter-server -prompt-toolkit==3.0.47 +prompt-toolkit==3.0.48 # via # -c envs/dev.env.txt # ipython @@ -553,7 +552,7 @@ pydantic-core==2.23.4 # via # -c envs/dev.env.txt # pydantic -pydot==3.0.1 +pydot==3.0.2 # via # -c envs/dev.env.txt # -r deps/runtime.txt @@ -568,7 +567,7 @@ pyparsing==3.1.4 # bartiq # matplotlib # pydot -pyscf==2.6.2 +pyscf==2.7.0 # via # -c envs/dev.env.txt # openfermion @@ -779,7 +778,7 @@ typing-extensions==4.12.2 # ipython # pydantic # pydantic-core -tzdata==2024.1 +tzdata==2024.2 # via # -c envs/dev.env.txt # pandas diff --git a/dev_tools/requirements/envs/runtime.env.txt b/dev_tools/requirements/envs/runtime.env.txt index 8fc6e6bd4..01a1dec16 100644 --- a/dev_tools/requirements/envs/runtime.env.txt +++ b/dev_tools/requirements/envs/runtime.env.txt @@ -8,7 +8,7 @@ annotated-types==0.7.0 # via # -c envs/dev.env.txt # pydantic -anyio==4.5.0 +anyio==4.6.0 # via # -c envs/dev.env.txt # httpx @@ -132,7 +132,7 @@ dash-table==5.0.0 # via # -c envs/dev.env.txt # dash -debugpy==1.8.5 +debugpy==1.8.6 # via # -c envs/dev.env.txt # ipykernel @@ -165,7 +165,7 @@ flask==3.0.3 # via # -c envs/dev.env.txt # dash -fonttools==4.53.1 +fonttools==4.54.1 # via # -c envs/dev.env.txt # matplotlib @@ -436,11 +436,11 @@ plotly==5.24.1 # -c envs/dev.env.txt # -r deps/runtime.txt # dash -prometheus-client==0.20.0 +prometheus-client==0.21.0 # via # -c envs/dev.env.txt # jupyter-server -prompt-toolkit==3.0.47 +prompt-toolkit==3.0.48 # via # -c envs/dev.env.txt # ipython @@ -479,7 +479,7 @@ pydantic-core==2.23.4 # via # -c envs/dev.env.txt # pydantic -pydot==3.0.1 +pydot==3.0.2 # via # -c envs/dev.env.txt # -r deps/runtime.txt @@ -673,7 +673,7 @@ typing-extensions==4.12.2 # ipython # pydantic # pydantic-core -tzdata==2024.1 +tzdata==2024.2 # via # -c envs/dev.env.txt # pandas diff --git a/pyproject.toml b/pyproject.toml index f6ec0b606..7b1548955 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.black] line-length = 100 -target_version = ['py39', 'py310'] +target_version = ['py39', 'py310', 'py311', 'py312'] skip-string-normalization = true skip-magic-trailing-comma = true exclude = "qualtran/protos/*" diff --git a/qualtran/_infra/bloq_example.py b/qualtran/_infra/bloq_example.py index 23484ed41..8153ea6fb 100644 --- a/qualtran/_infra/bloq_example.py +++ b/qualtran/_infra/bloq_example.py @@ -78,15 +78,13 @@ def _bloq_cls_from_func_annotation(func: Callable[[], _BloqType]) -> Type[_BloqT @typing.overload -def bloq_example(_func: Callable[[], _BloqType], **kwargs: Any) -> BloqExample[_BloqType]: - ... +def bloq_example(_func: Callable[[], _BloqType], **kwargs: Any) -> BloqExample[_BloqType]: ... @typing.overload def bloq_example( _func: None = None, *, generalizer: _GeneralizerType = lambda x: x -) -> Callable[[Callable[[], _BloqType]], BloqExample[_BloqType]]: - ... +) -> Callable[[Callable[[], _BloqType]], BloqExample[_BloqType]]: ... def bloq_example( diff --git a/qualtran/_infra/composite_bloq.py b/qualtran/_infra/composite_bloq.py index f55ebb282..8ad8b50c4 100644 --- a/qualtran/_infra/composite_bloq.py +++ b/qualtran/_infra/composite_bloq.py @@ -880,12 +880,10 @@ def add_register_from_dtype( return None @overload - def add_register(self, reg: Register, bitsize: None = None) -> Union[None, SoquetT]: - ... + def add_register(self, reg: Register, bitsize: None = None) -> Union[None, SoquetT]: ... @overload - def add_register(self, reg: str, bitsize: int) -> SoquetT: - ... + def add_register(self, reg: str, bitsize: int) -> SoquetT: ... def add_register( self, reg: Union[str, Register], bitsize: Optional[int] = None diff --git a/qualtran/_infra/controlled.py b/qualtran/_infra/controlled.py index 2516141e7..f417bc2b4 100644 --- a/qualtran/_infra/controlled.py +++ b/qualtran/_infra/controlled.py @@ -268,8 +268,7 @@ class AddControlledT(Protocol): def __call__( self, bb: 'BloqBuilder', ctrl_soqs: Sequence['SoquetT'], in_soqs: Dict[str, 'SoquetT'] - ) -> Tuple[Iterable['SoquetT'], Iterable['SoquetT']]: - ... + ) -> Tuple[Iterable['SoquetT'], Iterable['SoquetT']]: ... def _get_nice_ctrl_reg_names(reg_names: List[str], n: int) -> Tuple[str, ...]: diff --git a/qualtran/_infra/gate_with_registers.py b/qualtran/_infra/gate_with_registers.py index 6afd4265d..e9056cdd3 100644 --- a/qualtran/_infra/gate_with_registers.py +++ b/qualtran/_infra/gate_with_registers.py @@ -101,9 +101,11 @@ def _qubits_for_reg(reg: Register): return _qubit_array(reg) return np.array( - [cirq.NamedQubit(f"{reg.name}")] - if reg.total_bits() == 1 - else cirq.NamedQubit.range(reg.total_bits(), prefix=reg.name), + ( + [cirq.NamedQubit(f"{reg.name}")] + if reg.total_bits() == 1 + else cirq.NamedQubit.range(reg.total_bits(), prefix=reg.name) + ), dtype=object, ) diff --git a/qualtran/_infra/single_qubit_controlled.py b/qualtran/_infra/single_qubit_controlled.py index 84ca01129..1166bd13f 100644 --- a/qualtran/_infra/single_qubit_controlled.py +++ b/qualtran/_infra/single_qubit_controlled.py @@ -47,8 +47,7 @@ def control_registers() -> Tuple[Register, ...]: @property @abc.abstractmethod - def control_registers(self) -> Tuple[Register, ...]: - ... + def control_registers(self) -> Tuple[Register, ...]: ... def get_single_qubit_controlled_bloq( self, control_val: int diff --git a/qualtran/bloqs/arithmetic/comparison_test.py b/qualtran/bloqs/arithmetic/comparison_test.py index 23267e1d6..50ea8678c 100644 --- a/qualtran/bloqs/arithmetic/comparison_test.py +++ b/qualtran/bloqs/arithmetic/comparison_test.py @@ -351,7 +351,7 @@ def test_clineardepthgreaterthan_classical_action_unsigned(ctrl, dtype, bitsize) b = CLinearDepthGreaterThan(dtype(bitsize), ctrl) cb = b.decompose_bloq() for c, target in itertools.product(range(2), repeat=2): - for (x, y) in itertools.product(range(2**bitsize), repeat=2): + for x, y in itertools.product(range(2**bitsize), repeat=2): assert b.call_classically(ctrl=c, a=x, b=y, target=target) == cb.call_classically( ctrl=c, a=x, b=y, target=target ) @@ -363,7 +363,7 @@ def test_clineardepthgreaterthan_classical_action_signed(ctrl, bitsize): b = CLinearDepthGreaterThan(QInt(bitsize), ctrl) cb = b.decompose_bloq() for c, target in itertools.product(range(2), repeat=2): - for (x, y) in itertools.product(range(-(2 ** (bitsize - 1)), 2 ** (bitsize - 1)), repeat=2): + for x, y in itertools.product(range(-(2 ** (bitsize - 1)), 2 ** (bitsize - 1)), repeat=2): assert b.call_classically(ctrl=c, a=x, b=y, target=target) == cb.call_classically( ctrl=c, a=x, b=y, target=target ) diff --git a/qualtran/bloqs/arithmetic/subtraction_test.py b/qualtran/bloqs/arithmetic/subtraction_test.py index 5aa3c488b..40e2bc6fd 100644 --- a/qualtran/bloqs/arithmetic/subtraction_test.py +++ b/qualtran/bloqs/arithmetic/subtraction_test.py @@ -122,7 +122,7 @@ def test_against_classical_values(dtype): else: R1 = range(8) R2 = range(32) - for (a, b) in itertools.product(R1, R2): + for a, b in itertools.product(R1, R2): ref = subtract.call_classically(a=a, b=b) comp = cbloq.call_classically(a=a, b=b) assert ref == comp diff --git a/qualtran/bloqs/basic_gates/identity.py b/qualtran/bloqs/basic_gates/identity.py index 0b81fe34e..434cf1b8b 100644 --- a/qualtran/bloqs/basic_gates/identity.py +++ b/qualtran/bloqs/basic_gates/identity.py @@ -54,6 +54,7 @@ class Identity(Bloq): Registers: q: register of `n` qubits """ + bitsize: SymbolicInt = 1 @cached_property diff --git a/qualtran/bloqs/basic_gates/rotation.py b/qualtran/bloqs/basic_gates/rotation.py index 621c7b760..28a0c9bb3 100644 --- a/qualtran/bloqs/basic_gates/rotation.py +++ b/qualtran/bloqs/basic_gates/rotation.py @@ -177,6 +177,7 @@ class XPowGate(CirqGateAsBloqBase): [Optimal ancilla-free Clifford+T approximation of z-rotations](https://arxiv.org/pdf/1403.2975.pdf). """ + exponent: Union[sympy.Expr, float] = 1.0 global_shift: float = 0.0 eps: SymbolicFloat = 1e-11 @@ -250,6 +251,7 @@ class YPowGate(CirqGateAsBloqBase): [Optimal ancilla-free Clifford+T approximation of z-rotations](https://arxiv.org/pdf/1403.2975.pdf). """ + exponent: Union[sympy.Expr, float] = 1.0 global_shift: float = 0.0 eps: SymbolicFloat = 1e-11 diff --git a/qualtran/bloqs/basic_gates/s_gate.py b/qualtran/bloqs/basic_gates/s_gate.py index 8ea293564..b6a4d9678 100644 --- a/qualtran/bloqs/basic_gates/s_gate.py +++ b/qualtran/bloqs/basic_gates/s_gate.py @@ -50,6 +50,7 @@ class SGate(Bloq): Registers: q: The qubit """ + is_adjoint: bool = False @cached_property diff --git a/qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard.py b/qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard.py index efa0c9e7c..aa889f91f 100644 --- a/qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard.py +++ b/qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard.py @@ -145,8 +145,8 @@ def decompose_from_registers( yield CSwap.make_on(ctrl=V, x=p_y, y=q_y) yield CSwap.make_on(ctrl=V, x=p_x, y=q_x) - yield cirq.S(*control) ** -1 if control else cirq.global_phase_operation( - -1j + yield ( + cirq.S(*control) ** -1 if control else cirq.global_phase_operation(-1j) ) # Fix errant i from XY=iZ yield cirq.Z(*U).controlled_by(*control) # Fix errant -1 from multiple pauli applications diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare.py b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare.py index d85665de0..aba6fd476 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare.py @@ -42,6 +42,7 @@ class UniformSuperpostionIJFirstQuantization(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767). page 18, section A, around Eq 62. """ + eta: int num_bits_rot_aa: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_nu.py b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_nu.py index 74998758e..ae1e4e6bc 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_nu.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_nu.py @@ -50,6 +50,7 @@ class PrepareMuUnaryEncodedOneHot(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 21, Eq 77. """ + num_bits_p: int @cached_property @@ -93,6 +94,7 @@ class PrepareNuSuperPositionState(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 21, Eq 78. """ + num_bits_p: int is_adjoint: bool = False @@ -135,6 +137,7 @@ class FlagZeroAsFailure(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 21, Eq 80. """ + num_bits_p: int is_adjoint: bool = False @@ -184,6 +187,7 @@ class TestNuLessThanMu(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 21, Eq 80. """ + num_bits_p: int is_adjoint: bool = False @@ -250,6 +254,7 @@ class TestNuInequality(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 21, Eq 80. """ + num_bits_p: int num_bits_m: int is_adjoint: bool = False @@ -345,6 +350,7 @@ class PrepareNuState(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 19, section B """ + num_bits_p: int m_param: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_t.py b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_t.py index 26e9f24f1..cb69fc70b 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_t.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_t.py @@ -50,6 +50,7 @@ class PreparePowerTwoState(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767). Eq 67-69, pg 19-20 """ + bitsize: int @cached_property diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_uv.py b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_uv.py index de5273458..2c5e79f0c 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_uv.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_uv.py @@ -59,6 +59,7 @@ class PrepareUVFirstQuantization(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 19, section B """ + num_bits_p: int eta: int num_atoms: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_zeta.py b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_zeta.py index 48df42a2f..de328009e 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_zeta.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_zeta.py @@ -44,6 +44,7 @@ class PrepareZetaState(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 23-24, last 3 paragraphs. """ + num_atoms: int lambda_zeta: int num_bits_nuc_pos: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu.py b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu.py index 4d06eab32..682ab3c65 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu.py @@ -60,6 +60,7 @@ class PrepareMuUnaryEncodedOneHotWithProj(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 21, Eq 77. """ + bitsize_n: int bitsize_p: int is_adjoint: bool = False @@ -115,6 +116,7 @@ class PrepareNuStateWithProj(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 19, section B """ + num_bits_p: int num_bits_n: int m_param: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu_test.py b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu_test.py index c18e58d04..020c80caa 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu_test.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_nu_test.py @@ -39,9 +39,7 @@ def test_prepare_nu_with_proj_t_counts(): expected_cost += ( 2 * 4 * (num_bits_n - 1) + (num_bits_n - num_bits_p - 1) + 6 * num_bits_n + 2 + 2 ) - eq_c6 = ( - 3 * num_bits_n**2 + 16 * num_bits_n - num_bits_p - 6 + 4 * num_bits_m * (num_bits_n + 1) - ) + eq_c6 = 3 * num_bits_n**2 + 16 * num_bits_n - num_bits_p - 6 + 4 * num_bits_m * (num_bits_n + 1) assert expected_cost == eq_c6 + 5 prep = PrepareNuStateWithProj(num_bits_p, num_bits_n, m_param) qual_cost = get_cost_value(prep, QECGatesCost()).total_t_count() diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_t.py b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_t.py index 2603b51c7..d305b6a93 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_t.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_t.py @@ -53,6 +53,7 @@ class PreparePowerTwoStateWithProj(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 19, section B """ + bitsize_n: int bitsize_p: int is_adjoint: bool = False diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_uv.py b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_uv.py index 6fd41776c..f66875a9c 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_uv.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/prepare_uv.py @@ -54,6 +54,7 @@ class PrepareUVFirstQuantizationWithProj(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 19, section B """ + num_bits_p: int num_bits_n: int eta: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_and_prepare.py b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_and_prepare.py index c41428f82..581e30295 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_and_prepare.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_and_prepare.py @@ -83,6 +83,7 @@ class PrepareTUVSuperpositions(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 15, section A """ + num_bits_t: int eta: int lambda_zeta: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_t.py b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_t.py index 4c96e0dd9..efa2e943f 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_t.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_t.py @@ -52,6 +52,7 @@ class SelectTFirstQuantizationWithProj(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 20, section B """ + num_bits_n: int eta: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare.py b/qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare.py index ca95dc44d..5f5001c60 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare.py @@ -64,6 +64,7 @@ class PrepareTUVSuperpositions(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 15, section A """ + num_bits_t: int eta: int lambda_zeta: int @@ -102,6 +103,7 @@ class UniformSuperpostionIJFirstQuantization(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767). page 18, section A, around Eq 62. """ + eta: int num_bits_rot_aa: int diff --git a/qualtran/bloqs/chemistry/pbc/first_quantization/select_t.py b/qualtran/bloqs/chemistry/pbc/first_quantization/select_t.py index 50999c43c..ca7938daa 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/select_t.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/select_t.py @@ -42,6 +42,7 @@ class SelectTFirstQuantization(Bloq): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 20, section B """ + num_bits_p: int eta: int diff --git a/qualtran/bloqs/chemistry/quad_fermion/givens_bloq.py b/qualtran/bloqs/chemistry/quad_fermion/givens_bloq.py index 3c2a2d24f..75a7690f1 100644 --- a/qualtran/bloqs/chemistry/quad_fermion/givens_bloq.py +++ b/qualtran/bloqs/chemistry/quad_fermion/givens_bloq.py @@ -91,6 +91,7 @@ class RealGivensRotationByPhaseGradient(Bloq): Section II-C: Oracles for phasing by cost function. Appendix A: Addition for controlled rotations """ + phasegrad_bitsize: int @cached_property diff --git a/qualtran/bloqs/chemistry/trotter/grid_ham/inverse_sqrt_test.py b/qualtran/bloqs/chemistry/trotter/grid_ham/inverse_sqrt_test.py index 4c984bc09..a1af126a1 100644 --- a/qualtran/bloqs/chemistry/trotter/grid_ham/inverse_sqrt_test.py +++ b/qualtran/bloqs/chemistry/trotter/grid_ham/inverse_sqrt_test.py @@ -81,15 +81,11 @@ def test_build_qrom_data(bitsize, poly_bitsize): a_bits = unique[::2] coeff_as_float = [fixed_point_to_float(c, poly_bitsize) for c in a_bits] for k in range(2, len(unique) // 2): - np.isclose( - coeff_as_float[k], poly_coeffs_a[c] / 2 ** (k / 2), atol=1 / 2**poly_bitsize - ) + np.isclose(coeff_as_float[k], poly_coeffs_a[c] / 2 ** (k / 2), atol=1 / 2**poly_bitsize) b_bits = unique[1::2] coeff_as_float = [fixed_point_to_float(c, poly_bitsize) for c in b_bits] for k in range(2, len(unique) // 2): - np.isclose( - coeff_as_float[k], poly_coeffs_b[c] / 2 ** (k / 2), atol=1 / 2**poly_bitsize - ) + np.isclose(coeff_as_float[k], poly_coeffs_b[c] / 2 ** (k / 2), atol=1 / 2**poly_bitsize) def multiply_fixed_point_float_by_int( diff --git a/qualtran/bloqs/chemistry/trotter/grid_ham/qvr.py b/qualtran/bloqs/chemistry/trotter/grid_ham/qvr.py index 99075b88a..0809fd98b 100644 --- a/qualtran/bloqs/chemistry/trotter/grid_ham/qvr.py +++ b/qualtran/bloqs/chemistry/trotter/grid_ham/qvr.py @@ -47,6 +47,7 @@ class QuantumVariableRotation(Bloq): computers](https://iopscience.iop.org/article/10.1088/1367-2630/14/11/115023/meta) Fig 14. """ + phi_bitsize: int @cached_property diff --git a/qualtran/bloqs/chemistry/trotter/hubbard/hopping_test.py b/qualtran/bloqs/chemistry/trotter/hubbard/hopping_test.py index 337ac1adc..652664817 100644 --- a/qualtran/bloqs/chemistry/trotter/hubbard/hopping_test.py +++ b/qualtran/bloqs/chemistry/trotter/hubbard/hopping_test.py @@ -53,6 +53,4 @@ def test_hopping_tile_hwp_t_counts(): _, counts = bloq.call_graph(generalizer=catch_rotations) n_rot_par = bloq.length**2 // 2 assert counts[Rz(PHI)] == 2 * n_rot_par.bit_length() - assert counts[TGate()] == 8 * bloq.length**2 // 2 + 2 * 4 * ( - n_rot_par - n_rot_par.bit_count() - ) + assert counts[TGate()] == 8 * bloq.length**2 // 2 + 2 * 4 * (n_rot_par - n_rot_par.bit_count()) diff --git a/qualtran/bloqs/chemistry/trotter/ising/unitaries.py b/qualtran/bloqs/chemistry/trotter/ising/unitaries.py index b65714305..c9f9b14ce 100644 --- a/qualtran/bloqs/chemistry/trotter/ising/unitaries.py +++ b/qualtran/bloqs/chemistry/trotter/ising/unitaries.py @@ -33,6 +33,7 @@ class IsingXUnitary(Bloq): Registers: system: The system register to apply the unitary to. """ + nsites: int angle: float eps: float = 1e-10 @@ -65,6 +66,7 @@ class IsingZZUnitary(Bloq): Registers: system: The system register to apply the unitary to. """ + nsites: int angle: float eps: float = 1e-10 diff --git a/qualtran/bloqs/data_loading/qroam_clean.py b/qualtran/bloqs/data_loading/qroam_clean.py index 32b46bb70..d8a29721b 100644 --- a/qualtran/bloqs/data_loading/qroam_clean.py +++ b/qualtran/bloqs/data_loading/qroam_clean.py @@ -110,6 +110,7 @@ class QROAMCleanAdjoint(QROMBase, GateWithRegisters): # type: ignore[misc] [Qubitization of Arbitrary Basis Quantum Chemistry Leveraging Sparsity and Low Rank Factorization](https://arxiv.org/abs/1902.02134). Berry et. al. (2019). Appendix C. """ + log_block_sizes: Tuple[SymbolicInt, ...] = attrs.field( converter=lambda x: tuple(x.tolist() if isinstance(x, np.ndarray) else x) ) @@ -213,9 +214,9 @@ class QROAMCleanAdjointWrapper(Bloq): qroam_clean: 'QROAMClean' log_block_sizes: Tuple[SymbolicInt, ...] = attrs.field( - converter=lambda x: x - if x is None - else tuple(x.tolist() if isinstance(x, np.ndarray) else x) + converter=lambda x: ( + x if x is None else tuple(x.tolist() if isinstance(x, np.ndarray) else x) + ) ) @cached_property @@ -343,6 +344,7 @@ class QROAMClean(SelectSwapQROM): [Qubitization of Arbitrary Basis Quantum Chemistry Leveraging Sparsity and Low Rank Factorization](https://arxiv.org/abs/1902.02134). Berry et. al. (2019). Appendix A. and B. """ + log_block_sizes: Tuple[SymbolicInt, ...] = attrs.field( converter=lambda x: tuple(x.tolist() if isinstance(x, np.ndarray) else x) ) diff --git a/qualtran/bloqs/data_loading/select_swap_qrom.py b/qualtran/bloqs/data_loading/select_swap_qrom.py index b3ab05eef..859b48c90 100644 --- a/qualtran/bloqs/data_loading/select_swap_qrom.py +++ b/qualtran/bloqs/data_loading/select_swap_qrom.py @@ -139,9 +139,9 @@ class SelectSwapQROM(QROMBase, GateWithRegisters): # type: ignore[misc] """ log_block_sizes: Tuple[SymbolicInt, ...] = attrs.field( - converter=lambda x: tuple(x.tolist() if isinstance(x, np.ndarray) else x) - if x is not None - else x, + converter=lambda x: ( + tuple(x.tolist() if isinstance(x, np.ndarray) else x) if x is not None else x + ), default=None, ) use_dirty_ancilla: bool = True diff --git a/qualtran/bloqs/mcmt/multi_control_pauli.py b/qualtran/bloqs/mcmt/multi_control_pauli.py index 6ea86c686..27300e739 100644 --- a/qualtran/bloqs/mcmt/multi_control_pauli.py +++ b/qualtran/bloqs/mcmt/multi_control_pauli.py @@ -185,6 +185,7 @@ class MultiControlX(MultiControlPauli): See :class:`MultiControlPauli` for implementation and costs. """ + target_gate: cirq.Pauli = field(init=False) @target_gate.default @@ -198,6 +199,7 @@ class MultiControlZ(MultiControlPauli): See :class:`MultiControlPauli` for implementation and costs. """ + target_gate: cirq.Pauli = field(init=False) @target_gate.default diff --git a/qualtran/bloqs/mod_arithmetic/mod_multiplication.py b/qualtran/bloqs/mod_arithmetic/mod_multiplication.py index c38de6634..95f74edc7 100644 --- a/qualtran/bloqs/mod_arithmetic/mod_multiplication.py +++ b/qualtran/bloqs/mod_arithmetic/mod_multiplication.py @@ -449,6 +449,7 @@ class _DirtyOutOfPlaceMontgomeryModMulImpl(Bloq): [How to compute a 256-bit elliptic curve private key with only 50 million Toffoli gates](https://arxiv.org/abs/2306.08585) page 8. """ + bitsize: 'SymbolicInt' window_size: 'SymbolicInt' mod: 'SymbolicInt' @@ -571,6 +572,7 @@ class DirtyOutOfPlaceMontgomeryModMul(Bloq): [How to compute a 256-bit elliptic curve private key with only 50 million Toffoli gates](https://arxiv.org/abs/2306.08585) page 8. """ + bitsize: 'SymbolicInt' window_size: 'SymbolicInt' mod: 'SymbolicInt' diff --git a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py index 8238ebbcd..34dbae8b9 100644 --- a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py +++ b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py @@ -49,6 +49,7 @@ class ApplyGateToLthQubit(UnaryIterationGate): [Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity](https://arxiv.org/abs/1805.03662). Babbush et. al. (2018). Section III.A. and Figure 7. """ + selection_regs: Tuple[Register, ...] = attrs.field( converter=lambda v: (v,) if isinstance(v, Register) else tuple(v) ) diff --git a/qualtran/bloqs/multiplexers/select_base.py b/qualtran/bloqs/multiplexers/select_base.py index 26ad6d3d6..dc72bbc1a 100644 --- a/qualtran/bloqs/multiplexers/select_base.py +++ b/qualtran/bloqs/multiplexers/select_base.py @@ -39,18 +39,15 @@ class SelectOracle(GateWithRegisters): @property @abc.abstractmethod - def control_registers(self) -> Tuple[Register, ...]: - ... + def control_registers(self) -> Tuple[Register, ...]: ... @property @abc.abstractmethod - def selection_registers(self) -> Tuple[Register, ...]: - ... + def selection_registers(self) -> Tuple[Register, ...]: ... @property @abc.abstractmethod - def target_registers(self) -> Tuple[Register, ...]: - ... + def target_registers(self) -> Tuple[Register, ...]: ... @cached_property def signature(self) -> Signature: diff --git a/qualtran/bloqs/multiplexers/select_pauli_lcu.py b/qualtran/bloqs/multiplexers/select_pauli_lcu.py index 4cbedb324..840512a0b 100644 --- a/qualtran/bloqs/multiplexers/select_pauli_lcu.py +++ b/qualtran/bloqs/multiplexers/select_pauli_lcu.py @@ -59,6 +59,7 @@ class SelectPauliLCU(SelectOracle, UnaryIterationGate, SpecializedSingleQubitCon dense pauli string must contain `target_bitsize` terms. control_val: Optional control value. If specified, a singly controlled gate is constructed. """ + selection_bitsize: int target_bitsize: int select_unitaries: Tuple[cirq.DensePauliString, ...] = attrs.field(converter=_to_tuple) diff --git a/qualtran/bloqs/phase_estimation/qpe_window_state.py b/qualtran/bloqs/phase_estimation/qpe_window_state.py index 8b92a6495..5d6f0c373 100644 --- a/qualtran/bloqs/phase_estimation/qpe_window_state.py +++ b/qualtran/bloqs/phase_estimation/qpe_window_state.py @@ -35,8 +35,7 @@ def m_register(self) -> 'Register': @property @abc.abstractmethod - def m_bits(self) -> SymbolicInt: - ... + def m_bits(self) -> SymbolicInt: ... @attrs.frozen diff --git a/qualtran/bloqs/rotations/hamming_weight_phasing.py b/qualtran/bloqs/rotations/hamming_weight_phasing.py index 94239138e..7f6334fd4 100644 --- a/qualtran/bloqs/rotations/hamming_weight_phasing.py +++ b/qualtran/bloqs/rotations/hamming_weight_phasing.py @@ -85,8 +85,7 @@ def build_composite_bloq(self, bb: 'BloqBuilder', **soqs: 'SoquetT') -> Dict[str out = bb.split(out) for i in range(len(out)): out[-(i + 1)] = bb.add( - ZPowGate(exponent=(2**i) * self.exponent, eps=self.eps / len(out)), - q=out[-(i + 1)], + ZPowGate(exponent=(2**i) * self.exponent, eps=self.eps / len(out)), q=out[-(i + 1)] ) out = bb.join(out, dtype=QUInt(self.bitsize.bit_length())) soqs['x'] = bb.add( diff --git a/qualtran/bloqs/rotations/phasing_via_cost_function.py b/qualtran/bloqs/rotations/phasing_via_cost_function.py index e82b31a7a..7e4204a0d 100644 --- a/qualtran/bloqs/rotations/phasing_via_cost_function.py +++ b/qualtran/bloqs/rotations/phasing_via_cost_function.py @@ -68,6 +68,7 @@ class PhasingViaCostFunction(Bloq): [Compilation of Fault-Tolerant Quantum Heuristics for Combinatorial Optimization](https://arxiv.org/abs/2007.07391). Appendix C: Oracles for phasing by cost function """ + cost_eval_oracle: Bloq phase_oracle: QvrInterface diff --git a/qualtran/bloqs/rotations/phasing_via_cost_function_test.py b/qualtran/bloqs/rotations/phasing_via_cost_function_test.py index ebb8bdc18..a554f98fa 100644 --- a/qualtran/bloqs/rotations/phasing_via_cost_function_test.py +++ b/qualtran/bloqs/rotations/phasing_via_cost_function_test.py @@ -180,10 +180,7 @@ def test_square_phasing_via_phase_gradient( initial_state = np.array([1 / np.sqrt(2**n)] * 2**n) normalization_factor = 1 if normalize_cost_function else 4**n phases = np.array( - [ - np.exp(1j * 2 * np.pi * gamma * x**2 * normalization_factor / 4**n) - for x in range(2**n) - ] + [np.exp(1j * 2 * np.pi * gamma * x**2 * normalization_factor / 4**n) for x in range(2**n)] ) expected_final_state = np.multiply(initial_state, phases) test_bloq_one = TestSquarePhasing( diff --git a/qualtran/bloqs/rotations/programmable_ancilla_rotation.py b/qualtran/bloqs/rotations/programmable_ancilla_rotation.py index 07b6097e9..a1bd38569 100644 --- a/qualtran/bloqs/rotations/programmable_ancilla_rotation.py +++ b/qualtran/bloqs/rotations/programmable_ancilla_rotation.py @@ -36,6 +36,7 @@ class ZPowProgrammedAncilla(Bloq): Signature: q: the ancilla qubit prepared in the above state. """ + exponent: SymbolicFloat eps: SymbolicFloat = 1e-11 diff --git a/qualtran/bloqs/rotations/quantum_variable_rotation.py b/qualtran/bloqs/rotations/quantum_variable_rotation.py index 869882f96..5a254a4b4 100644 --- a/qualtran/bloqs/rotations/quantum_variable_rotation.py +++ b/qualtran/bloqs/rotations/quantum_variable_rotation.py @@ -98,13 +98,11 @@ class QvrInterface(GateWithRegisters, metaclass=abc.ABCMeta): @property @abc.abstractmethod - def cost_registers(self) -> Sequence[Register]: - ... + def cost_registers(self) -> Sequence[Register]: ... @property @abc.abstractmethod - def extra_registers(self) -> Sequence[Register]: - ... + def extra_registers(self) -> Sequence[Register]: ... @cached_property def signature(self) -> Signature: diff --git a/qualtran/bloqs/rotations/zpow_via_phase_gradient.py b/qualtran/bloqs/rotations/zpow_via_phase_gradient.py index 5e4e9c412..162de173a 100644 --- a/qualtran/bloqs/rotations/zpow_via_phase_gradient.py +++ b/qualtran/bloqs/rotations/zpow_via_phase_gradient.py @@ -64,6 +64,7 @@ class ZPowConstViaPhaseGradient(Bloq): [Improved quantum circuits for elliptic curve discrete logarithms](https://arxiv.org/abs/2001.09580). Haner et. al. 2020. Section 3: Components. "Integer addition" and Fig 2a. """ + exponent: SymbolicFloat phase_grad_bitsize: SymbolicInt diff --git a/qualtran/bloqs/state_preparation/prepare_base.py b/qualtran/bloqs/state_preparation/prepare_base.py index d918d43d0..6870d7752 100644 --- a/qualtran/bloqs/state_preparation/prepare_base.py +++ b/qualtran/bloqs/state_preparation/prepare_base.py @@ -38,8 +38,7 @@ class PrepareOracle(GateWithRegisters): @property @abc.abstractmethod - def selection_registers(self) -> Tuple[Register, ...]: - ... + def selection_registers(self) -> Tuple[Register, ...]: ... @cached_property def junk_registers(self) -> Tuple[Register, ...]: diff --git a/qualtran/bloqs/state_preparation/sparse_state_preparation_via_rotations.py b/qualtran/bloqs/state_preparation/sparse_state_preparation_via_rotations.py index 37939becf..c6d606e11 100644 --- a/qualtran/bloqs/state_preparation/sparse_state_preparation_via_rotations.py +++ b/qualtran/bloqs/state_preparation/sparse_state_preparation_via_rotations.py @@ -53,6 +53,7 @@ class SparseStatePreparationViaRotations(Bloq): [A simple quantum algorithm to efficiently prepare sparse states](https://arxiv.org/abs/2310.19309) Ramacciotti et. al. Section 4 "Permutation Grover-Rudolph". """ + sparse_indices: Union[tuple[int, ...], HasLength] = field(converter=_to_tuple_or_has_length) nonzero_coeffs: Union[tuple[complex, ...], HasLength] = field(converter=_to_tuple_or_has_length) N: SymbolicInt diff --git a/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py b/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py index 99bc134f0..9741eeec3 100644 --- a/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py +++ b/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py @@ -353,6 +353,7 @@ class SparseStatePreparationAliasSampling(PrepareOracle): [2] [Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity](https://arxiv.org/abs/1805.03662). Babbush et al. (2018). Section III.D. and Figure 11. """ + selection_registers: Tuple[Register, ...] = attrs.field( converter=lambda v: (v,) if isinstance(v, Register) else tuple(v) ) diff --git a/qualtran/bloqs/swap_network/multiplexed_cswap.py b/qualtran/bloqs/swap_network/multiplexed_cswap.py index 7872f45fa..d41e2bb20 100644 --- a/qualtran/bloqs/swap_network/multiplexed_cswap.py +++ b/qualtran/bloqs/swap_network/multiplexed_cswap.py @@ -57,6 +57,7 @@ class MultiplexedCSwap(UnaryIterationGate): [Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) page 20 paragraph 2. """ + selection_regs: Tuple[Register, ...] = field( converter=lambda v: (v,) if isinstance(v, Register) else tuple(v) ) diff --git a/qualtran/cirq_interop/_cirq_to_bloq.py b/qualtran/cirq_interop/_cirq_to_bloq.py index 447227a6b..7dd96fc7c 100644 --- a/qualtran/cirq_interop/_cirq_to_bloq.py +++ b/qualtran/cirq_interop/_cirq_to_bloq.py @@ -75,8 +75,7 @@ class CirqGateAsBloqBase(GateWithRegisters, metaclass=abc.ABCMeta): @property @abc.abstractmethod - def cirq_gate(self) -> cirq.Gate: - ... + def cirq_gate(self) -> cirq.Gate: ... @cached_property def signature(self) -> 'Signature': @@ -264,9 +263,9 @@ def _ensure_in_reg_exists( qubits_to_allocate: List[cirq.Qid] = [q for q in in_reg.qubits if q not in all_mapped_qubits] if qubits_to_allocate: n_alloc = len(qubits_to_allocate) - qreg_to_qvar[ - _QReg(qubits_to_allocate, dtype=QBit() if n_alloc == 1 else QAny(n_alloc)) - ] = bb.allocate(n_alloc) + qreg_to_qvar[_QReg(qubits_to_allocate, dtype=QBit() if n_alloc == 1 else QAny(n_alloc))] = ( + bb.allocate(n_alloc) + ) if in_reg in qreg_to_qvar: # This is the easy case when no split / joins are needed. diff --git a/qualtran/cirq_interop/t_complexity_protocol_test.py b/qualtran/cirq_interop/t_complexity_protocol_test.py index 2572b85ec..cf5d9166f 100644 --- a/qualtran/cirq_interop/t_complexity_protocol_test.py +++ b/qualtran/cirq_interop/t_complexity_protocol_test.py @@ -34,8 +34,7 @@ from qualtran.resource_counting import BloqCountT, SympySymbolAllocator -class DoesNotSupportTComplexity: - ... +class DoesNotSupportTComplexity: ... @frozen diff --git a/qualtran/drawing/_show_funcs.py b/qualtran/drawing/_show_funcs.py index 7760ebcd1..932a78ad6 100644 --- a/qualtran/drawing/_show_funcs.py +++ b/qualtran/drawing/_show_funcs.py @@ -81,15 +81,13 @@ def show_bloqs(bloqs: Sequence['Bloq'], labels: Optional[Sequence[Optional[str]] @overload def show_call_graph( item: 'Bloq', /, *, max_depth: Optional[int] = None, agg_gate_counts: Optional[str] = None -) -> None: - ... +) -> None: ... @overload def show_call_graph( item: 'nx.Graph', /, *, max_depth: Optional[int] = None, agg_gate_counts: Optional[str] = None -) -> None: - ... +) -> None: ... def show_call_graph( diff --git a/qualtran/linalg/lcu_util.py b/qualtran/linalg/lcu_util.py index aba500df7..fea17c03d 100644 --- a/qualtran/linalg/lcu_util.py +++ b/qualtran/linalg/lcu_util.py @@ -150,15 +150,13 @@ def _preprocess_for_efficient_roulette_selection( @overload -def sub_bit_prec_from_epsilon(number_of_coefficients: int, precision: float) -> int: - ... +def sub_bit_prec_from_epsilon(number_of_coefficients: int, precision: float) -> int: ... @overload def sub_bit_prec_from_epsilon( number_of_coefficients: SymbolicInt, precision: SymbolicFloat -) -> SymbolicInt: - ... +) -> SymbolicInt: ... def sub_bit_prec_from_epsilon( diff --git a/qualtran/surface_code/ccz2t_factory_test.py b/qualtran/surface_code/ccz2t_factory_test.py index 4bf7e9dab..5fd35ce68 100644 --- a/qualtran/surface_code/ccz2t_factory_test.py +++ b/qualtran/surface_code/ccz2t_factory_test.py @@ -19,9 +19,7 @@ def test_ccz_2t_factory(): factory = CCZ2TFactory() worse_factory = CCZ2TFactory(distillation_l1_d=7, distillation_l2_d=15) - alg = AlgorithmSummary( - n_logical_gates=GateCounts(t=10**8, toffoli=10**8), n_algo_qubits=100 - ) + alg = AlgorithmSummary(n_logical_gates=GateCounts(t=10**8, toffoli=10**8), n_algo_qubits=100) lem = LogicalErrorModel(qec_scheme=QECScheme.make_gidney_fowler(), physical_error=1e-3) err1 = factory.factory_error(n_logical_gates=alg.n_logical_gates, logical_error_model=lem) diff --git a/qualtran/symbolics/math_funcs.py b/qualtran/symbolics/math_funcs.py index 7ac2e496d..19473ad20 100644 --- a/qualtran/symbolics/math_funcs.py +++ b/qualtran/symbolics/math_funcs.py @@ -31,13 +31,11 @@ def pi(*args) -> SymbolicFloat: @overload -def log2(x: float) -> float: - ... +def log2(x: float) -> float: ... @overload -def log2(x: sympy.Expr) -> sympy.Expr: - ... +def log2(x: sympy.Expr) -> sympy.Expr: ... def log2(x: SymbolicFloat) -> SymbolicFloat: @@ -49,13 +47,11 @@ def log2(x: SymbolicFloat) -> SymbolicFloat: @overload -def ln(x: float) -> float: - ... +def ln(x: float) -> float: ... @overload -def ln(x: sympy.Expr) -> sympy.Expr: - ... +def ln(x: sympy.Expr) -> sympy.Expr: ... def ln(x: SymbolicFloat) -> SymbolicFloat: @@ -67,13 +63,11 @@ def ln(x: SymbolicFloat) -> SymbolicFloat: @overload -def sexp(x: complex) -> complex: - ... +def sexp(x: complex) -> complex: ... @overload -def sexp(x: sympy.Expr) -> sympy.Expr: - ... +def sexp(x: sympy.Expr) -> sympy.Expr: ... def sexp(x: SymbolicComplex) -> SymbolicComplex: @@ -83,13 +77,11 @@ def sexp(x: SymbolicComplex) -> SymbolicComplex: @overload -def sarg(x: complex) -> float: - ... +def sarg(x: complex) -> float: ... @overload -def sarg(x: sympy.Expr) -> sympy.Expr: - ... +def sarg(x: sympy.Expr) -> sympy.Expr: ... def sarg(x: SymbolicComplex) -> SymbolicFloat: @@ -100,13 +92,11 @@ def sarg(x: SymbolicComplex) -> SymbolicFloat: @overload -def sabs(x: float) -> float: - ... +def sabs(x: float) -> float: ... @overload -def sabs(x: sympy.Expr) -> sympy.Expr: - ... +def sabs(x: sympy.Expr) -> sympy.Expr: ... def sabs(x: SymbolicFloat) -> SymbolicFloat: @@ -114,13 +104,11 @@ def sabs(x: SymbolicFloat) -> SymbolicFloat: @overload -def ssqrt(x: float) -> float: - ... +def ssqrt(x: float) -> float: ... @overload -def ssqrt(x: sympy.Expr) -> sympy.Expr: - ... +def ssqrt(x: sympy.Expr) -> sympy.Expr: ... def ssqrt(x: SymbolicFloat) -> SymbolicFloat: @@ -130,13 +118,11 @@ def ssqrt(x: SymbolicFloat) -> SymbolicFloat: @overload -def ceil(x: float) -> int: - ... +def ceil(x: float) -> int: ... @overload -def ceil(x: sympy.Expr) -> sympy.Expr: - ... +def ceil(x: sympy.Expr) -> sympy.Expr: ... def ceil(x: SymbolicFloat) -> SymbolicInt: @@ -146,13 +132,11 @@ def ceil(x: SymbolicFloat) -> SymbolicInt: @overload -def floor(x: float) -> int: - ... +def floor(x: float) -> int: ... @overload -def floor(x: sympy.Expr) -> sympy.Expr: - ... +def floor(x: sympy.Expr) -> sympy.Expr: ... def floor(x: SymbolicFloat) -> SymbolicInt: @@ -162,13 +146,11 @@ def floor(x: SymbolicFloat) -> SymbolicInt: @overload -def bit_length(x: float) -> int: - ... +def bit_length(x: float) -> int: ... @overload -def bit_length(x: sympy.Expr) -> sympy.Expr: - ... +def bit_length(x: sympy.Expr) -> sympy.Expr: ... def bit_length(x: SymbolicFloat) -> SymbolicInt: @@ -253,13 +235,11 @@ def ssum(args: Iterable[SymbolicT]) -> SymbolicT: @overload -def acos(x: float) -> float: - ... +def acos(x: float) -> float: ... @overload -def acos(x: sympy.Expr) -> sympy.Expr: - ... +def acos(x: sympy.Expr) -> sympy.Expr: ... def acos(x: SymbolicFloat) -> SymbolicFloat: @@ -269,13 +249,11 @@ def acos(x: SymbolicFloat) -> SymbolicFloat: @overload -def sconj(x: complex) -> complex: - ... +def sconj(x: complex) -> complex: ... @overload -def sconj(x: sympy.Expr) -> sympy.Expr: - ... +def sconj(x: sympy.Expr) -> sympy.Expr: ... def sconj(x: SymbolicComplex) -> SymbolicComplex: @@ -284,13 +262,11 @@ def sconj(x: SymbolicComplex) -> SymbolicComplex: @overload -def slen(x: Sized) -> int: - ... +def slen(x: Sized) -> int: ... @overload -def slen(x: Union[Shaped, HasLength]) -> sympy.Expr: - ... +def slen(x: Union[Shaped, HasLength]) -> sympy.Expr: ... def slen(x: Union[Sized, Shaped, HasLength]) -> SymbolicInt: @@ -302,13 +278,11 @@ def slen(x: Union[Sized, Shaped, HasLength]) -> SymbolicInt: @overload -def shape(x: np.ndarray) -> Tuple[int, ...]: - ... +def shape(x: np.ndarray) -> Tuple[int, ...]: ... @overload -def shape(x: Shaped) -> Tuple[SymbolicInt, ...]: - ... +def shape(x: Shaped) -> Tuple[SymbolicInt, ...]: ... def shape(x: Union[np.ndarray, Shaped]): diff --git a/qualtran/symbolics/types.py b/qualtran/symbolics/types.py index 3bc42e229..b9f017fc0 100644 --- a/qualtran/symbolics/types.py +++ b/qualtran/symbolics/types.py @@ -70,13 +70,11 @@ def is_symbolic(self): @overload def is_symbolic( arg: Union[T, sympy.Expr, Shaped, HasLength], / -) -> TypeIs[Union[sympy.Expr, Shaped, HasLength]]: - ... +) -> TypeIs[Union[sympy.Expr, Shaped, HasLength]]: ... @overload -def is_symbolic(*args) -> bool: - ... +def is_symbolic(*args) -> bool: ... def is_symbolic(*args) -> Union[TypeIs[Union[sympy.Expr, Shaped, HasLength]], bool]: