From 89d3d3b387c16a68f698f58d73dab189f2da65d7 Mon Sep 17 00:00:00 2001 From: Fionn Malone Date: Thu, 29 Aug 2024 21:52:29 +0000 Subject: [PATCH 1/3] BoundedQUInt -> BQUInt. --- qualtran/__init__.py | 2 +- qualtran/_infra/composite_bloq_test.py | 6 +- qualtran/_infra/data_types.py | 12 ++-- qualtran/_infra/data_types_test.py | 42 +++++++------- qualtran/_infra/registers_test.py | 18 +++--- qualtran/bloqs/arithmetic/permutation.py | 6 +- .../block_encoding/linear_combination.py | 4 +- .../bloqs/block_encoding/sparse_matrix.py | 4 +- .../qubitization/prepare_hubbard.py | 18 +++--- .../qubitization/select_hubbard.py | 42 ++++++-------- .../projectile/select_and_prepare.py | 58 +++++++++---------- .../first_quantization/select_and_prepare.py | 52 ++++++++--------- .../chemistry/sf/single_factorization.py | 15 +++-- qualtran/bloqs/chemistry/sparse/prepare.py | 18 +++--- .../bloqs/chemistry/sparse/select_bloq.py | 25 +++----- qualtran/bloqs/chemistry/thc/prepare.py | 22 ++++--- qualtran/bloqs/chemistry/thc/select_bloq.py | 22 ++++--- .../chemistry/trotter/grid_ham/potential.py | 4 +- .../bloqs/chemistry/writing_algorithms.ipynb | 46 +++++++-------- qualtran/bloqs/data_loading/qrom_base.py | 4 +- .../bloqs/data_loading/select_swap_qrom.py | 6 +- qualtran/bloqs/for_testing/many_registers.py | 6 +- .../for_testing/qubitization_walk_test.py | 4 +- .../for_testing/random_select_and_prepare.py | 8 +-- qualtran/bloqs/mcmt/ctrl_spec_and.py | 6 +- .../mean_estimation_operator_test.py | 6 +- .../apply_gate_to_lth_target.ipynb | 4 +- .../multiplexers/apply_gate_to_lth_target.py | 8 +-- .../apply_gate_to_lth_target_test.py | 10 ++-- qualtran/bloqs/multiplexers/apply_lth_bloq.py | 4 +- .../bloqs/multiplexers/apply_lth_bloq_test.py | 21 ++----- .../bloqs/multiplexers/select_pauli_lcu.py | 6 +- .../multiplexers/selected_majorana_fermion.py | 6 +- .../selected_majorana_fermion_test.py | 11 ++-- .../bloqs/multiplexers/unary_iteration.ipynb | 4 +- .../multiplexers/unary_iteration_bloq_test.py | 9 ++- .../programmable_rotation_gate_array.py | 4 +- .../state_preparation_alias_sampling.py | 10 ++-- .../bloqs/swap_network/multiplexed_cswap.py | 4 +- .../swap_network/multiplexed_cswap_test.py | 8 +-- .../bloqs/swap_network/swap_network.ipynb | 4 +- qualtran/bloqs/swap_network/swap_with_zero.py | 4 +- qualtran/drawing/qpic_diagram_test.py | 2 +- qualtran/serialization/data_types.py | 24 ++------ qualtran/serialization/data_types_test.py | 14 +---- 45 files changed, 274 insertions(+), 339 deletions(-) diff --git a/qualtran/__init__.py b/qualtran/__init__.py index 6b24feaca..6f04267a3 100644 --- a/qualtran/__init__.py +++ b/qualtran/__init__.py @@ -51,7 +51,7 @@ QFxp, QIntOnesComp, QUInt, - BoundedQUInt, + BQUInt, QMontgomeryUInt, ) diff --git a/qualtran/_infra/composite_bloq_test.py b/qualtran/_infra/composite_bloq_test.py index f326a357e..5685641ab 100644 --- a/qualtran/_infra/composite_bloq_test.py +++ b/qualtran/_infra/composite_bloq_test.py @@ -39,7 +39,7 @@ SoquetT, ) from qualtran._infra.composite_bloq import _create_binst_graph, _get_dangling_soquets -from qualtran._infra.data_types import BoundedQUInt, QAny, QBit, QFxp, QUInt +from qualtran._infra.data_types import BQUInt, QAny, QBit, QFxp, QUInt from qualtran.bloqs.basic_gates import CNOT, IntEffect, ZeroEffect from qualtran.bloqs.bookkeeping import Join from qualtran.bloqs.for_testing.atom import TestAtom, TestTwoBitOp @@ -515,7 +515,7 @@ def test_flatten(): def test_type_error(): bb = BloqBuilder() - a = bb.add_register_from_dtype('i', BoundedQUInt(4, 3)) + a = bb.add_register_from_dtype('i', BQUInt(4, 3)) b = bb.add_register_from_dtype('j', QFxp(8, 6, True)) c = bb.add_register_from_dtype('k', QFxp(8, 8)) d = bb.add_register_from_dtype('l', QUInt(8)) @@ -527,7 +527,7 @@ def test_type_error(): with pytest.raises(BloqError, match=r'.*register dtypes are not consistent.*'): b, a = bb.add(TestQFxp(), xx=b, yy=a) bb = BloqBuilder() - a = bb.add_register_from_dtype('i', BoundedQUInt(4, 3)) + a = bb.add_register_from_dtype('i', BQUInt(4, 3)) b = bb.add_register_from_dtype('j', QFxp(8, 6, True)) c = bb.add_register_from_dtype('k', QFxp(8, 8)) d = bb.add_register_from_dtype('l', QUInt(8)) diff --git a/qualtran/_infra/data_types.py b/qualtran/_infra/data_types.py index f9667a464..5ea2ac1f8 100644 --- a/qualtran/_infra/data_types.py +++ b/qualtran/_infra/data_types.py @@ -413,12 +413,12 @@ def __str__(self): @attrs.frozen -class BoundedQUInt(QDType): +class BQUInt(QDType): """Unsigned integer whose values are bounded within a range. LCU methods often make use of coherent for-loops via UnaryIteration, iterating over a range of values stored as a superposition over the `SELECT` register. Such (nested) coherent - for-loops can be represented using a `Tuple[Register(dtype=BoundedQUInt), + for-loops can be represented using a `Tuple[Register(dtype=BQUInt), ...]` where the i'th entry stores the bitsize and iteration length of i'th nested for-loop. @@ -466,7 +466,7 @@ def __attrs_post_init__(self): if not self.is_symbolic(): if self.iteration_length > 2**self.bitsize: raise ValueError( - "BoundedQUInt iteration length is too large for given bitsize. " + "BQUInt iteration length is too large for given bitsize. " f"{self.iteration_length} vs {2**self.bitsize}" ) @@ -810,8 +810,8 @@ def assert_valid_classical_val_array( raise ValueError(f"Too-large classical values encountered in {debug_str}") -QAnyInt = (QInt, QUInt, BoundedQUInt, QMontgomeryUInt) -QAnyUInt = (QUInt, BoundedQUInt, QMontgomeryUInt) +QAnyInt = (QInt, QUInt, BQUInt, QMontgomeryUInt) +QAnyUInt = (QUInt, BQUInt, QMontgomeryUInt) class QDTypeCheckingSeverity(Enum): @@ -827,7 +827,7 @@ class QDTypeCheckingSeverity(Enum): """Strictly enforce type checking between registers. Only single bit conversions are allowed.""" -def _check_uint_fxp_consistent(a: Union[QUInt, BoundedQUInt, QMontgomeryUInt], b: QFxp) -> bool: +def _check_uint_fxp_consistent(a: Union[QUInt, BQUInt, QMontgomeryUInt], b: QFxp) -> bool: """A uint / qfxp is consistent with a whole or totally fractional unsigned QFxp.""" if b.signed: return False diff --git a/qualtran/_infra/data_types_test.py b/qualtran/_infra/data_types_test.py index a59ba43ce..1dc0ced33 100644 --- a/qualtran/_infra/data_types_test.py +++ b/qualtran/_infra/data_types_test.py @@ -24,7 +24,7 @@ from qualtran.symbolics import is_symbolic from .data_types import ( - BoundedQUInt, + BQUInt, check_dtypes_consistent, QAny, QAnyInt, @@ -75,21 +75,21 @@ def test_quint(): def test_bounded_quint(): - qint_3 = BoundedQUInt(2, 3) - assert str(qint_3) == 'BoundedQUInt(2, 3)' + qint_3 = BQUInt(2, 3) + assert str(qint_3) == 'BQUInt(2, 3)' assert qint_3.bitsize == 2 assert qint_3.iteration_length == 3 - with pytest.raises(ValueError, match="BoundedQUInt iteration length.*"): - BoundedQUInt(4, 76) + with pytest.raises(ValueError, match="BQUInt iteration length.*"): + BQUInt(4, 76) n = sympy.symbols('x') l = sympy.symbols('l') - qint_8 = BoundedQUInt(n, l) + qint_8 = BQUInt(n, l) assert qint_8.num_qubits == n assert qint_8.iteration_length == l - assert is_symbolic(BoundedQUInt(sympy.Symbol('x'), 2)) - assert is_symbolic(BoundedQUInt(2, sympy.Symbol('x'))) - assert is_symbolic(BoundedQUInt(*sympy.symbols('x y'))) + assert is_symbolic(BQUInt(sympy.Symbol('x'), 2)) + assert is_symbolic(BQUInt(2, sympy.Symbol('x'))) + assert is_symbolic(BQUInt(*sympy.symbols('x y'))) def test_qfxp(): @@ -135,13 +135,13 @@ def test_qmontgomeryuint(): assert is_symbolic(QMontgomeryUInt(sympy.Symbol('x'))) -@pytest.mark.parametrize('qdtype', [QBit(), QInt(4), QUInt(4), BoundedQUInt(3, 5)]) +@pytest.mark.parametrize('qdtype', [QBit(), QInt(4), QUInt(4), BQUInt(3, 5)]) def test_domain_and_validation(qdtype: QDType): for v in qdtype.get_classical_domain(): qdtype.assert_valid_classical_val(v) -@pytest.mark.parametrize('qdtype', [QBit(), QInt(4), QUInt(4), BoundedQUInt(3, 5)]) +@pytest.mark.parametrize('qdtype', [QBit(), QInt(4), QUInt(4), BQUInt(3, 5)]) def test_domain_and_validation_arr(qdtype: QDType): arr = np.array(list(qdtype.get_classical_domain())) qdtype.assert_valid_classical_val_array(arr) @@ -158,10 +158,10 @@ def test_validation_errs(): QUInt(3).assert_valid_classical_val(8) with pytest.raises(ValueError): - BoundedQUInt(3, 5).assert_valid_classical_val(-1) + BQUInt(3, 5).assert_valid_classical_val(-1) with pytest.raises(ValueError): - BoundedQUInt(3, 5).assert_valid_classical_val(6) + BQUInt(3, 5).assert_valid_classical_val(6) with pytest.raises(ValueError): QInt(4).assert_valid_classical_val(-9) @@ -183,15 +183,13 @@ def test_validate_arrays(): QBit().assert_valid_classical_val_array(arr) -@pytest.mark.parametrize( - 'qdtype', [QIntOnesComp(4), QFxp(4, 4), QInt(4), QUInt(4), BoundedQUInt(4, 5)] -) +@pytest.mark.parametrize('qdtype', [QIntOnesComp(4), QFxp(4, 4), QInt(4), QUInt(4), BQUInt(4, 5)]) def test_qany_consistency(qdtype): # All Types with correct bitsize are ok with QAny assert check_dtypes_consistent(qdtype, QAny(4)) -@pytest.mark.parametrize('qdtype', [QUInt(4), BoundedQUInt(4, 5), QMontgomeryUInt(4)]) +@pytest.mark.parametrize('qdtype', [QUInt(4), BQUInt(4, 5), QMontgomeryUInt(4)]) def test_type_errors_fxp_uint(qdtype): assert check_dtypes_consistent(qdtype, QFxp(4, 4)) assert check_dtypes_consistent(qdtype, QFxp(4, 0)) @@ -213,10 +211,10 @@ def test_type_errors_fxp(): @pytest.mark.parametrize( - 'qdtype_a', [QUInt(4), BoundedQUInt(4, 5), QMontgomeryUInt(4), QInt(4), QIntOnesComp(4)] + 'qdtype_a', [QUInt(4), BQUInt(4, 5), QMontgomeryUInt(4), QInt(4), QIntOnesComp(4)] ) @pytest.mark.parametrize( - 'qdtype_b', [QUInt(4), BoundedQUInt(4, 5), QMontgomeryUInt(4), QInt(4), QIntOnesComp(4)] + 'qdtype_b', [QUInt(4), BQUInt(4, 5), QMontgomeryUInt(4), QInt(4), QIntOnesComp(4)] ) def test_type_errors_matrix(qdtype_a, qdtype_b): if qdtype_a == qdtype_b: @@ -233,7 +231,7 @@ def test_single_qubit_consistency(): assert check_dtypes_consistent(QBit(), QInt(1)) assert check_dtypes_consistent(QInt(1), QBit()) assert check_dtypes_consistent(QAny(1), QBit()) - assert check_dtypes_consistent(BoundedQUInt(1), QBit()) + assert check_dtypes_consistent(BQUInt(1), QBit()) assert check_dtypes_consistent(QFxp(1, 1), QBit()) @@ -313,11 +311,11 @@ def test_int_to_bits(): def test_bounded_quint_to_and_from_bits(): - bquint4 = BoundedQUInt(4, 12) + bquint4 = BQUInt(4, 12) assert [*bquint4.get_classical_domain()] == [*range(0, 12)] assert list(bquint4.to_bits(10)) == [1, 0, 1, 0] with pytest.raises(ValueError): - BoundedQUInt(4, 12).to_bits(13) + BQUInt(4, 12).to_bits(13) assert_to_and_from_bits_array_consistent(bquint4, range(0, 12)) diff --git a/qualtran/_infra/registers_test.py b/qualtran/_infra/registers_test.py index 33419a1ac..8beb0163a 100644 --- a/qualtran/_infra/registers_test.py +++ b/qualtran/_infra/registers_test.py @@ -17,7 +17,7 @@ import pytest import sympy -from qualtran import BoundedQUInt, QAny, QBit, QInt, Register, Side, Signature +from qualtran import BQUInt, QAny, QBit, QInt, Register, Side, Signature from qualtran._infra.gate_with_registers import get_named_qubits from qualtran.symbolics import is_symbolic @@ -47,7 +47,7 @@ def test_multidim_register(): @pytest.mark.parametrize('n, N, m, M', [(4, 10, 5, 19), (4, 16, 5, 32)]) def test_selection_registers_indexing(n, N, m, M): - dtypes = [BoundedQUInt(n, N), BoundedQUInt(m, M)] + dtypes = [BQUInt(n, N), BQUInt(m, M)] regs = [Register(sym, dtype) for sym, dtype in zip(['x', 'y'], dtypes)] for x in range(int(dtypes[0].iteration_length)): for y in range(int(dtypes[1].iteration_length)): @@ -59,17 +59,17 @@ def test_selection_registers_indexing(n, N, m, M): def test_selection_registers_consistent(): with pytest.raises(ValueError, match=".*iteration length is too large "): - _ = Register('a', BoundedQUInt(3, 10)) + _ = Register('a', BQUInt(3, 10)) selection_reg = Signature( [ - Register('n', BoundedQUInt(bitsize=3, iteration_length=5)), - Register('m', BoundedQUInt(bitsize=4, iteration_length=12)), + Register('n', BQUInt(bitsize=3, iteration_length=5)), + Register('m', BQUInt(bitsize=4, iteration_length=12)), ] ) - assert selection_reg[0] == Register('n', BoundedQUInt(3, 5)) - assert selection_reg[1] == Register('m', BoundedQUInt(4, 12)) - assert selection_reg[:1] == tuple([Register('n', BoundedQUInt(3, 5))]) + assert selection_reg[0] == Register('n', BQUInt(3, 5)) + assert selection_reg[1] == Register('m', BQUInt(4, 12)) + assert selection_reg[:1] == tuple([Register('n', BQUInt(3, 5))]) def test_registers_getitem_raises(): @@ -77,7 +77,7 @@ def test_registers_getitem_raises(): with pytest.raises(TypeError, match="indices must be integers or slices"): _ = g[2.5] # type: ignore[call-overload] - selection_reg = Signature([Register('n', BoundedQUInt(bitsize=3, iteration_length=5))]) + selection_reg = Signature([Register('n', BQUInt(bitsize=3, iteration_length=5))]) with pytest.raises(TypeError, match='indices must be integers or slices'): _ = selection_reg[2.5] # type: ignore[call-overload] diff --git a/qualtran/bloqs/arithmetic/permutation.py b/qualtran/bloqs/arithmetic/permutation.py index 5c737228f..7deb8fabc 100644 --- a/qualtran/bloqs/arithmetic/permutation.py +++ b/qualtran/bloqs/arithmetic/permutation.py @@ -32,7 +32,7 @@ Bloq, bloq_example, BloqDocSpec, - BoundedQUInt, + BQUInt, DecomposeTypeError, QBit, QUInt, @@ -98,7 +98,7 @@ class PermutationCycle(Bloq): @cached_property def signature(self) -> Signature: - return Signature.build_from_dtypes(x=BoundedQUInt(self.bitsize, self.N)) + return Signature.build_from_dtypes(x=BQUInt(self.bitsize, self.N)) @cached_property def bitsize(self): @@ -199,7 +199,7 @@ class Permutation(Bloq): @cached_property def signature(self) -> Signature: - return Signature.build_from_dtypes(x=BoundedQUInt(self.bitsize, self.N)) + return Signature.build_from_dtypes(x=BQUInt(self.bitsize, self.N)) @cached_property def bitsize(self): diff --git a/qualtran/bloqs/block_encoding/linear_combination.py b/qualtran/bloqs/block_encoding/linear_combination.py index 5bb6c2d12..d21301645 100644 --- a/qualtran/bloqs/block_encoding/linear_combination.py +++ b/qualtran/bloqs/block_encoding/linear_combination.py @@ -23,7 +23,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, QAny, Register, Signature, @@ -201,7 +201,7 @@ def prepare(self) -> BlackBoxPrepare: # disable spurious pylint # pylint: disable=abstract-class-instantiated prep = StatePreparationAliasSampling( - selection_registers=Register('selection', BoundedQUInt((N - 1).bit_length(), N)), + selection_registers=Register('selection', BQUInt((N - 1).bit_length(), N)), alt=np.array(alt), keep=np.array(keep), mu=mu, diff --git a/qualtran/bloqs/block_encoding/sparse_matrix.py b/qualtran/bloqs/block_encoding/sparse_matrix.py index 31abc8398..002e5246a 100644 --- a/qualtran/bloqs/block_encoding/sparse_matrix.py +++ b/qualtran/bloqs/block_encoding/sparse_matrix.py @@ -26,7 +26,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, DecomposeTypeError, QAny, QBit, @@ -94,7 +94,7 @@ def __attrs_post_init__(self): @cached_property def signature(self) -> Signature: return Signature.build_from_dtypes( - l=BoundedQUInt(self.system_bitsize, self.num_nonzero), i=QUInt(self.system_bitsize) + l=BQUInt(self.system_bitsize, self.num_nonzero), i=QUInt(self.system_bitsize) ) diff --git a/qualtran/bloqs/chemistry/hubbard_model/qubitization/prepare_hubbard.py b/qualtran/bloqs/chemistry/hubbard_model/qubitization/prepare_hubbard.py index bb8c1eb5f..cfdbf20b0 100644 --- a/qualtran/bloqs/chemistry/hubbard_model/qubitization/prepare_hubbard.py +++ b/qualtran/bloqs/chemistry/hubbard_model/qubitization/prepare_hubbard.py @@ -20,7 +20,7 @@ import numpy as np from numpy.typing import NDArray -from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, QAny, Register, Signature +from qualtran import bloq_example, BloqDocSpec, BQUInt, QAny, Register, Signature from qualtran.bloqs.basic_gates import CSwap from qualtran.bloqs.mcmt.and_bloq import MultiAnd from qualtran.bloqs.mod_arithmetic import ModAddK @@ -81,14 +81,14 @@ def __attrs_post_init__(self): @cached_property def selection_registers(self) -> Tuple[Register, ...]: return ( - Register('U', BoundedQUInt(1, 2)), - Register('V', BoundedQUInt(1, 2)), - Register('p_x', BoundedQUInt((self.x_dim - 1).bit_length(), self.x_dim)), - Register('p_y', BoundedQUInt((self.y_dim - 1).bit_length(), self.y_dim)), - Register('alpha', BoundedQUInt(1, 2)), - Register('q_x', BoundedQUInt((self.x_dim - 1).bit_length(), self.x_dim)), - Register('q_y', BoundedQUInt((self.y_dim - 1).bit_length(), self.y_dim)), - Register('beta', BoundedQUInt(1, 2)), + Register('U', BQUInt(1, 2)), + Register('V', BQUInt(1, 2)), + Register('p_x', BQUInt((self.x_dim - 1).bit_length(), self.x_dim)), + Register('p_y', BQUInt((self.y_dim - 1).bit_length(), self.y_dim)), + Register('alpha', BQUInt(1, 2)), + Register('q_x', BQUInt((self.x_dim - 1).bit_length(), self.x_dim)), + Register('q_y', BQUInt((self.y_dim - 1).bit_length(), self.y_dim)), + Register('beta', BQUInt(1, 2)), ) @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 ec5bd4e0a..efa0c9e7c 100644 --- a/qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard.py +++ b/qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard.py @@ -20,7 +20,7 @@ import numpy as np from numpy.typing import NDArray -from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, QAny, QBit, Register, Signature +from qualtran import bloq_example, BloqDocSpec, BQUInt, QAny, QBit, Register, Signature from qualtran._infra.gate_with_registers import total_bits from qualtran._infra.single_qubit_controlled import SpecializedSingleQubitControlledExtension from qualtran.bloqs.basic_gates import CSwap @@ -88,14 +88,14 @@ def control_registers(self) -> Tuple[Register, ...]: @cached_property def selection_registers(self) -> Tuple[Register, ...]: return ( - Register('U', BoundedQUInt(1, 2)), - Register('V', BoundedQUInt(1, 2)), - Register('p_x', BoundedQUInt((self.x_dim - 1).bit_length(), self.x_dim)), - Register('p_y', BoundedQUInt((self.y_dim - 1).bit_length(), self.y_dim)), - Register('alpha', BoundedQUInt(1, 2)), - Register('q_x', BoundedQUInt((self.x_dim - 1).bit_length(), self.x_dim)), - Register('q_y', BoundedQUInt((self.y_dim - 1).bit_length(), self.y_dim)), - Register('beta', BoundedQUInt(1, 2)), + Register('U', BQUInt(1, 2)), + Register('V', BQUInt(1, 2)), + Register('p_x', BQUInt((self.x_dim - 1).bit_length(), self.x_dim)), + Register('p_y', BQUInt((self.y_dim - 1).bit_length(), self.y_dim)), + Register('alpha', BQUInt(1, 2)), + Register('q_x', BQUInt((self.x_dim - 1).bit_length(), self.x_dim)), + Register('q_y', BQUInt((self.y_dim - 1).bit_length(), self.y_dim)), + Register('beta', BQUInt(1, 2)), ) @cached_property @@ -120,13 +120,9 @@ def decompose_from_registers( yield SelectedMajoranaFermion( selection_regs=( - Register('alpha', BoundedQUInt(1, 2)), - Register( - 'p_y', BoundedQUInt(self.signature.get_left('p_y').total_bits(), self.y_dim) - ), - Register( - 'p_x', BoundedQUInt(self.signature.get_left('p_x').total_bits(), self.x_dim) - ), + Register('alpha', BQUInt(1, 2)), + Register('p_y', BQUInt(self.signature.get_left('p_y').total_bits(), self.y_dim)), + Register('p_x', BQUInt(self.signature.get_left('p_x').total_bits(), self.x_dim)), ), control_regs=self.control_registers, target_gate=cirq.Y, @@ -137,9 +133,9 @@ def decompose_from_registers( yield CSwap.make_on(ctrl=V, x=alpha, y=beta) q_selection_regs = ( - Register('beta', BoundedQUInt(1, 2)), - Register('q_y', BoundedQUInt(self.signature.get_left('q_y').total_bits(), self.y_dim)), - Register('q_x', BoundedQUInt(self.signature.get_left('q_x').total_bits(), self.x_dim)), + Register('beta', BQUInt(1, 2)), + Register('q_y', BQUInt(self.signature.get_left('q_y').total_bits(), self.y_dim)), + Register('q_x', BQUInt(self.signature.get_left('q_x').total_bits(), self.x_dim)), ) yield SelectedMajoranaFermion( selection_regs=q_selection_regs, control_regs=self.control_registers, target_gate=cirq.X @@ -162,12 +158,8 @@ def decompose_from_registers( yield ApplyGateToLthQubit( selection_regs=( - Register( - 'q_y', BoundedQUInt(self.signature.get_left('q_y').total_bits(), self.y_dim) - ), - Register( - 'q_x', BoundedQUInt(self.signature.get_left('q_x').total_bits(), self.x_dim) - ), + Register('q_y', BQUInt(self.signature.get_left('q_y').total_bits(), self.y_dim)), + Register('q_x', BQUInt(self.signature.get_left('q_x').total_bits(), self.x_dim)), ), nth_gate=lambda *_: cirq.Z, control_regs=Register('control', QAny(1 + total_bits(self.control_registers))), 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 e4ba5a02e..93dbf744f 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 @@ -24,7 +24,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, QAny, QBit, Register, @@ -132,7 +132,7 @@ def signature(self) -> Signature: return Signature( [ Register('ctrl', QBit(), shape=(len(self.cvs),)), - Register('sel', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register('sel', BQUInt(bitsize=n_eta, iteration_length=self.eta)), Register('targets', QAny(bitsize=self.num_bits_p), shape=(self.eta, 3)), Register('junk', QAny(bitsize=self.num_bits_n), shape=(3,)), ] @@ -257,21 +257,21 @@ def selection_registers(self) -> Tuple[Register, ...]: # overflow: 3 * 2 qubits are missing. # l: should not be reflected on. return ( - Register('tuv', BoundedQUInt(bitsize=1, iteration_length=2)), - Register('tepm', BoundedQUInt(bitsize=2, iteration_length=3)), - Register('uv', BoundedQUInt(bitsize=2, iteration_length=4)), - Register('i', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register('j', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register("w", BoundedQUInt(iteration_length=3, bitsize=2)), - Register("w_mean", BoundedQUInt(iteration_length=3, bitsize=2)), - Register("r", BoundedQUInt(bitsize=self.num_bits_n)), - Register("s", BoundedQUInt(bitsize=self.num_bits_n)), - Register("mu", BoundedQUInt(bitsize=self.num_bits_n)), - Register("nu_x", BoundedQUInt(bitsize=n_nu)), - Register("nu_y", BoundedQUInt(bitsize=n_nu)), - Register("nu_z", BoundedQUInt(bitsize=n_nu)), - Register("m", BoundedQUInt(bitsize=n_m)), - Register("l", BoundedQUInt(bitsize=n_at)), + Register('tuv', BQUInt(bitsize=1, iteration_length=2)), + Register('tepm', BQUInt(bitsize=2, iteration_length=3)), + Register('uv', BQUInt(bitsize=2, iteration_length=4)), + Register('i', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register('j', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register("w", BQUInt(iteration_length=3, bitsize=2)), + Register("w_mean", BQUInt(iteration_length=3, bitsize=2)), + Register("r", BQUInt(bitsize=self.num_bits_n)), + Register("s", BQUInt(bitsize=self.num_bits_n)), + Register("mu", BQUInt(bitsize=self.num_bits_n)), + Register("nu_x", BQUInt(bitsize=n_nu)), + Register("nu_y", BQUInt(bitsize=n_nu)), + Register("nu_z", BQUInt(bitsize=n_nu)), + Register("m", BQUInt(bitsize=n_m)), + Register("l", BQUInt(bitsize=n_at)), ) @cached_property @@ -434,18 +434,18 @@ def selection_registers(self) -> Tuple[Register, ...]: n_at = (self.num_atoms - 1).bit_length() n_m = (self.m_param - 1).bit_length() return ( - Register('i', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register('j', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register("w", BoundedQUInt(bitsize=3)), - Register("w_mean", BoundedQUInt(bitsize=3)), - Register("r", BoundedQUInt(bitsize=self.num_bits_n)), - Register("s", BoundedQUInt(bitsize=self.num_bits_n)), - Register("mu", BoundedQUInt(bitsize=self.num_bits_n)), - Register("nu_x", BoundedQUInt(bitsize=n_nu)), - Register("nu_y", BoundedQUInt(bitsize=n_nu)), - Register("nu_z", BoundedQUInt(bitsize=n_nu)), - Register("m", BoundedQUInt(bitsize=n_m)), - Register("l", BoundedQUInt(bitsize=n_at)), + Register('i', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register('j', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register("w", BQUInt(bitsize=3)), + Register("w_mean", BQUInt(bitsize=3)), + Register("r", BQUInt(bitsize=self.num_bits_n)), + Register("s", BQUInt(bitsize=self.num_bits_n)), + Register("mu", BQUInt(bitsize=self.num_bits_n)), + Register("nu_x", BQUInt(bitsize=n_nu)), + Register("nu_y", BQUInt(bitsize=n_nu)), + Register("nu_z", BQUInt(bitsize=n_nu)), + Register("m", BQUInt(bitsize=n_m)), + Register("l", BQUInt(bitsize=n_at)), ) @cached_property 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 98478b0c5..8303440ea 100644 --- a/qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare.py +++ b/qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare.py @@ -24,7 +24,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, QAny, QBit, Register, @@ -126,7 +126,7 @@ def signature(self) -> Signature: n_eta = (self.eta - 1).bit_length() return Signature( [ - Register('sel', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register('sel', BQUInt(bitsize=n_eta, iteration_length=self.eta)), Register('targets', QAny(bitsize=self.num_bits_p), shape=(self.eta, 3)), Register('junk', QAny(bitsize=self.num_bits_p), shape=(3,)), ] @@ -255,19 +255,19 @@ def selection_registers(self) -> Tuple[Register, ...]: # overflow: 3 * 2 qubits are missing. # l: should not be reflected on. return ( - Register('tuv', BoundedQUInt(bitsize=1, iteration_length=2)), - Register('uv', BoundedQUInt(bitsize=1, iteration_length=2)), - Register('i', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register('j', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register("w", BoundedQUInt(iteration_length=3, bitsize=2)), - Register("r", BoundedQUInt(bitsize=self.num_bits_p)), - Register("s", BoundedQUInt(bitsize=self.num_bits_p)), - Register("mu", BoundedQUInt(bitsize=self.num_bits_p)), - Register("nu_x", BoundedQUInt(bitsize=n_nu)), - Register("nu_y", BoundedQUInt(bitsize=n_nu)), - Register("nu_z", BoundedQUInt(bitsize=n_nu)), - Register("m", BoundedQUInt(bitsize=n_m)), - Register("l", BoundedQUInt(bitsize=n_at, iteration_length=n_at)), + Register('tuv', BQUInt(bitsize=1, iteration_length=2)), + Register('uv', BQUInt(bitsize=1, iteration_length=2)), + Register('i', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register('j', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register("w", BQUInt(iteration_length=3, bitsize=2)), + Register("r", BQUInt(bitsize=self.num_bits_p)), + Register("s", BQUInt(bitsize=self.num_bits_p)), + Register("mu", BQUInt(bitsize=self.num_bits_p)), + Register("nu_x", BQUInt(bitsize=n_nu)), + Register("nu_y", BQUInt(bitsize=n_nu)), + Register("nu_z", BQUInt(bitsize=n_nu)), + Register("m", BQUInt(bitsize=n_m)), + Register("l", BQUInt(bitsize=n_at, iteration_length=n_at)), ) @cached_property @@ -424,17 +424,17 @@ def selection_registers(self) -> Tuple[Register, ...]: n_at = (self.num_atoms - 1).bit_length() n_m = (self.m_param - 1).bit_length() return ( - Register('i', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register('j', BoundedQUInt(bitsize=n_eta, iteration_length=self.eta)), - Register("w", BoundedQUInt(bitsize=3)), - Register("r", BoundedQUInt(bitsize=self.num_bits_p)), - Register("s", BoundedQUInt(bitsize=self.num_bits_p)), - Register("mu", BoundedQUInt(bitsize=self.num_bits_p)), - Register("nu_x", BoundedQUInt(bitsize=n_nu)), - Register("nu_y", BoundedQUInt(bitsize=n_nu)), - Register("nu_z", BoundedQUInt(bitsize=n_nu)), - Register("m", BoundedQUInt(bitsize=n_m)), - Register("l", BoundedQUInt(bitsize=n_at)), + Register('i', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register('j', BQUInt(bitsize=n_eta, iteration_length=self.eta)), + Register("w", BQUInt(bitsize=3)), + Register("r", BQUInt(bitsize=self.num_bits_p)), + Register("s", BQUInt(bitsize=self.num_bits_p)), + Register("mu", BQUInt(bitsize=self.num_bits_p)), + Register("nu_x", BQUInt(bitsize=n_nu)), + Register("nu_y", BQUInt(bitsize=n_nu)), + Register("nu_z", BQUInt(bitsize=n_nu)), + Register("m", BQUInt(bitsize=n_m)), + Register("l", BQUInt(bitsize=n_at)), ) @cached_property diff --git a/qualtran/bloqs/chemistry/sf/single_factorization.py b/qualtran/bloqs/chemistry/sf/single_factorization.py index 80e346560..173156fab 100644 --- a/qualtran/bloqs/chemistry/sf/single_factorization.py +++ b/qualtran/bloqs/chemistry/sf/single_factorization.py @@ -41,7 +41,7 @@ Soquet, SoquetT, ) -from qualtran._infra.data_types import BoundedQUInt +from qualtran._infra.data_types import BQUInt from qualtran.bloqs.basic_gates import Hadamard from qualtran.bloqs.basic_gates.swap import CSwap from qualtran.bloqs.block_encoding import BlockEncoding @@ -145,26 +145,25 @@ def system_bitsize(self) -> int: def selection_registers(self) -> Iterable[Register]: return ( Register( - "l", - BoundedQUInt(bitsize=self.num_aux.bit_length(), iteration_length=self.num_aux + 1), + "l", BQUInt(bitsize=self.num_aux.bit_length(), iteration_length=self.num_aux + 1) ), Register( "p", - BoundedQUInt( + BQUInt( bitsize=(self.num_spin_orb // 2 - 1).bit_length(), iteration_length=self.num_spin_orb // 2, ), ), Register( "q", - BoundedQUInt( + BQUInt( bitsize=(self.num_spin_orb // 2 - 1).bit_length(), iteration_length=self.num_spin_orb // 2, ), ), - Register("rot_aa", BoundedQUInt(bitsize=1)), - Register("swap_pq", BoundedQUInt(bitsize=1)), - Register("spin", BoundedQUInt(bitsize=1)), + Register("rot_aa", BQUInt(bitsize=1)), + Register("swap_pq", BQUInt(bitsize=1)), + Register("spin", BQUInt(bitsize=1)), ) @property diff --git a/qualtran/bloqs/chemistry/sparse/prepare.py b/qualtran/bloqs/chemistry/sparse/prepare.py index 3c6a4c043..c5e08be72 100644 --- a/qualtran/bloqs/chemistry/sparse/prepare.py +++ b/qualtran/bloqs/chemistry/sparse/prepare.py @@ -25,7 +25,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, CtrlSpec, QAny, QBit, @@ -189,17 +189,17 @@ def selection_registers(self) -> Tuple[Register, ...]: return ( Register( "d", - BoundedQUInt( + BQUInt( bitsize=(self.num_non_zero - 1).bit_length(), iteration_length=self.num_non_zero ), ), - Register("sigma", BoundedQUInt(self.num_bits_state_prep)), - Register("alpha", BoundedQUInt(1)), - Register("beta", BoundedQUInt(1)), - Register("rot_aa", BoundedQUInt(1)), - Register("swap_pq", BoundedQUInt(1)), - Register("swap_rs", BoundedQUInt(1)), - Register("swap_pqrs", BoundedQUInt(1)), + Register("sigma", BQUInt(self.num_bits_state_prep)), + Register("alpha", BQUInt(1)), + Register("beta", BQUInt(1)), + Register("rot_aa", BQUInt(1)), + Register("swap_pq", BQUInt(1)), + Register("swap_rs", BQUInt(1)), + Register("swap_pqrs", BQUInt(1)), ) @cached_property diff --git a/qualtran/bloqs/chemistry/sparse/select_bloq.py b/qualtran/bloqs/chemistry/sparse/select_bloq.py index 681a66557..8b632ac6f 100644 --- a/qualtran/bloqs/chemistry/sparse/select_bloq.py +++ b/qualtran/bloqs/chemistry/sparse/select_bloq.py @@ -19,16 +19,7 @@ import cirq from attrs import frozen -from qualtran import ( - bloq_example, - BloqBuilder, - BloqDocSpec, - BoundedQUInt, - QAny, - QBit, - Register, - SoquetT, -) +from qualtran import bloq_example, BloqBuilder, BloqDocSpec, BQUInt, QAny, QBit, Register, SoquetT from qualtran._infra.single_qubit_controlled import SpecializedSingleQubitControlledExtension from qualtran.bloqs.basic_gates import SGate from qualtran.bloqs.multiplexers.select_base import SelectOracle @@ -76,35 +67,35 @@ def selection_registers(self) -> Tuple[Register, ...]: return ( Register( "p", - BoundedQUInt( + BQUInt( bitsize=(self.num_spin_orb // 2 - 1).bit_length(), iteration_length=self.num_spin_orb // 2, ), ), Register( "q", - BoundedQUInt( + BQUInt( bitsize=(self.num_spin_orb // 2 - 1).bit_length(), iteration_length=self.num_spin_orb // 2, ), ), Register( "r", - BoundedQUInt( + BQUInt( bitsize=(self.num_spin_orb // 2 - 1).bit_length(), iteration_length=self.num_spin_orb // 2, ), ), Register( "s", - BoundedQUInt( + BQUInt( bitsize=(self.num_spin_orb // 2 - 1).bit_length(), iteration_length=self.num_spin_orb // 2, ), ), - Register("alpha", BoundedQUInt(1)), - Register("beta", BoundedQUInt(1)), - Register("flag_1b", BoundedQUInt(1)), + Register("alpha", BQUInt(1)), + Register("beta", BQUInt(1)), + Register("flag_1b", BQUInt(1)), ) @cached_property diff --git a/qualtran/bloqs/chemistry/thc/prepare.py b/qualtran/bloqs/chemistry/thc/prepare.py index 0bd711985..dfc38fee9 100644 --- a/qualtran/bloqs/chemistry/thc/prepare.py +++ b/qualtran/bloqs/chemistry/thc/prepare.py @@ -32,7 +32,7 @@ Soquet, SoquetT, ) -from qualtran._infra.data_types import BoundedQUInt +from qualtran._infra.data_types import BQUInt from qualtran.bloqs.arithmetic import ( EqualsAConstant, GreaterThanConstant, @@ -344,20 +344,18 @@ def l1_norm_of_coeffs(self) -> SymbolicFloat: def selection_registers(self) -> Tuple[Register, ...]: return ( Register( - "mu", - BoundedQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1), + "mu", BQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1) ), Register( - "nu", - BoundedQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1), + "nu", BQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1) ), - Register("plus_mn", BoundedQUInt(bitsize=1)), - Register("plus_a", BoundedQUInt(bitsize=1)), - Register("plus_b", BoundedQUInt(bitsize=1)), - Register("sigma", BoundedQUInt(bitsize=self.keep_bitsize)), - Register("rot", BoundedQUInt(bitsize=1)), - Register('succ', BoundedQUInt(bitsize=1)), - Register('nu_eq_mp1', BoundedQUInt(bitsize=1)), + Register("plus_mn", BQUInt(bitsize=1)), + Register("plus_a", BQUInt(bitsize=1)), + Register("plus_b", BQUInt(bitsize=1)), + Register("sigma", BQUInt(bitsize=self.keep_bitsize)), + Register("rot", BQUInt(bitsize=1)), + Register('succ', BQUInt(bitsize=1)), + Register('nu_eq_mp1', BQUInt(bitsize=1)), ) @cached_property diff --git a/qualtran/bloqs/chemistry/thc/select_bloq.py b/qualtran/bloqs/chemistry/thc/select_bloq.py index 1eaf229ad..d172a3d72 100644 --- a/qualtran/bloqs/chemistry/thc/select_bloq.py +++ b/qualtran/bloqs/chemistry/thc/select_bloq.py @@ -24,7 +24,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, QAny, QBit, Register, @@ -168,21 +168,19 @@ def control_registers(self) -> Tuple[Register, ...]: @cached_property def selection_registers(self) -> Tuple[Register, ...]: return ( - Register("succ", BoundedQUInt(bitsize=1)), - Register("nu_eq_mp1", BoundedQUInt(bitsize=1)), + Register("succ", BQUInt(bitsize=1)), + Register("nu_eq_mp1", BQUInt(bitsize=1)), Register( - "mu", - BoundedQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1), + "mu", BQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1) ), Register( - "nu", - BoundedQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1), + "nu", BQUInt(bitsize=(self.num_mu).bit_length(), iteration_length=self.num_mu + 1) ), - Register("plus_mn", BoundedQUInt(bitsize=1)), - Register("plus_a", BoundedQUInt(bitsize=1)), - Register("plus_b", BoundedQUInt(bitsize=1)), - Register("sigma", BoundedQUInt(bitsize=self.keep_bitsize)), - Register("rot", BoundedQUInt(bitsize=1)), + Register("plus_mn", BQUInt(bitsize=1)), + Register("plus_a", BQUInt(bitsize=1)), + Register("plus_b", BQUInt(bitsize=1)), + Register("sigma", BQUInt(bitsize=self.keep_bitsize)), + Register("rot", BQUInt(bitsize=1)), ) @cached_property diff --git a/qualtran/bloqs/chemistry/trotter/grid_ham/potential.py b/qualtran/bloqs/chemistry/trotter/grid_ham/potential.py index e5e49d250..307985fe3 100644 --- a/qualtran/bloqs/chemistry/trotter/grid_ham/potential.py +++ b/qualtran/bloqs/chemistry/trotter/grid_ham/potential.py @@ -30,7 +30,7 @@ Soquet, SoquetT, ) -from qualtran._infra.data_types import BoundedQUInt +from qualtran._infra.data_types import BQUInt from qualtran.bloqs.arithmetic import OutOfPlaceAdder, SumOfSquares from qualtran.bloqs.bookkeeping import Cast from qualtran.bloqs.chemistry.trotter.grid_ham.inverse_sqrt import ( @@ -124,7 +124,7 @@ def build_composite_bloq( qrom_anc_c3 = bb.allocate(self.poly_bitsize) cast = Cast( inp_dtype=sos.reg.dtype, - out_dtype=BoundedQUInt(sos.reg.dtype.bitsize, iteration_length=len(self.qrom_data[0])), + out_dtype=BQUInt(sos.reg.dtype.bitsize, iteration_length=len(self.qrom_data[0])), ) sos = bb.add(cast, reg=sos) qrom_bloq = QROM( diff --git a/qualtran/bloqs/chemistry/writing_algorithms.ipynb b/qualtran/bloqs/chemistry/writing_algorithms.ipynb index 9de10287a..f020eef15 100644 --- a/qualtran/bloqs/chemistry/writing_algorithms.ipynb +++ b/qualtran/bloqs/chemistry/writing_algorithms.ipynb @@ -69,7 +69,7 @@ "from functools import cached_property\n", "from typing import Tuple\n", "from attrs import frozen\n", - "from qualtran import Register, BoundedQUInt, QBit, QAny\n", + "from qualtran import Register, BQUInt, QBit, QAny\n", "\n", "from qualtran.drawing import show_bloq\n", "from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle\n", @@ -83,13 +83,13 @@ " def selection_registers(self) -> Tuple[Register, ...]:\n", " bitsize = (self.num_spin_orb // 2 - 1).bit_length()\n", " return (\n", - " Register('p', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", - " Register('q', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", - " Register('r', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", - " Register('s', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", - " Register('alpha', BoundedQUInt(bitsize=1)),\n", - " Register('beta', BoundedQUInt(bitsize=1)),\n", - " Register('sign', BoundedQUInt(bitsize=1)),\n", + " Register('p', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", + " Register('q', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", + " Register('r', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", + " Register('s', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb//2)),\n", + " Register('alpha', BQUInt(bitsize=1)),\n", + " Register('beta', BQUInt(bitsize=1)),\n", + " Register('sign', BQUInt(bitsize=1)),\n", " )\n", "\n", " # defer definition of junk registers until you actually need to implement a decomposition.\n", @@ -134,13 +134,13 @@ " def selection_registers(self) -> Tuple[Register, ...]:\n", " bitsize = (self.num_spin_orb // 2 - 1).bit_length()\n", " return (\n", - " Register('p', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('q', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('r', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('s', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('alpha', BoundedQUInt(1)),\n", - " Register('beta', BoundedQUInt(1)),\n", - " Register('sign', BoundedQUInt(1)),\n", + " Register('p', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('q', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('r', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('s', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('alpha', BQUInt(1)),\n", + " Register('beta', BQUInt(1)),\n", + " Register('sign', BQUInt(1)),\n", " )\n", "\n", " def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:\n", @@ -323,16 +323,16 @@ " data_size = (ns ** 2 + ns**4)\n", " contg_reg_size = (data_size - 1).bit_length()\n", " return (\n", - " Register('p', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('q', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('r', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", - " Register('s', BoundedQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('p', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('q', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('r', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", + " Register('s', BQUInt(bitsize=bitsize, iteration_length=self.num_spin_orb // 2)),\n", " Register(\n", - " 'l', BoundedQUInt(bitsize=contg_reg_size, iteration_length=data_size),\n", + " 'l', BQUInt(bitsize=contg_reg_size, iteration_length=data_size),\n", " ),\n", - " Register('alpha', BoundedQUInt(1)),\n", - " Register('beta', BoundedQUInt(1)),\n", - " Register('sigma', BoundedQUInt(bitsize=self.num_bits_state_prep)),\n", + " Register('alpha', BQUInt(1)),\n", + " Register('beta', BQUInt(1)),\n", + " Register('sigma', BQUInt(bitsize=self.num_bits_state_prep)),\n", " )\n", "\n", " @cached_property\n", diff --git a/qualtran/bloqs/data_loading/qrom_base.py b/qualtran/bloqs/data_loading/qrom_base.py index dc751949c..efe1c5e23 100644 --- a/qualtran/bloqs/data_loading/qrom_base.py +++ b/qualtran/bloqs/data_loading/qrom_base.py @@ -23,7 +23,7 @@ import sympy from numpy.typing import ArrayLike, NDArray -from qualtran import BloqDocSpec, BoundedQUInt, QAny, Register, Side +from qualtran import BloqDocSpec, BQUInt, QAny, Register, Side from qualtran.simulation.classical_sim import ClassicalValT from qualtran.symbolics import bit_length, is_symbolic, shape, Shaped, SymbolicInt @@ -285,7 +285,7 @@ def control_registers(self) -> Tuple[Register, ...]: @cached_property def selection_registers(self) -> Tuple[Register, ...]: types = [ - BoundedQUInt(sb, l) + BQUInt(sb, l) for l, sb in zip(self.data_shape, self.selection_bitsizes) if is_symbolic(l) or l > 1 ] diff --git a/qualtran/bloqs/data_loading/select_swap_qrom.py b/qualtran/bloqs/data_loading/select_swap_qrom.py index 504a9a914..590fccaf0 100644 --- a/qualtran/bloqs/data_loading/select_swap_qrom.py +++ b/qualtran/bloqs/data_loading/select_swap_qrom.py @@ -22,7 +22,7 @@ import sympy from numpy.typing import ArrayLike -from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, GateWithRegisters, Register, Signature +from qualtran import bloq_example, BloqDocSpec, BQUInt, GateWithRegisters, Register, Signature from qualtran.bloqs.arithmetic.bitwise import Xor from qualtran.bloqs.bookkeeping import Partition from qualtran.bloqs.data_loading.qrom import QROM @@ -319,8 +319,8 @@ def _partition_selection_reg_bloqs(self) -> List[Partition]: partition_bloqs = [] for reg, k in zip(self.selection_registers, self.log_block_sizes): preg = ( - Register('l', BoundedQUInt(reg.bitsize - k, 2 ** (reg.bitsize - k))), - Register('k', BoundedQUInt(k, 2**k)), + Register('l', BQUInt(reg.bitsize - k, 2 ** (reg.bitsize - k))), + Register('k', BQUInt(k, 2**k)), ) partition_bloqs.append(Partition(reg.bitsize, preg)) return partition_bloqs diff --git a/qualtran/bloqs/for_testing/many_registers.py b/qualtran/bloqs/for_testing/many_registers.py index beb03870e..e2f2d584d 100644 --- a/qualtran/bloqs/for_testing/many_registers.py +++ b/qualtran/bloqs/for_testing/many_registers.py @@ -22,7 +22,7 @@ from qualtran import ( Bloq, BloqBuilder, - BoundedQUInt, + BQUInt, QAny, QBit, QFxp, @@ -73,7 +73,7 @@ def pretty_name(self) -> str: class TestBoundedQUInt(Bloq): @cached_property def signature(self) -> Signature: - return Signature([Register('xx', BoundedQUInt(4, 3)), Register('yy', QFxp(8, 6, True))]) + return Signature([Register('xx', BQUInt(4, 3)), Register('yy', QFxp(8, 6, True))]) @frozen @@ -97,7 +97,7 @@ class TestMultiTypedRegister(Bloq): def signature(self) -> Signature: return Signature( [ - Register('a', BoundedQUInt(4, 3)), + Register('a', BQUInt(4, 3)), Register('b', QFxp(8, 6, True)), Register('c', QFxp(8, 8)), Register('d', QUInt(8)), diff --git a/qualtran/bloqs/for_testing/qubitization_walk_test.py b/qualtran/bloqs/for_testing/qubitization_walk_test.py index d8655faeb..d1c0fdb5e 100644 --- a/qualtran/bloqs/for_testing/qubitization_walk_test.py +++ b/qualtran/bloqs/for_testing/qubitization_walk_test.py @@ -19,7 +19,7 @@ import scipy from numpy.typing import NDArray -from qualtran import BoundedQUInt, Register +from qualtran import BQUInt, Register from qualtran.bloqs.block_encoding.lcu_block_encoding import SelectBlockEncoding from qualtran.bloqs.multiplexers.select_pauli_lcu import SelectPauliLCU from qualtran.bloqs.qubitization.qubitization_walk_operator import QubitizationWalkOperator @@ -38,7 +38,7 @@ class PrepareUniformSuperpositionTest(PrepareOracle): @cached_property def selection_registers(self) -> Tuple[Register, ...]: - return (Register('selection', BoundedQUInt((self.n - 1).bit_length(), self.n)),) + return (Register('selection', BQUInt((self.n - 1).bit_length(), self.n)),) @cached_property def junk_registers(self) -> Tuple[Register, ...]: diff --git a/qualtran/bloqs/for_testing/random_select_and_prepare.py b/qualtran/bloqs/for_testing/random_select_and_prepare.py index 92fe63743..c5eed3569 100644 --- a/qualtran/bloqs/for_testing/random_select_and_prepare.py +++ b/qualtran/bloqs/for_testing/random_select_and_prepare.py @@ -19,7 +19,7 @@ from attrs import frozen from numpy.typing import NDArray -from qualtran import BloqBuilder, BoundedQUInt, QBit, Register, SoquetT +from qualtran import BloqBuilder, BQUInt, QBit, Register, SoquetT from qualtran._infra.single_qubit_controlled import SpecializedSingleQubitControlledExtension from qualtran.bloqs.block_encoding.lcu_block_encoding import SelectBlockEncoding from qualtran.bloqs.for_testing.matrix_gate import MatrixGate @@ -56,7 +56,7 @@ def __attrs_post_init__(self): @property def selection_registers(self) -> tuple[Register, ...]: - return (Register('selection', BoundedQUInt(bitsize=self.U.bitsize)),) + return (Register('selection', BQUInt(bitsize=self.U.bitsize)),) @property def l1_norm_of_coeffs(self) -> float: @@ -128,11 +128,11 @@ def control_registers(self) -> Tuple[Register, ...]: @property def selection_registers(self) -> Tuple[Register, ...]: - return (Register('selection', BoundedQUInt(bitsize=self.select_bitsize)),) + return (Register('selection', BQUInt(bitsize=self.select_bitsize)),) @property def target_registers(self) -> Tuple[Register, ...]: - return (Register('target', BoundedQUInt(bitsize=self.target_bitsize)),) + return (Register('target', BQUInt(bitsize=self.target_bitsize)),) def decompose_from_registers( self, diff --git a/qualtran/bloqs/mcmt/ctrl_spec_and.py b/qualtran/bloqs/mcmt/ctrl_spec_and.py index 07eea747e..587670594 100644 --- a/qualtran/bloqs/mcmt/ctrl_spec_and.py +++ b/qualtran/bloqs/mcmt/ctrl_spec_and.py @@ -20,7 +20,7 @@ Bloq, bloq_example, BloqDocSpec, - BoundedQUInt, + BQUInt, CtrlSpec, DecomposeTypeError, QAny, @@ -80,9 +80,7 @@ def __attrs_post_init__(self): if not is_symbolic(self.n_ctrl_qubits) and self.n_ctrl_qubits <= 1: raise ValueError(f"Expected at least 2 controls, got {self.n_ctrl_qubits}") for qdtype in self.ctrl_spec.qdtypes: - if not isinstance( - qdtype, (QBit, QInt, QUInt, BoundedQUInt, QIntOnesComp, QMontgomeryUInt) - ): + if not isinstance(qdtype, (QBit, QInt, QUInt, BQUInt, QIntOnesComp, QMontgomeryUInt)): raise NotImplementedError("CtrlSpecAnd currently only supports integer types") @cached_property diff --git a/qualtran/bloqs/mean_estimation/mean_estimation_operator_test.py b/qualtran/bloqs/mean_estimation/mean_estimation_operator_test.py index 663a9320c..cc62f7f4a 100644 --- a/qualtran/bloqs/mean_estimation/mean_estimation_operator_test.py +++ b/qualtran/bloqs/mean_estimation/mean_estimation_operator_test.py @@ -20,7 +20,7 @@ import pytest from attrs import frozen -from qualtran import BoundedQUInt, QAny, QBit, QUInt, Register +from qualtran import BQUInt, QAny, QBit, QUInt, Register from qualtran._infra.gate_with_registers import get_named_qubits, total_bits from qualtran._infra.single_qubit_controlled import SpecializedSingleQubitControlledExtension from qualtran.bloqs.mean_estimation.mean_estimation_operator import ( @@ -41,7 +41,7 @@ class BernoulliSynthesizer(PrepareOracle): @cached_property def selection_registers(self) -> Tuple[Register, ...]: - return (Register('q', BoundedQUInt(self.nqubits, 2)),) + return (Register('q', BQUInt(self.nqubits, 2)),) def decompose_from_registers( # type:ignore[override] self, context, q: Sequence[cirq.Qid] @@ -67,7 +67,7 @@ def control_registers(self) -> Tuple[Register, ...]: @cached_property def selection_registers(self) -> Tuple[Register, ...]: - return (Register('q', BoundedQUInt(self.selection_bitsize, 2)),) + return (Register('q', BQUInt(self.selection_bitsize, 2)),) @cached_property def target_registers(self) -> Tuple[Register, ...]: diff --git a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.ipynb b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.ipynb index 458e71db6..a4785f12d 100644 --- a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.ipynb +++ b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.ipynb @@ -109,7 +109,7 @@ }, "outputs": [], "source": [ - "from qualtran import BoundedQUInt, Register\n", + "from qualtran import BQUInt, Register\n", "\n", "def _z_to_odd(n: int):\n", " if n % 2 == 1:\n", @@ -117,7 +117,7 @@ " return cirq.I\n", "\n", "apply_z_to_odd = ApplyGateToLthQubit(\n", - " Register('selection', BoundedQUInt(3, 4)),\n", + " Register('selection', BQUInt(3, 4)),\n", " nth_gate=_z_to_odd,\n", " control_regs=Signature.build(control=2),\n", ")\n" diff --git a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py index ec418a057..8238ebbcd 100644 --- a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py +++ b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py @@ -21,7 +21,7 @@ import numpy as np import sympy -from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, QAny, QBit, Register, Signature +from qualtran import bloq_example, BloqDocSpec, BQUInt, QAny, QBit, Register, Signature from qualtran._infra.gate_with_registers import total_bits from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate @@ -64,7 +64,7 @@ def make_on( ) -> cirq.Operation: """Helper constructor to automatically deduce bitsize attributes.""" return ApplyGateToLthQubit( - Register('selection', BoundedQUInt(len(quregs['selection']), len(quregs['target']))), + Register('selection', BQUInt(len(quregs['selection']), len(quregs['target']))), nth_gate=nth_gate, control_regs=Register('control', QAny(len(quregs['control']))), ).on_registers(**quregs) @@ -125,7 +125,7 @@ def nth_operation( # type: ignore[override] @bloq_example def _apply_z_to_odd() -> ApplyGateToLthQubit: - from qualtran import BoundedQUInt, Register + from qualtran import BQUInt, Register def _z_to_odd(n: int): if n % 2 == 1: @@ -133,7 +133,7 @@ def _z_to_odd(n: int): return cirq.I apply_z_to_odd = ApplyGateToLthQubit( - Register('selection', BoundedQUInt(3, 4)), + Register('selection', BQUInt(3, 4)), nth_gate=_z_to_odd, control_regs=Signature.build(control=2), ) diff --git a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target_test.py b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target_test.py index db4cecf3c..79e770fc3 100644 --- a/qualtran/bloqs/multiplexers/apply_gate_to_lth_target_test.py +++ b/qualtran/bloqs/multiplexers/apply_gate_to_lth_target_test.py @@ -16,7 +16,7 @@ import pytest import qualtran.testing as qlt_testing -from qualtran import BoundedQUInt, QUInt, Register, Signature +from qualtran import BQUInt, QUInt, Register, Signature from qualtran._infra.gate_with_registers import get_named_qubits, total_bits from qualtran.bloqs.multiplexers.apply_gate_to_lth_target import ( _apply_z_to_odd, @@ -40,7 +40,7 @@ def test_notebook(): def test_apply_gate_to_lth_qubit(selection_bitsize, target_bitsize): greedy_mm = cirq.GreedyQubitManager(prefix="_a", maximize_reuse=True) gate = ApplyGateToLthQubit( - Register('selection', BoundedQUInt(selection_bitsize, target_bitsize)), lambda _: cirq.X + Register('selection', BQUInt(selection_bitsize, target_bitsize)), lambda _: cirq.X ) g = GateHelper(gate, context=cirq.DecompositionContext(greedy_mm)) # Upper bounded because not all ancillas may be used as part of unary iteration. @@ -68,7 +68,7 @@ def test_apply_gate_to_lth_qubit(selection_bitsize, target_bitsize): def test_apply_gate_to_lth_qubit_diagram(): # Apply Z gate to all odd targets and Identity to even targets. gate = ApplyGateToLthQubit( - Register('selection', BoundedQUInt(3, 5)), + Register('selection', BQUInt(3, 5)), lambda n: cirq.Z if n & 1 else cirq.I, control_regs=Signature.build(control=2), ) @@ -103,7 +103,7 @@ def test_apply_gate_to_lth_qubit_diagram(): def test_apply_gate_to_lth_qubit_make_on(): gate = ApplyGateToLthQubit( - Register('selection', BoundedQUInt(3, 5)), + Register('selection', BQUInt(3, 5)), lambda n: cirq.Z if n & 1 else cirq.I, control_regs=Signature.build(control=2), ) @@ -123,7 +123,7 @@ def test_apply_gate_to_lth_qubit_make_on(): @pytest.mark.parametrize("selection_bitsize,target_bitsize", [[3, 5], [3, 7], [4, 5]]) def test_bloq_has_consistent_decomposition(selection_bitsize, target_bitsize): bloq = ApplyGateToLthQubit( - Register('selection', BoundedQUInt(selection_bitsize, target_bitsize)), + Register('selection', BQUInt(selection_bitsize, target_bitsize)), lambda n: cirq.Z if n & 1 else cirq.I, control_regs=Signature.build(control=2), ) diff --git a/qualtran/bloqs/multiplexers/apply_lth_bloq.py b/qualtran/bloqs/multiplexers/apply_lth_bloq.py index 549c77a5d..003080af1 100644 --- a/qualtran/bloqs/multiplexers/apply_lth_bloq.py +++ b/qualtran/bloqs/multiplexers/apply_lth_bloq.py @@ -20,7 +20,7 @@ from attrs import field, frozen from numpy.typing import NDArray -from qualtran import Bloq, bloq_example, BloqDocSpec, BoundedQUInt, QBit, Register, Side +from qualtran import Bloq, bloq_example, BloqDocSpec, BQUInt, QBit, Register, Side from qualtran._infra.gate_with_registers import merge_qubits from qualtran._infra.single_qubit_controlled import SpecializedSingleQubitControlledExtension from qualtran.bloqs.multiplexers.select_base import SelectOracle @@ -81,7 +81,7 @@ def selection_registers(self) -> Tuple[Register, ...]: return tuple( Register( "selection" if len(self.ops.shape) == 1 else f"selection{i}", - BoundedQUInt(ceil(log2(k)), k), + BQUInt(ceil(log2(k)), k), ) for i, k in enumerate(self.ops.shape) ) diff --git a/qualtran/bloqs/multiplexers/apply_lth_bloq_test.py b/qualtran/bloqs/multiplexers/apply_lth_bloq_test.py index f26bac438..3f4733218 100644 --- a/qualtran/bloqs/multiplexers/apply_lth_bloq_test.py +++ b/qualtran/bloqs/multiplexers/apply_lth_bloq_test.py @@ -17,16 +17,7 @@ import numpy as np import pytest -from qualtran import ( - BloqBuilder, - BoundedQUInt, - Controlled, - CtrlSpec, - QBit, - Register, - Signature, - Soquet, -) +from qualtran import BloqBuilder, BQUInt, Controlled, CtrlSpec, QBit, Register, Signature, Soquet from qualtran.bloqs.basic_gates import ( CHadamard, CNOT, @@ -55,11 +46,7 @@ def test_apply_lth_bloq(bloq_autotester): def test_signature(): assert _apply_lth_bloq().signature == Signature( - [ - Register("control", QBit()), - Register("selection", BoundedQUInt(2, 4)), - Register("q", QBit()), - ] + [Register("control", QBit()), Register("selection", BQUInt(2, 4)), Register("q", QBit())] ) with pytest.raises(ValueError): @@ -156,8 +143,8 @@ def test_ndim(i, j, ctrl): assert bloq.signature == Signature( [ Register("control", QBit()), - Register("selection0", BoundedQUInt(1, 2)), - Register("selection1", BoundedQUInt(1, 2)), + Register("selection0", BQUInt(1, 2)), + Register("selection1", BQUInt(1, 2)), Register("q", QBit()), ] ) diff --git a/qualtran/bloqs/multiplexers/select_pauli_lcu.py b/qualtran/bloqs/multiplexers/select_pauli_lcu.py index 4eb1de6bd..4cbedb324 100644 --- a/qualtran/bloqs/multiplexers/select_pauli_lcu.py +++ b/qualtran/bloqs/multiplexers/select_pauli_lcu.py @@ -22,7 +22,7 @@ import numpy as np from numpy.typing import NDArray -from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, QAny, QBit, Register +from qualtran import bloq_example, BloqDocSpec, BQUInt, QAny, QBit, Register from qualtran._infra.single_qubit_controlled import SpecializedSingleQubitControlledExtension from qualtran.bloqs.multiplexers.select_base import SelectOracle from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate @@ -82,9 +82,7 @@ def control_registers(self) -> Tuple[Register, ...]: @cached_property def selection_registers(self) -> Tuple[Register, ...]: - return ( - Register('selection', BoundedQUInt(self.selection_bitsize, len(self.select_unitaries))), - ) + return (Register('selection', BQUInt(self.selection_bitsize, len(self.select_unitaries))),) @cached_property def target_registers(self) -> Tuple[Register, ...]: diff --git a/qualtran/bloqs/multiplexers/selected_majorana_fermion.py b/qualtran/bloqs/multiplexers/selected_majorana_fermion.py index 822ece6bc..8be4daaea 100644 --- a/qualtran/bloqs/multiplexers/selected_majorana_fermion.py +++ b/qualtran/bloqs/multiplexers/selected_majorana_fermion.py @@ -22,7 +22,7 @@ from numpy.typing import NDArray from qualtran import QAny, QBit, Register -from qualtran._infra.data_types import BoundedQUInt +from qualtran._infra.data_types import BQUInt from qualtran._infra.gate_with_registers import total_bits from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate @@ -37,7 +37,7 @@ class SelectedMajoranaFermion(UnaryIterationGate): Args: - selection_regs: Indexing `select` signature of type `Register(dtype=BoundedQUInt)`. + selection_regs: Indexing `select` signature of type `Register(dtype=BQUInt)`. It also contains information about the iteration length of each selection register. control_regs: Control signature for constructing a controlled version of the gate. target_gate: Single qubit gate to be applied to the target qubits. @@ -66,7 +66,7 @@ def make_on( """Helper constructor to automatically deduce selection_regs attribute.""" return SelectedMajoranaFermion( selection_regs=Register( - 'selection', BoundedQUInt(len(quregs['selection']), len(quregs['target'])) + 'selection', BQUInt(len(quregs['selection']), len(quregs['target'])) ), target_gate=target_gate, ).on_registers(**quregs) diff --git a/qualtran/bloqs/multiplexers/selected_majorana_fermion_test.py b/qualtran/bloqs/multiplexers/selected_majorana_fermion_test.py index 1d759d441..d0b964420 100644 --- a/qualtran/bloqs/multiplexers/selected_majorana_fermion_test.py +++ b/qualtran/bloqs/multiplexers/selected_majorana_fermion_test.py @@ -16,7 +16,7 @@ import numpy as np import pytest -from qualtran import BoundedQUInt, QUInt, Register +from qualtran import BQUInt, QUInt, Register from qualtran._infra.gate_with_registers import get_named_qubits, total_bits from qualtran.bloqs.multiplexers.selected_majorana_fermion import SelectedMajoranaFermion from qualtran.cirq_interop.testing import GateHelper @@ -28,8 +28,7 @@ @pytest.mark.parametrize("target_gate", [cirq.X, cirq.Y]) def test_selected_majorana_fermion_gate(selection_bitsize, target_bitsize, target_gate): gate = SelectedMajoranaFermion( - Register('selection', BoundedQUInt(selection_bitsize, target_bitsize)), - target_gate=target_gate, + Register('selection', BQUInt(selection_bitsize, target_bitsize)), target_gate=target_gate ) assert_valid_bloq_decomposition(gate) @@ -70,7 +69,7 @@ def test_selected_majorana_fermion_gate(selection_bitsize, target_bitsize, targe def test_selected_majorana_fermion_gate_diagram(): selection_bitsize, target_bitsize = 3, 5 gate = SelectedMajoranaFermion( - Register('selection', BoundedQUInt(selection_bitsize, target_bitsize)), target_gate=cirq.X + Register('selection', BQUInt(selection_bitsize, target_bitsize)), target_gate=cirq.X ) circuit = cirq.Circuit(gate.on_registers(**get_named_qubits(gate.signature))) qubits = list(q for v in get_named_qubits(gate.signature).values() for q in v) @@ -102,7 +101,7 @@ def test_selected_majorana_fermion_gate_diagram(): def test_selected_majorana_fermion_gate_decomposed_diagram(): selection_bitsize, target_bitsize = 2, 3 gate = SelectedMajoranaFermion( - Register('selection', BoundedQUInt(selection_bitsize, target_bitsize)), target_gate=cirq.X + Register('selection', BQUInt(selection_bitsize, target_bitsize)), target_gate=cirq.X ) greedy_mm = cirq.GreedyQubitManager(prefix="_a", maximize_reuse=True) g = GateHelper(gate) @@ -144,7 +143,7 @@ def test_selected_majorana_fermion_gate_decomposed_diagram(): def test_selected_majorana_fermion_gate_make_on(): selection_bitsize, target_bitsize = 3, 5 gate = SelectedMajoranaFermion( - Register('selection', BoundedQUInt(selection_bitsize, target_bitsize)), target_gate=cirq.X + Register('selection', BQUInt(selection_bitsize, target_bitsize)), target_gate=cirq.X ) op = gate.on_registers(**get_named_qubits(gate.signature)) op2 = SelectedMajoranaFermion.make_on(target_gate=cirq.X, **get_named_qubits(gate.signature)) diff --git a/qualtran/bloqs/multiplexers/unary_iteration.ipynb b/qualtran/bloqs/multiplexers/unary_iteration.ipynb index 8d4e7b4a4..b0a18619c 100644 --- a/qualtran/bloqs/multiplexers/unary_iteration.ipynb +++ b/qualtran/bloqs/multiplexers/unary_iteration.ipynb @@ -470,7 +470,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qualtran import QAny, Register, Register, BoundedQUInt\n", + "from qualtran import QAny, Register, Register, BQUInt\n", "from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate\n", "from functools import cached_property\n", "\n", @@ -488,7 +488,7 @@ "\n", " @cached_property\n", " def selection_registers(self) -> Tuple[Register, ...]:\n", - " return (Register('selection', BoundedQUInt(self._selection_bitsize, self._target_bitsize)),)\n", + " return (Register('selection', BQUInt(self._selection_bitsize, self._target_bitsize)),)\n", "\n", " @cached_property\n", " def target_registers(self) -> Tuple[Register, ...]:\n", diff --git a/qualtran/bloqs/multiplexers/unary_iteration_bloq_test.py b/qualtran/bloqs/multiplexers/unary_iteration_bloq_test.py index 94f588e1c..529640770 100644 --- a/qualtran/bloqs/multiplexers/unary_iteration_bloq_test.py +++ b/qualtran/bloqs/multiplexers/unary_iteration_bloq_test.py @@ -19,7 +19,7 @@ import cirq import pytest -from qualtran import BoundedQUInt, QAny, QUInt, Register, Signature +from qualtran import BQUInt, QAny, QUInt, Register, Signature from qualtran._infra.gate_with_registers import get_named_qubits, total_bits from qualtran.bloqs.basic_gates import CNOT from qualtran.bloqs.bookkeeping import Join, Split @@ -47,7 +47,7 @@ def control_registers(self) -> Tuple[Register, ...]: @cached_property def selection_registers(self) -> Tuple[Register, ...]: - return (Register('selection', BoundedQUInt(self._selection_bitsize, self._target_bitsize)),) + return (Register('selection', BQUInt(self._selection_bitsize, self._target_bitsize)),) @cached_property def target_registers(self) -> Tuple[Register, ...]: @@ -102,8 +102,7 @@ def control_registers(self) -> Tuple[Register, ...]: def selection_registers(self) -> Tuple[Register, ...]: return tuple( Register( - 'ijk'[i], - BoundedQUInt((self._target_shape[i] - 1).bit_length(), self._target_shape[i]), + 'ijk'[i], BQUInt((self._target_shape[i] - 1).bit_length(), self._target_shape[i]) ) for i in range(3) ) @@ -162,7 +161,7 @@ def test_multi_dimensional_unary_iteration_gate(target_shape: Tuple[int, int, in def test_unary_iteration_loop(): n_range, m_range = (3, 5), (6, 8) - selection_registers = [Register('n', BoundedQUInt(3, 5)), Register('m', BoundedQUInt(3, 8))] + selection_registers = [Register('n', BQUInt(3, 5)), Register('m', BQUInt(3, 8))] selection = get_named_qubits(selection_registers) target = {(n, m): cirq.q(f't({n}, {m})') for n in range(*n_range) for m in range(*m_range)} qm = cirq.GreedyQubitManager("ancilla", maximize_reuse=True) diff --git a/qualtran/bloqs/rotations/programmable_rotation_gate_array.py b/qualtran/bloqs/rotations/programmable_rotation_gate_array.py index de43fae6a..8b59c6bc6 100644 --- a/qualtran/bloqs/rotations/programmable_rotation_gate_array.py +++ b/qualtran/bloqs/rotations/programmable_rotation_gate_array.py @@ -24,7 +24,7 @@ from qualtran import ( bloq_example, BloqDocSpec, - BoundedQUInt, + BQUInt, GateWithRegisters, QAny, QUInt, @@ -112,7 +112,7 @@ def interleaved_unitary( @cached_property def selection_registers(self) -> Tuple[Register, ...]: - return (Register('selection', BoundedQUInt(self._selection_bitsize, len(self.angles[0]))),) + return (Register('selection', BQUInt(self._selection_bitsize, len(self.angles[0]))),) @cached_property def kappa_load_target(self) -> Tuple[Register, ...]: diff --git a/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py b/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py index 06b361a98..22e344c2b 100644 --- a/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py +++ b/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.py @@ -26,7 +26,7 @@ import numpy as np from numpy.typing import NDArray -from qualtran import bloq_example, BloqDocSpec, BoundedQUInt, Register, Signature +from qualtran import bloq_example, BloqDocSpec, BQUInt, Register, Signature from qualtran._infra.gate_with_registers import total_bits from qualtran.bloqs.arithmetic import LessThanEqual from qualtran.bloqs.basic_gates import CSwap, Hadamard, OnEach @@ -160,7 +160,7 @@ def from_probabilities( ) N = len(unnormalized_probabilities) return StatePreparationAliasSampling( - selection_registers=Register('selection', BoundedQUInt((N - 1).bit_length(), N)), + selection_registers=Register('selection', BQUInt((N - 1).bit_length(), N)), alt=np.array(alt), keep=np.array(keep), mu=mu, @@ -191,7 +191,7 @@ def from_n_coeff( selection_bitsize = bit_length(n_coeff - 1) alt, keep = Shaped((n_coeff,)), Shaped((n_coeff,)) return StatePreparationAliasSampling( - selection_registers=Register('selection', BoundedQUInt(selection_bitsize, n_coeff)), + selection_registers=Register('selection', BQUInt(selection_bitsize, n_coeff)), alt=alt, keep=keep, mu=mu, @@ -407,7 +407,7 @@ def from_sparse_dict( alt = [index[idx] for idx in alt_compressed] return cls( - selection_registers=Register('selection', BoundedQUInt((N - 1).bit_length(), N)), + selection_registers=Register('selection', BQUInt((N - 1).bit_length(), N)), index=np.array(index), alt=np.array(alt), keep=np.array(keep), @@ -463,7 +463,7 @@ def from_n_coeff( mu = sub_bit_prec_from_epsilon(n_coeff, precision) selection_bitsize = bit_length(n_coeff - 1) return cls( - selection_registers=Register('selection', BoundedQUInt(selection_bitsize, n_coeff)), + selection_registers=Register('selection', BQUInt(selection_bitsize, n_coeff)), index=Shaped((n_nonzero_coeff,)), alt=Shaped((n_nonzero_coeff,)), keep=Shaped((n_nonzero_coeff,)), diff --git a/qualtran/bloqs/swap_network/multiplexed_cswap.py b/qualtran/bloqs/swap_network/multiplexed_cswap.py index 9818fa143..7872f45fa 100644 --- a/qualtran/bloqs/swap_network/multiplexed_cswap.py +++ b/qualtran/bloqs/swap_network/multiplexed_cswap.py @@ -108,13 +108,13 @@ def nth_operation( @bloq_example def _multiplexed_cswap() -> MultiplexedCSwap: - from qualtran import BoundedQUInt + from qualtran import BQUInt selection_bitsize = 3 iteration_length = 5 target_bitsize = 2 multiplexed_cswap = MultiplexedCSwap( - Register('selection', BoundedQUInt(selection_bitsize, iteration_length)), + Register('selection', BQUInt(selection_bitsize, iteration_length)), target_bitsize=target_bitsize, ) diff --git a/qualtran/bloqs/swap_network/multiplexed_cswap_test.py b/qualtran/bloqs/swap_network/multiplexed_cswap_test.py index bf6023c49..9a98c4196 100644 --- a/qualtran/bloqs/swap_network/multiplexed_cswap_test.py +++ b/qualtran/bloqs/swap_network/multiplexed_cswap_test.py @@ -17,7 +17,7 @@ import cirq import pytest -from qualtran import BoundedQUInt, QUInt, Register +from qualtran import BQUInt, QUInt, Register from qualtran.bloqs.basic_gates import TGate from qualtran.bloqs.swap_network.multiplexed_cswap import _multiplexed_cswap, MultiplexedCSwap from qualtran.cirq_interop.testing import assert_circuit_inp_out_cirqsim, GateHelper @@ -32,7 +32,7 @@ def test_cswap_lth_reg(selection_bitsize, iteration_length, target_bitsize): greedy_mm = cirq.GreedyQubitManager(prefix="_a", maximize_reuse=True) gate = MultiplexedCSwap( - Register('selection', BoundedQUInt(selection_bitsize, iteration_length)), + Register('selection', BQUInt(selection_bitsize, iteration_length)), target_bitsize=target_bitsize, ) g = GateHelper(gate, context=cirq.DecompositionContext(greedy_mm)) @@ -61,7 +61,7 @@ def test_multiplexed_cswap_bloq_has_consistent_decomposition( selection_bitsize, iteration_length, target_bitsize ): bloq = MultiplexedCSwap( - Register('selection', BoundedQUInt(selection_bitsize, iteration_length)), + Register('selection', BQUInt(selection_bitsize, iteration_length)), target_bitsize=target_bitsize, ) assert_valid_bloq_decomposition(bloq) @@ -72,7 +72,7 @@ def test_multiplexed_cswap_bloq_has_consistent_decomposition( ) def test_multiplexed_cswap_t_counts(selection_bitsize, iteration_length, target_bitsize): bloq = MultiplexedCSwap( - Register('selection', BoundedQUInt(selection_bitsize, iteration_length)), + Register('selection', BQUInt(selection_bitsize, iteration_length)), target_bitsize=target_bitsize, ) expected = 4 * (iteration_length - 2) + 7 * (iteration_length * target_bitsize) diff --git a/qualtran/bloqs/swap_network/swap_network.ipynb b/qualtran/bloqs/swap_network/swap_network.ipynb index 5a3c53740..442247992 100644 --- a/qualtran/bloqs/swap_network/swap_network.ipynb +++ b/qualtran/bloqs/swap_network/swap_network.ipynb @@ -505,13 +505,13 @@ }, "outputs": [], "source": [ - "from qualtran import BoundedQUInt\n", + "from qualtran import BQUInt\n", "\n", "selection_bitsize = 3\n", "iteration_length = 5\n", "target_bitsize = 2\n", "multiplexed_cswap = MultiplexedCSwap(\n", - " Register('selection', BoundedQUInt(selection_bitsize, iteration_length)),\n", + " Register('selection', BQUInt(selection_bitsize, iteration_length)),\n", " target_bitsize=target_bitsize,\n", ")\n" ] diff --git a/qualtran/bloqs/swap_network/swap_with_zero.py b/qualtran/bloqs/swap_network/swap_with_zero.py index 0c21b2123..c4d7c4358 100644 --- a/qualtran/bloqs/swap_network/swap_with_zero.py +++ b/qualtran/bloqs/swap_network/swap_with_zero.py @@ -24,7 +24,7 @@ bloq_example, BloqBuilder, BloqDocSpec, - BoundedQUInt, + BQUInt, GateWithRegisters, QAny, Register, @@ -135,7 +135,7 @@ def __attrs_post_init__(self): @cached_property def selection_registers(self) -> Tuple[Register, ...]: types = [ - BoundedQUInt(sb, l) + BQUInt(sb, l) for sb, l in zip(self.selection_bitsizes, self.n_target_registers) if is_symbolic(sb) or sb > 0 ] diff --git a/qualtran/drawing/qpic_diagram_test.py b/qualtran/drawing/qpic_diagram_test.py index 61f054396..c5aeb0ed2 100644 --- a/qualtran/drawing/qpic_diagram_test.py +++ b/qualtran/drawing/qpic_diagram_test.py @@ -34,7 +34,7 @@ def test_qpic_data_for_reflect_using_prepare(): DEFINE off color=white DEFINE on color=black selection W \textrm{\scalebox{0.8}{selection}} -selection / \textrm{\scalebox{0.5}{BoundedQUInt(2, 4)}} +selection / \textrm{\scalebox{0.5}{BQUInt(2, 4)}} LABEL length=10 selection G:width=17:shape=box \textrm{\scalebox{0.8}{R\_L}} """, diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index 1d91d9cc6..eda03dbb2 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -11,17 +11,7 @@ # 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. -from qualtran import ( - BoundedQUInt, - QAny, - QBit, - QDType, - QFxp, - QInt, - QIntOnesComp, - QMontgomeryUInt, - QUInt, -) +from qualtran import BQUInt, QAny, QBit, QDType, QFxp, QInt, QIntOnesComp, QMontgomeryUInt, QUInt from qualtran.protos import data_types_pb2 from qualtran.serialization.args import int_or_sympy_from_proto, int_or_sympy_to_proto @@ -43,12 +33,10 @@ def data_type_to_proto(data: QDType) -> data_types_pb2.QDataType: return data_types_pb2.QDataType( qmontgomery_uint=data_types_pb2.QMontgomeryUInt(bitsize=bitsize) ) - elif isinstance(data, BoundedQUInt): + elif isinstance(data, BQUInt): iteration_length = int_or_sympy_to_proto(data.iteration_length) return data_types_pb2.QDataType( - bounded_quint=data_types_pb2.BoundedQUInt( - bitsize=bitsize, iteration_length=iteration_length - ) + bounded_quint=data_types_pb2.BQUInt(bitsize=bitsize, iteration_length=iteration_length) ) elif isinstance(data, QFxp): num_frac = int_or_sympy_to_proto(data.num_frac) @@ -59,7 +47,7 @@ def data_type_to_proto(data: QDType) -> data_types_pb2.QDataType: raise TypeError( f"Data type {type(data)} is not recognized." " It must be of one of the following subtypes: QBit, " - "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, " + "QAny, QInt, QIntOnesComp, QUInt, BQUInt, " "QFxp, QMontgomeryUInt" ) @@ -86,7 +74,7 @@ def data_type_from_proto(serialized: data_types_pb2.QDataType) -> QDType: elif serialized.HasField('bounded_quint'): bitsize = int_or_sympy_from_proto(serialized.bounded_quint.bitsize) iteration_length = int_or_sympy_from_proto(serialized.bounded_quint.iteration_length) - return BoundedQUInt(bitsize=bitsize, iteration_length=iteration_length) + return BQUInt(bitsize=bitsize, iteration_length=iteration_length) elif serialized.HasField('qfxp'): bitsize = int_or_sympy_from_proto(serialized.qfxp.bitsize) num_frac = int_or_sympy_from_proto(serialized.qfxp.num_frac) @@ -95,6 +83,6 @@ def data_type_from_proto(serialized: data_types_pb2.QDataType) -> QDType: raise TypeError( f"Data type {type(serialized)} is not recognized." " It must be of one of the following subtypes: QBit, " - "QAny, QInt, QIntOnesComp, QUInt, BoundedQUInt, " + "QAny, QInt, QIntOnesComp, QUInt, BQUInt, " "QFxp, QMontgomeryUInt" ) diff --git a/qualtran/serialization/data_types_test.py b/qualtran/serialization/data_types_test.py index 5b500299d..ff88e4e11 100644 --- a/qualtran/serialization/data_types_test.py +++ b/qualtran/serialization/data_types_test.py @@ -17,17 +17,7 @@ import pytest import sympy -from qualtran import ( - BoundedQUInt, - QAny, - QBit, - QDType, - QFxp, - QInt, - QIntOnesComp, - QMontgomeryUInt, - QUInt, -) +from qualtran import BQUInt, QAny, QBit, QDType, QFxp, QInt, QIntOnesComp, QMontgomeryUInt, QUInt from qualtran._infra.data_types import QMontgomeryUInt from qualtran.serialization.data_types import data_type_from_proto, data_type_to_proto @@ -63,7 +53,7 @@ def test_basic_data_types(num_qbits: Union[int, sympy.Expr]): ], ) def test_bounded_quint(num_qbits: int, iteration_length): - round_trip_qdt(BoundedQUInt(num_qbits, iteration_length)) + round_trip_qdt(BQUInt(num_qbits, iteration_length)) @pytest.mark.parametrize( From 6003b8db0307ed23195823fdac7e9cfdf71e71c6 Mon Sep 17 00:00:00 2001 From: Fionn Malone Date: Thu, 29 Aug 2024 22:04:02 +0000 Subject: [PATCH 2/3] Update proto defs too. --- qualtran/protos/data_types.proto | 4 ++-- qualtran/protos/data_types_pb2.py | 14 +++++++------- qualtran/protos/data_types_pb2.pyi | 16 ++++++++-------- qualtran/serialization/data_types.py | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/qualtran/protos/data_types.proto b/qualtran/protos/data_types.proto index 6db632f40..2848ffb0a 100644 --- a/qualtran/protos/data_types.proto +++ b/qualtran/protos/data_types.proto @@ -41,7 +41,7 @@ message QMontgomeryUInt { optional IntOrSympy bitsize = 1; } -message BoundedQUInt { +message BQUInt { optional IntOrSympy bitsize = 1; optional IntOrSympy iteration_length = 2; } @@ -59,7 +59,7 @@ message QDataType { QInt qint = 3; QIntOnesComp qint_ones_comp = 4; QUInt quint = 5; - BoundedQUInt bounded_quint = 6; + BQUInt bquint = 6; QFxp qfxp = 7; QMontgomeryUInt qmontgomery_uint = 8; } diff --git a/qualtran/protos/data_types_pb2.py b/qualtran/protos/data_types_pb2.py index 8087f0324..e7e669456 100644 --- a/qualtran/protos/data_types_pb2.py +++ b/qualtran/protos/data_types_pb2.py @@ -15,7 +15,7 @@ from qualtran.protos import args_pb2 as qualtran_dot_protos_dot_args__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n qualtran/protos/data_types.proto\x12\x08qualtran\x1a\x1aqualtran/protos/args.proto\"\x06\n\x04QBit\">\n\x04QAny\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\">\n\x04QInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"F\n\x0cQIntOnesComp\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"?\n\x05QUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"I\n\x0fQMontgomeryUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"\x90\x01\n\x0c\x42oundedQUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x12\x33\n\x10iteration_length\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x01\x88\x01\x01\x42\n\n\x08_bitsizeB\x13\n\x11_iteration_length\"\x98\x01\n\x04QFxp\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x12+\n\x08num_frac\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x01\x88\x01\x01\x12\x13\n\x06signed\x18\x03 \x01(\x08H\x02\x88\x01\x01\x42\n\n\x08_bitsizeB\x0b\n\t_num_fracB\t\n\x07_signed\"\xce\x02\n\tQDataType\x12\x1e\n\x04qbit\x18\x01 \x01(\x0b\x32\x0e.qualtran.QBitH\x00\x12\x1e\n\x04qany\x18\x02 \x01(\x0b\x32\x0e.qualtran.QAnyH\x00\x12\x1e\n\x04qint\x18\x03 \x01(\x0b\x32\x0e.qualtran.QIntH\x00\x12\x30\n\x0eqint_ones_comp\x18\x04 \x01(\x0b\x32\x16.qualtran.QIntOnesCompH\x00\x12 \n\x05quint\x18\x05 \x01(\x0b\x32\x0f.qualtran.QUIntH\x00\x12/\n\rbounded_quint\x18\x06 \x01(\x0b\x32\x16.qualtran.BoundedQUIntH\x00\x12\x1e\n\x04qfxp\x18\x07 \x01(\x0b\x32\x0e.qualtran.QFxpH\x00\x12\x35\n\x10qmontgomery_uint\x18\x08 \x01(\x0b\x32\x19.qualtran.QMontgomeryUIntH\x00\x42\x05\n\x03valb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n qualtran/protos/data_types.proto\x12\x08qualtran\x1a\x1aqualtran/protos/args.proto\"\x06\n\x04QBit\">\n\x04QAny\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\">\n\x04QInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"F\n\x0cQIntOnesComp\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"?\n\x05QUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"I\n\x0fQMontgomeryUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x42\n\n\x08_bitsize\"\x8a\x01\n\x06\x42QUInt\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x12\x33\n\x10iteration_length\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x01\x88\x01\x01\x42\n\n\x08_bitsizeB\x13\n\x11_iteration_length\"\x98\x01\n\x04QFxp\x12*\n\x07\x62itsize\x18\x01 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x00\x88\x01\x01\x12+\n\x08num_frac\x18\x02 \x01(\x0b\x32\x14.qualtran.IntOrSympyH\x01\x88\x01\x01\x12\x13\n\x06signed\x18\x03 \x01(\x08H\x02\x88\x01\x01\x42\n\n\x08_bitsizeB\x0b\n\t_num_fracB\t\n\x07_signed\"\xc1\x02\n\tQDataType\x12\x1e\n\x04qbit\x18\x01 \x01(\x0b\x32\x0e.qualtran.QBitH\x00\x12\x1e\n\x04qany\x18\x02 \x01(\x0b\x32\x0e.qualtran.QAnyH\x00\x12\x1e\n\x04qint\x18\x03 \x01(\x0b\x32\x0e.qualtran.QIntH\x00\x12\x30\n\x0eqint_ones_comp\x18\x04 \x01(\x0b\x32\x16.qualtran.QIntOnesCompH\x00\x12 \n\x05quint\x18\x05 \x01(\x0b\x32\x0f.qualtran.QUIntH\x00\x12\"\n\x06\x62quint\x18\x06 \x01(\x0b\x32\x10.qualtran.BQUIntH\x00\x12\x1e\n\x04qfxp\x18\x07 \x01(\x0b\x32\x0e.qualtran.QFxpH\x00\x12\x35\n\x10qmontgomery_uint\x18\x08 \x01(\x0b\x32\x19.qualtran.QMontgomeryUIntH\x00\x42\x05\n\x03valb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -34,10 +34,10 @@ _globals['_QUINT']._serialized_end=345 _globals['_QMONTGOMERYUINT']._serialized_start=347 _globals['_QMONTGOMERYUINT']._serialized_end=420 - _globals['_BOUNDEDQUINT']._serialized_start=423 - _globals['_BOUNDEDQUINT']._serialized_end=567 - _globals['_QFXP']._serialized_start=570 - _globals['_QFXP']._serialized_end=722 - _globals['_QDATATYPE']._serialized_start=725 - _globals['_QDATATYPE']._serialized_end=1059 + _globals['_BQUINT']._serialized_start=423 + _globals['_BQUINT']._serialized_end=561 + _globals['_QFXP']._serialized_start=564 + _globals['_QFXP']._serialized_end=716 + _globals['_QDATATYPE']._serialized_start=719 + _globals['_QDATATYPE']._serialized_end=1040 # @@protoc_insertion_point(module_scope) diff --git a/qualtran/protos/data_types_pb2.pyi b/qualtran/protos/data_types_pb2.pyi index d975b5387..ec9125233 100644 --- a/qualtran/protos/data_types_pb2.pyi +++ b/qualtran/protos/data_types_pb2.pyi @@ -126,7 +126,7 @@ class QMontgomeryUInt(google.protobuf.message.Message): global___QMontgomeryUInt = QMontgomeryUInt @typing.final -class BoundedQUInt(google.protobuf.message.Message): +class BQUInt(google.protobuf.message.Message): DESCRIPTOR: google.protobuf.descriptor.Descriptor BITSIZE_FIELD_NUMBER: builtins.int @@ -148,7 +148,7 @@ class BoundedQUInt(google.protobuf.message.Message): @typing.overload def WhichOneof(self, oneof_group: typing.Literal["_iteration_length", b"_iteration_length"]) -> typing.Literal["iteration_length"] | None: ... -global___BoundedQUInt = BoundedQUInt +global___BQUInt = BQUInt @typing.final class QFxp(google.protobuf.message.Message): @@ -189,7 +189,7 @@ class QDataType(google.protobuf.message.Message): QINT_FIELD_NUMBER: builtins.int QINT_ONES_COMP_FIELD_NUMBER: builtins.int QUINT_FIELD_NUMBER: builtins.int - BOUNDED_QUINT_FIELD_NUMBER: builtins.int + BQUINT_FIELD_NUMBER: builtins.int QFXP_FIELD_NUMBER: builtins.int QMONTGOMERY_UINT_FIELD_NUMBER: builtins.int @property @@ -203,7 +203,7 @@ class QDataType(google.protobuf.message.Message): @property def quint(self) -> global___QUInt: ... @property - def bounded_quint(self) -> global___BoundedQUInt: ... + def bquint(self) -> global___BQUInt: ... @property def qfxp(self) -> global___QFxp: ... @property @@ -216,12 +216,12 @@ class QDataType(google.protobuf.message.Message): qint: global___QInt | None = ..., qint_ones_comp: global___QIntOnesComp | None = ..., quint: global___QUInt | None = ..., - bounded_quint: global___BoundedQUInt | None = ..., + bquint: global___BQUInt | None = ..., qfxp: global___QFxp | None = ..., qmontgomery_uint: global___QMontgomeryUInt | None = ..., ) -> None: ... - def HasField(self, field_name: typing.Literal["bounded_quint", b"bounded_quint", "qany", b"qany", "qbit", b"qbit", "qfxp", b"qfxp", "qint", b"qint", "qint_ones_comp", b"qint_ones_comp", "qmontgomery_uint", b"qmontgomery_uint", "quint", b"quint", "val", b"val"]) -> builtins.bool: ... - def ClearField(self, field_name: typing.Literal["bounded_quint", b"bounded_quint", "qany", b"qany", "qbit", b"qbit", "qfxp", b"qfxp", "qint", b"qint", "qint_ones_comp", b"qint_ones_comp", "qmontgomery_uint", b"qmontgomery_uint", "quint", b"quint", "val", b"val"]) -> None: ... - def WhichOneof(self, oneof_group: typing.Literal["val", b"val"]) -> typing.Literal["qbit", "qany", "qint", "qint_ones_comp", "quint", "bounded_quint", "qfxp", "qmontgomery_uint"] | None: ... + def HasField(self, field_name: typing.Literal["bquint", b"bquint", "qany", b"qany", "qbit", b"qbit", "qfxp", b"qfxp", "qint", b"qint", "qint_ones_comp", b"qint_ones_comp", "qmontgomery_uint", b"qmontgomery_uint", "quint", b"quint", "val", b"val"]) -> builtins.bool: ... + def ClearField(self, field_name: typing.Literal["bquint", b"bquint", "qany", b"qany", "qbit", b"qbit", "qfxp", b"qfxp", "qint", b"qint", "qint_ones_comp", b"qint_ones_comp", "qmontgomery_uint", b"qmontgomery_uint", "quint", b"quint", "val", b"val"]) -> None: ... + def WhichOneof(self, oneof_group: typing.Literal["val", b"val"]) -> typing.Literal["qbit", "qany", "qint", "qint_ones_comp", "quint", "bquint", "qfxp", "qmontgomery_uint"] | None: ... global___QDataType = QDataType diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index eda03dbb2..0044db2df 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -36,7 +36,7 @@ def data_type_to_proto(data: QDType) -> data_types_pb2.QDataType: elif isinstance(data, BQUInt): iteration_length = int_or_sympy_to_proto(data.iteration_length) return data_types_pb2.QDataType( - bounded_quint=data_types_pb2.BQUInt(bitsize=bitsize, iteration_length=iteration_length) + bquint=data_types_pb2.BQUInt(bitsize=bitsize, iteration_length=iteration_length) ) elif isinstance(data, QFxp): num_frac = int_or_sympy_to_proto(data.num_frac) @@ -71,7 +71,7 @@ def data_type_from_proto(serialized: data_types_pb2.QDataType) -> QDType: elif serialized.HasField('qmontgomery_uint'): bitsize = int_or_sympy_from_proto(serialized.qmontgomery_uint.bitsize) return QMontgomeryUInt(bitsize=bitsize) - elif serialized.HasField('bounded_quint'): + elif serialized.HasField('bquint'): bitsize = int_or_sympy_from_proto(serialized.bounded_quint.bitsize) iteration_length = int_or_sympy_from_proto(serialized.bounded_quint.iteration_length) return BQUInt(bitsize=bitsize, iteration_length=iteration_length) From 0d638c742714edfe749b71a281e0a1b8541f44b0 Mon Sep 17 00:00:00 2001 From: Fionn Malone Date: Thu, 29 Aug 2024 22:30:40 +0000 Subject: [PATCH 3/3] Fix serialization. --- qualtran/serialization/data_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qualtran/serialization/data_types.py b/qualtran/serialization/data_types.py index 0044db2df..6badc9045 100644 --- a/qualtran/serialization/data_types.py +++ b/qualtran/serialization/data_types.py @@ -72,8 +72,8 @@ def data_type_from_proto(serialized: data_types_pb2.QDataType) -> QDType: bitsize = int_or_sympy_from_proto(serialized.qmontgomery_uint.bitsize) return QMontgomeryUInt(bitsize=bitsize) elif serialized.HasField('bquint'): - bitsize = int_or_sympy_from_proto(serialized.bounded_quint.bitsize) - iteration_length = int_or_sympy_from_proto(serialized.bounded_quint.iteration_length) + bitsize = int_or_sympy_from_proto(serialized.bquint.bitsize) + iteration_length = int_or_sympy_from_proto(serialized.bquint.iteration_length) return BQUInt(bitsize=bitsize, iteration_length=iteration_length) elif serialized.HasField('qfxp'): bitsize = int_or_sympy_from_proto(serialized.qfxp.bitsize)