Skip to content

Commit

Permalink
fix(algorithms): make qnn forward and backward consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaoyilunnn committed Sep 10, 2024
1 parent 2bae7f0 commit dff492d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion quafu/algorithms/gradients/param_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __call__(self, obs: Hamiltonian, params: List[float]):
estimator (Estimator): estimator to calculate expectation values
params (List[float]): params to optimize
"""
if self._est._backend != "sim":
return self.grad(obs, params)
return self.new_grad(obs, params)

def _gen_param_shift_vals(self, params):
Expand All @@ -46,7 +48,6 @@ def _gen_param_shift_vals(self, params):
minus_params = params - offsets * np.pi / 2
return plus_params.tolist() + minus_params.tolist()

# TODO: delete after 0.4.1
def grad(self, obs: Hamiltonian, params: List[float]):
"""grad.
Expand Down

0 comments on commit dff492d

Please sign in to comment.