Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PVQD loss function #9371

Merged
merged 4 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions qiskit/algorithms/time_evolvers/pvqd/pvqd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019, 2022.
# (C) Copyright IBM 2019, 2022, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -270,7 +270,7 @@ def evaluate_loss(displacement: np.ndarray | list[np.ndarray]) -> float | list[f
# the first state does not have free parameters so values_1 will be None by default
try:
job = self.fidelity_primitive.run(states1, states2, values_2=param_dicts2)
fidelities = job.result().fidelities
fidelities = np.array(job.result().fidelities)
except Exception as exc:
raise AlgorithmError("The primitive job failed!") from exc

Expand All @@ -279,7 +279,7 @@ def evaluate_loss(displacement: np.ndarray | list[np.ndarray]) -> float | list[f

# in principle, we could add different loss functions here, but we're currently
# not aware of a use-case for a different one than in the paper
return 1 - np.abs(fidelities) ** 2
return 1 - fidelities

if _is_gradient_supported(ansatz) and self.use_parameter_shift:

Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-pvqd-loss-cb1ebe0258f225de.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fixed loss function in PVQD. Removed extra abs**2 that is already covered by the fidelity primitive
gentinettagian marked this conversation as resolved.
Show resolved Hide resolved