From 5fbfe53e685d713c1a11e6a0138764fd3fa5d972 Mon Sep 17 00:00:00 2001 From: Charles Yuan Date: Wed, 7 Aug 2024 12:48:03 -0700 Subject: [PATCH] Switch `BlockEncoding.signal_state` to `BlackBoxPrepare` (#1259) --- qualtran/bloqs/block_encoding/block_encoding_base.py | 4 ++-- qualtran/bloqs/block_encoding/chebyshev_polynomial.py | 6 +++--- .../bloqs/block_encoding/chebyshev_polynomial_test.py | 4 ++-- qualtran/bloqs/block_encoding/linear_combination.py | 4 ++-- qualtran/bloqs/block_encoding/phase.py | 4 ++-- qualtran/bloqs/block_encoding/product.py | 4 ++-- qualtran/bloqs/block_encoding/sparse_matrix.py | 4 ++-- qualtran/bloqs/block_encoding/tensor_product.py | 4 ++-- qualtran/bloqs/block_encoding/unitary.py | 4 ++-- qualtran/bloqs/chemistry/df/double_factorization.py | 10 +++++----- qualtran/bloqs/chemistry/sf/single_factorization.py | 10 +++++----- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/qualtran/bloqs/block_encoding/block_encoding_base.py b/qualtran/bloqs/block_encoding/block_encoding_base.py index a2df01974..c1cb8ad4f 100644 --- a/qualtran/bloqs/block_encoding/block_encoding_base.py +++ b/qualtran/bloqs/block_encoding/block_encoding_base.py @@ -14,7 +14,7 @@ import abc from qualtran import Bloq, BloqDocSpec -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.symbolics import SymbolicFloat, SymbolicInt @@ -94,7 +94,7 @@ def epsilon(self) -> SymbolicFloat: @property @abc.abstractmethod - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: r"""Returns the signal / ancilla flag state $|G\rangle.""" diff --git a/qualtran/bloqs/block_encoding/chebyshev_polynomial.py b/qualtran/bloqs/block_encoding/chebyshev_polynomial.py index 9d406fbd8..a6d35bd99 100644 --- a/qualtran/bloqs/block_encoding/chebyshev_polynomial.py +++ b/qualtran/bloqs/block_encoding/chebyshev_polynomial.py @@ -31,7 +31,7 @@ from qualtran.bloqs.block_encoding import BlockEncoding from qualtran.bloqs.block_encoding.linear_combination import LinearCombination from qualtran.bloqs.reflections.reflection_using_prepare import ReflectionUsingPrepare -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.symbolics import is_symbolic, SymbolicFloat, SymbolicInt if TYPE_CHECKING: @@ -108,7 +108,7 @@ def epsilon(self) -> SymbolicFloat: return self.block_encoding.epsilon * self.order @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # Github issue: https://github.com/quantumlib/Qualtran/issues/1104 @@ -242,7 +242,7 @@ def selection_registers(self) -> Tuple[Register, ...]: return (self.signature.get_right("ancilla"),) if self.ancilla_bitsize > 0 else () @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # Github issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/block_encoding/chebyshev_polynomial_test.py b/qualtran/bloqs/block_encoding/chebyshev_polynomial_test.py index f7577e931..d38b062c4 100644 --- a/qualtran/bloqs/block_encoding/chebyshev_polynomial_test.py +++ b/qualtran/bloqs/block_encoding/chebyshev_polynomial_test.py @@ -31,7 +31,7 @@ ChebyshevPolynomial, ) from qualtran.bloqs.for_testing.matrix_gate import MatrixGate -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.linalg.matrix import random_hermitian_matrix from qualtran.symbolics import is_symbolic, SymbolicFloat, SymbolicInt from qualtran.testing import assert_equivalent_bloq_example_counts, execute_notebook @@ -189,7 +189,7 @@ def signature(self) -> Signature: return Signature.build(system=1, ancilla=1, resource=1) @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: raise NotImplementedError def build_composite_bloq( diff --git a/qualtran/bloqs/block_encoding/linear_combination.py b/qualtran/bloqs/block_encoding/linear_combination.py index 71574d745..a2c984184 100644 --- a/qualtran/bloqs/block_encoding/linear_combination.py +++ b/qualtran/bloqs/block_encoding/linear_combination.py @@ -36,7 +36,7 @@ from qualtran.bloqs.block_encoding.phase import Phase from qualtran.bloqs.bookkeeping.auto_partition import AutoPartition, Unused from qualtran.bloqs.bookkeeping.partition import Partition -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.linalg.lcu_util import preprocess_probabilities_for_reversible_sampling from qualtran.symbolics import smax, ssum, SymbolicFloat, SymbolicInt from qualtran.symbolics.types import is_symbolic @@ -170,7 +170,7 @@ def epsilon(self) -> SymbolicFloat: ) @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # GitHub issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/block_encoding/phase.py b/qualtran/bloqs/block_encoding/phase.py index f515508d8..7a008f3f1 100644 --- a/qualtran/bloqs/block_encoding/phase.py +++ b/qualtran/bloqs/block_encoding/phase.py @@ -20,7 +20,7 @@ from qualtran import bloq_example, BloqBuilder, BloqDocSpec, QAny, Signature, SoquetT from qualtran.bloqs.basic_gates import GlobalPhase from qualtran.bloqs.block_encoding import BlockEncoding -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.resource_counting import BloqCountT, SympySymbolAllocator from qualtran.symbolics import SymbolicFloat, SymbolicInt @@ -79,7 +79,7 @@ def pretty_name(self) -> str: return f"B[exp({self.phi}i){self.block_encoding.pretty_name()[2:-1]}]" @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # GitHub issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/block_encoding/product.py b/qualtran/bloqs/block_encoding/product.py index a5803c24d..d75c70be7 100644 --- a/qualtran/bloqs/block_encoding/product.py +++ b/qualtran/bloqs/block_encoding/product.py @@ -37,7 +37,7 @@ from qualtran.bloqs.bookkeeping.auto_partition import AutoPartition, Unused from qualtran.bloqs.bookkeeping.partition import Partition from qualtran.bloqs.mcmt.multi_control_multi_target_pauli import MultiControlPauli -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.symbolics import is_symbolic, prod, smax, ssum, SymbolicFloat, SymbolicInt @@ -125,7 +125,7 @@ def epsilon(self) -> SymbolicFloat: return ssum(u.alpha * u.epsilon for u in self.block_encodings) @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # Github issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/block_encoding/sparse_matrix.py b/qualtran/bloqs/block_encoding/sparse_matrix.py index 08fb01d35..8279da381 100644 --- a/qualtran/bloqs/block_encoding/sparse_matrix.py +++ b/qualtran/bloqs/block_encoding/sparse_matrix.py @@ -41,7 +41,7 @@ from qualtran.bloqs.block_encoding import BlockEncoding from qualtran.bloqs.bookkeeping.auto_partition import AutoPartition, Unused from qualtran.bloqs.data_loading import QROM -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.bloqs.state_preparation.prepare_uniform_superposition import ( PrepareUniformSuperposition, ) @@ -209,7 +209,7 @@ def epsilon(self) -> SymbolicFloat: return self.eps @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # Github issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/block_encoding/tensor_product.py b/qualtran/bloqs/block_encoding/tensor_product.py index cf892a2c0..62c49a474 100644 --- a/qualtran/bloqs/block_encoding/tensor_product.py +++ b/qualtran/bloqs/block_encoding/tensor_product.py @@ -30,7 +30,7 @@ ) from qualtran.bloqs.block_encoding import BlockEncoding from qualtran.bloqs.bookkeeping import Partition -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.resource_counting import BloqCountT, SympySymbolAllocator from qualtran.symbolics import is_symbolic, prod, ssum, SymbolicFloat, SymbolicInt @@ -101,7 +101,7 @@ def epsilon(self) -> SymbolicFloat: return ssum(u.alpha * u.epsilon for u in self.block_encodings) @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # Github issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/block_encoding/unitary.py b/qualtran/bloqs/block_encoding/unitary.py index 4db1c27e0..d9bd94c55 100644 --- a/qualtran/bloqs/block_encoding/unitary.py +++ b/qualtran/bloqs/block_encoding/unitary.py @@ -19,7 +19,7 @@ from qualtran import Bloq, bloq_example, BloqBuilder, BloqDocSpec, QAny, Side, Signature, SoquetT from qualtran.bloqs.block_encoding import BlockEncoding -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare from qualtran.resource_counting import BloqCountT, SympySymbolAllocator from qualtran.symbolics import SymbolicFloat, SymbolicInt @@ -73,7 +73,7 @@ def pretty_name(self) -> str: return f"B[{self.U.pretty_name()}]" @property - def signal_state(self) -> PrepareOracle: + def signal_state(self) -> BlackBoxPrepare: # This method will be implemented in the future after PrepareOracle # is updated for the BlockEncoding interface. # Github issue: https://github.com/quantumlib/Qualtran/issues/1104 diff --git a/qualtran/bloqs/chemistry/df/double_factorization.py b/qualtran/bloqs/chemistry/df/double_factorization.py index a86cee3f6..6366b3fed 100644 --- a/qualtran/bloqs/chemistry/df/double_factorization.py +++ b/qualtran/bloqs/chemistry/df/double_factorization.py @@ -60,7 +60,7 @@ from qualtran.bloqs.chemistry.df.select_bloq import ProgRotGateArray from qualtran.bloqs.reflections.prepare_identity import PrepareIdentity from qualtran.bloqs.reflections.reflection_using_prepare import ReflectionUsingPrepare -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare if TYPE_CHECKING: from qualtran.resource_counting import BloqCountT, SympySymbolAllocator @@ -166,8 +166,8 @@ def target_registers(self) -> Iterable[Register]: return (Register("sys", QAny(bitsize=self.num_spin_orb // 2), shape=(2,)),) @property - def signal_state(self) -> PrepareOracle: - return PrepareIdentity(self.selection_registers) + def signal_state(self) -> BlackBoxPrepare: + return BlackBoxPrepare(PrepareIdentity(self.selection_registers)) @cached_property def signature(self) -> Signature: @@ -414,8 +414,8 @@ def target_registers(self) -> Iterable[Register]: return (Register("sys", QAny(bitsize=self.num_spin_orb // 2), shape=(2,)),) @property - def signal_state(self) -> PrepareOracle: - return PrepareIdentity(self.selection_registers) + def signal_state(self) -> BlackBoxPrepare: + return BlackBoxPrepare(PrepareIdentity(self.selection_registers)) @cached_property def signature(self) -> Signature: diff --git a/qualtran/bloqs/chemistry/sf/single_factorization.py b/qualtran/bloqs/chemistry/sf/single_factorization.py index 50c50cea5..80e346560 100644 --- a/qualtran/bloqs/chemistry/sf/single_factorization.py +++ b/qualtran/bloqs/chemistry/sf/single_factorization.py @@ -52,7 +52,7 @@ from qualtran.bloqs.chemistry.sf.select_bloq import SelectSingleFactorization from qualtran.bloqs.reflections.prepare_identity import PrepareIdentity from qualtran.bloqs.reflections.reflection_using_prepare import ReflectionUsingPrepare -from qualtran.bloqs.state_preparation.prepare_base import PrepareOracle +from qualtran.bloqs.state_preparation.black_box_prepare import BlackBoxPrepare if TYPE_CHECKING: from qualtran.resource_counting import BloqCountT, SympySymbolAllocator @@ -176,8 +176,8 @@ def junk_registers(self) -> Iterable[Register]: return () @property - def signal_state(self) -> PrepareOracle: - return PrepareIdentity(self.selection_registers) + def signal_state(self) -> BlackBoxPrepare: + return BlackBoxPrepare(PrepareIdentity(self.selection_registers)) @cached_property def signature(self) -> Signature: @@ -381,8 +381,8 @@ def signature(self) -> Signature: ) @property - def signal_state(self) -> PrepareOracle: - return PrepareIdentity(self.selection_registers) + def signal_state(self) -> BlackBoxPrepare: + return BlackBoxPrepare(PrepareIdentity(self.selection_registers)) def build_composite_bloq( self,