17
17
import numpy as np
18
18
import scipy
19
19
import sympy
20
- from attrs import frozen
20
+ from attrs import field , frozen
21
21
22
22
from qualtran import Bloq , bloq_example , BloqBuilder , BloqDocSpec , Signature , SoquetT
23
23
from qualtran .bloqs .state_preparation .black_box_prepare import BlackBoxPrepare
@@ -219,6 +219,7 @@ class PlantedNoisyKXOR(Bloq):
219
219
inst_solve : KXorInstance
220
220
ell : SymbolicInt
221
221
rho : SymbolicFloat
222
+ _guiding_state_overlap : Optional [SymbolicFloat ] = field (kw_only = True , default = None )
222
223
223
224
def __attrs_post_init__ (self ):
224
225
k = self .inst_guide .k
@@ -242,6 +243,7 @@ def from_inst(
242
243
* ,
243
244
zeta : Optional [SymbolicFloat ],
244
245
rng : np .random .Generator ,
246
+ guiding_state_overlap : Optional [SymbolicFloat ] = None ,
245
247
):
246
248
(use_for_guide ,) = np .nonzero (np .atleast_1d (rng .random (inst .m ) < zeta ))
247
249
inst_guide = inst .subset (tuple (use_for_guide ))
@@ -254,7 +256,13 @@ def from_inst(
254
256
(rest ,) = np .nonzero (mask )
255
257
inst_solve = inst .subset (tuple (rest ))
256
258
257
- return cls (inst_guide = inst_guide , inst_solve = inst_solve , ell = ell , rho = rho )
259
+ return cls (
260
+ inst_guide = inst_guide ,
261
+ inst_solve = inst_solve ,
262
+ ell = ell ,
263
+ rho = rho ,
264
+ guiding_state_overlap = guiding_state_overlap ,
265
+ )
258
266
259
267
@cached_property
260
268
def guiding_state_and_coefficient (self ) -> tuple [PrepareOracle , SymbolicFloat ]:
@@ -286,10 +294,17 @@ def guiding_state_overlap_guarantee(self) -> GuidingStateOverlapTheorem:
286
294
n = n , k = k , ell = self .ell , m_hat = m_hat , zeta = zeta , nu = 1 / ln (n ), eps = 0.005 , rho = self .rho
287
295
)
288
296
297
+ @cached_property
298
+ def guiding_state_overlap (self ) -> SymbolicFloat :
299
+ if self ._guiding_state_overlap is not None :
300
+ return self .guiding_state_overlap
301
+ _ , guiding_state_good_coeff = self .guiding_state_and_coefficient
302
+ return guiding_state_good_coeff
303
+
289
304
@cached_property
290
305
def overlap (self ) -> SymbolicFloat :
291
306
# guiding state
292
- _ , guiding_state_good_coeff = self .guiding_state_and_coefficient
307
+ guiding_state_good_coeff = self .guiding_state_overlap
293
308
294
309
# overlap of |\Gamma(A)> with the threshold eigenspace
295
310
overlap_good_eigen = self .guiding_state_overlap_guarantee .overlap_probability ** 0.5
@@ -330,6 +345,8 @@ def guided_hamiltonian_bloq(self) -> GuidedHamiltonian:
330
345
kappa = 0.99 * self .rho
331
346
eps = 0.005
332
347
alpha = 1 - (kappa + eps ) / eigenvalue_threshold
348
+ if not is_symbolic (alpha ):
349
+ assert alpha > 0
333
350
334
351
guiding_state , _ = self .guiding_state_and_coefficient
335
352
0 commit comments