2121from numpy .typing import NDArray
2222
2323from qualtran import BloqBuilder , BoundedQUInt , QBit , Register , SoquetT
24- from qualtran .bloqs .for_testing .random_gate import RandomGate
24+ from qualtran .bloqs .for_testing .matrix_gate import MatrixGate
2525from qualtran .bloqs .qubitization_walk_operator import QubitizationWalkOperator
2626from qualtran .bloqs .select_and_prepare import PrepareOracle , SelectOracle
2727
2828
2929@frozen
30- class RandomPrepareOracle (PrepareOracle ):
31- r"""Gate that prepares a randomly chosen state with real amplitudes.
30+ class TestPrepareOracle (PrepareOracle ):
31+ r"""Gate that prepares a fixed state with real amplitudes using a MatrixGate .
3232
3333 It is an $n$-qubit unitary $U$ such that
3434
@@ -39,13 +39,13 @@ class RandomPrepareOracle(PrepareOracle):
3939 where $\alpha_x \ge 0$ such that $\sum_x \alpha_x = 1$.
4040
4141 Args:
42- U: A `RandomGate ` whose matrix is the unitary of the oracle.
42+ U: A `MatrixGate ` whose matrix is the unitary of the oracle.
4343
4444 Registers:
4545 selection: $n$-qubit register
4646 """
4747
48- U : RandomGate
48+ U : MatrixGate
4949
5050 def __attrs_post_init__ (self ):
5151 # check that first column is all reals
@@ -57,32 +57,28 @@ def selection_registers(self) -> tuple[Register, ...]:
5757 return (Register ('selection' , BoundedQUInt (bitsize = self .U .bitsize )),)
5858
5959 @classmethod
60- def create (cls , bitsize : int , * , random_state : np .random .RandomState ):
61- matrix = RandomGate .create (bitsize , random_state = random_state ).matrix
60+ def random (cls , bitsize : int , * , random_state : np .random .RandomState ):
61+ """Generate a random unitary s.t. the first column has all real amplitudes"""
62+ matrix = MatrixGate .random (bitsize , random_state = random_state ).matrix
6263 matrix = np .array (matrix )
6364
6465 # make the first column (weights \sqrt{alpha_i}) all reals
6566 column = matrix [:, 0 ]
6667 matrix = matrix * (column .conj () / np .abs (column ))[:, None ]
6768
68- return cls (RandomGate (bitsize , matrix ))
69+ return cls (MatrixGate (bitsize , matrix ))
6970
7071 def build_composite_bloq (self , bb : BloqBuilder , selection : SoquetT ) -> dict [str , SoquetT ]:
7172 selection = bb .add (self .U , q = selection )
7273 return {'selection' : selection }
7374
74- def __pow__ (self , power ):
75- if power == - 1 :
76- return self .U .adjoint ()
77- return NotImplemented
78-
7975 @cached_property
8076 def alphas (self ):
8177 return np .array (self .U .matrix )[:, 0 ] ** 2
8278
8379
8480@frozen
85- class PauliSelectOracle (SelectOracle ):
81+ class TestPauliSelectOracle (SelectOracle ):
8682 r"""Paulis acting on $m$ qubits, controlled by an $n$-qubit register.
8783
8884 Given $2^n$ multi-qubit-Paulis (acting on $m$ qubits) $U_j$,
@@ -113,7 +109,7 @@ class PauliSelectOracle(SelectOracle):
113109 @classmethod
114110 def random (
115111 cls , select_bitsize : int , target_bitsize : int , * , random_state : np .random .RandomState
116- ) -> 'PauliSelectOracle ' :
112+ ) -> 'TestPauliSelectOracle ' :
117113 dps = tuple (
118114 cirq .DensePauliString (random_state .randint (0 , 4 , size = target_bitsize ))
119115 for _ in range (2 ** select_bitsize )
@@ -197,8 +193,8 @@ def random_qubitization_walk_operator(
197193 Returns:
198194 WalkOperator for $H$, and the Hamiltonian $H$.
199195 """
200- prepare = RandomPrepareOracle . create (select_bitsize , random_state = random_state )
201- select = PauliSelectOracle .random (select_bitsize , target_bitsize , random_state = random_state )
196+ prepare = TestPrepareOracle . random (select_bitsize , random_state = random_state )
197+ select = TestPauliSelectOracle .random (select_bitsize , target_bitsize , random_state = random_state )
202198
203199 np .testing .assert_allclose (np .linalg .norm (prepare .alphas , 1 ), 1 )
204200
0 commit comments