@@ -103,36 +103,33 @@ def test_sparse_matrix_tensors():
103103 np .testing .assert_allclose (from_gate , from_tensors )
104104
105105
106- rs = np .random .RandomState (1234 )
107-
108-
109- def gen_test ():
110- n = rs .randint (1 , 3 )
111- N = 2 ** n
112- data = rs .rand (N , N )
113- return n , data
114-
115-
116106@pytest .mark .slow
117- @pytest .mark .parametrize (
118- "n,data" , [(1 , [[0.0 , 0.25 ], [1 / 3 , 0.467 ]])] + [gen_test () for _ in range (10 )]
119- )
120- def test_explicit_entry_oracle (n , data ):
121- row_oracle = TopLeftRowColumnOracle (n )
122- col_oracle = TopLeftRowColumnOracle (n )
123- entry_oracle = ExplicitEntryOracle (n , data = data , entry_bitsize = 10 )
124- bloq = SparseMatrix (row_oracle , col_oracle , entry_oracle , eps = 0 )
107+ def test_explicit_entry_oracle ():
108+ rs = np .random .RandomState (1234 )
125109
126- alpha = bloq .alpha
127- bb = BloqBuilder ()
128- system = bb .add_register ("system" , n )
129- ancilla = cast (Soquet , bb .add (IntState (0 , n + 1 )))
130- system , ancilla = bb .add_t (bloq , system = system , ancilla = ancilla )
131- bb .add (IntEffect (0 , n + 1 ), val = ancilla )
132- bloq = bb .finalize (system = system )
110+ def gen_test ():
111+ n = rs .randint (1 , 3 )
112+ N = 2 ** n
113+ data = rs .rand (N , N )
114+ return n , data
133115
134- from_tensors = bloq .tensor_contract () * alpha
135- np .testing .assert_allclose (data , from_tensors , atol = 0.003 )
116+ tests = [(1 , [[0.0 , 0.25 ], [1 / 3 , 0.467 ]])] + [gen_test () for _ in range (10 )]
117+ for n , data in tests :
118+ row_oracle = TopLeftRowColumnOracle (n )
119+ col_oracle = TopLeftRowColumnOracle (n )
120+ entry_oracle = ExplicitEntryOracle (n , data = data , entry_bitsize = 10 )
121+ bloq = SparseMatrix (row_oracle , col_oracle , entry_oracle , eps = 0 )
122+
123+ alpha = bloq .alpha
124+ bb = BloqBuilder ()
125+ system = bb .add_register ("system" , n )
126+ ancilla = cast (Soquet , bb .add (IntState (0 , n + 1 )))
127+ system , ancilla = bb .add_t (bloq , system = system , ancilla = ancilla )
128+ bb .add (IntEffect (0 , n + 1 ), val = ancilla )
129+ bloq = bb .finalize (system = system )
130+
131+ from_tensors = bloq .tensor_contract () * alpha
132+ np .testing .assert_allclose (data , from_tensors , atol = 0.003 )
136133
137134
138135topleft_matrix = [
0 commit comments