@@ -36,23 +36,25 @@ def get_cost_diagonal(self) -> np.ndarray:
3636 @property
3737 def default_sv0 (self ):
3838 return np .full (self .n_states , 1.0 / np .sqrt (self .n_states ), dtype = "complex" )
39-
39+
4040 def warmstart_sv0 (self , init_rots ):
4141 state = 1.0
4242 for init_rot in init_rots :
43- qubit_state = np .array ([
44- np .cos (init_rot / 2 ),
45- # np.exp(-1j*np.pi/2)*np.sin(init_rot/2)
46- np .sin (init_rot / 2 )
47- ])
43+ qubit_state = np .array (
44+ [
45+ np .cos (init_rot / 2 ),
46+ # np.exp(-1j*np.pi/2)*np.sin(init_rot/2)
47+ np .sin (init_rot / 2 ),
48+ ]
49+ )
4850 # state = np.kron(state, qubit_state) #original as GW
4951 state = np .kron (qubit_state , state )
50-
52+
5153 return state
5254
5355 def _apply_qaoa (self , sv : np .ndarray , gammas : Sequence [float ], betas : Sequence [float ], ** kwargs ):
5456 raise NotImplementedError
55-
57+
5658 def simulate_ws_qaoa (
5759 self ,
5860 gammas : ParamType ,
@@ -69,11 +71,11 @@ def simulate_ws_qaoa(
6971 @return statevector or vector of probabilities
7072 """
7173 sv = sv0 .astype ("complex" ) if sv0 is not None else self .warmstart_sv0 (init_rots ).astype ("complex" )
72- assert np .isclose (np .sum (np .abs (sv ** 2 )), 1 )
74+ assert np .isclose (np .sum (np .abs (sv ** 2 )), 1 )
7375 self ._apply_qaoa (sv , list (gammas ), list (betas ), init_rots , ** kwargs )
74- assert np .isclose (np .sum (np .abs (sv ** 2 )), 1 )
76+ assert np .isclose (np .sum (np .abs (sv ** 2 )), 1 )
7577 return sv
76-
78+
7779 def simulate_qaoa (
7880 self ,
7981 gammas : ParamType ,
@@ -106,14 +108,13 @@ def get_expectation(self, result: np.ndarray, costs: np.ndarray | None = None, o
106108 if optimization_type == "max" :
107109 return - 1 * np .dot (costs , np .abs (result ) ** 2 )
108110 return np .dot (costs , np .abs (result ) ** 2 )
109-
111+
110112 def get_std (self , result : np .ndarray , costs : np .ndarray | None = None , ** kwargs ) -> float :
111113 if costs is None :
112114 costs = self ._hc_diag
113115 probs = np .abs (result ) ** 2
114116 return np .sqrt (max (np .dot (costs ** 2 , probs ) - np .dot (costs , probs ) ** 2 , 0 ))
115117
116-
117118 def get_overlap (
118119 self , result : np .ndarray , costs : CostsType | None = None , indices : np .ndarray | Sequence [int ] | None = None , optimization_type = "min" , ** kwargs
119120 ) -> float :
@@ -145,10 +146,12 @@ class QAOAFURXSimulator(QAOAFastSimulatorPythonBase):
145146 def _apply_qaoa (self , sv : np .ndarray , gammas : Sequence [float ], betas : Sequence [float ], ** kwargs ):
146147 apply_qaoa_furx (sv , gammas , betas , self ._hc_diag , self .n_qubits )
147148
149+
148150class QAOAFURXZSimulator (QAOAFastSimulatorPythonBase ):
149151 def _apply_qaoa (self , sv : np .ndarray , gammas : Sequence [float ], betas : Sequence [float ], init_rots : Sequence [float ], ** kwargs ):
150152 apply_qaoa_furxz (sv , gammas , betas , init_rots , self ._hc_diag , self .n_qubits )
151153
154+
152155class QAOAFURXYRingSimulator (QAOAFastSimulatorPythonBase ):
153156 def _apply_qaoa (self , sv : np .ndarray , gammas : Sequence [float ], betas : Sequence [float ], ** kwargs ):
154157 n_trotters = kwargs .get ("n_trotters" , 1 )
0 commit comments