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

Change QAOA observable to problem Hamiltonian #260

Merged
merged 6 commits into from
Mar 4, 2025
Merged
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
33 changes: 31 additions & 2 deletions benchmarks/scripts/expval_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,37 @@ def simulate_expvals(

else:
density_matrix = simulate_density_matrix(compiled_circuit)
obs_str = "Z" * compiled.num_qubits
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable obs_str still needs to be set in order to be recorded in the results.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I wonder why it didn't raise an error when I ran it. Let me check again...

Copy link
Collaborator Author

@Misty-W Misty-W Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both issues are fixed-

  1. I set obs_str to "H_p" (problem Hamiltonian) because the sum of Pauli strings is way too long to display.
  2. The missing obs_str didn't throw an error because the 'if' statement should have read if circuit_name == "qaoa_barabasi_albert" not if circuit_name == "qaoa"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using H_p doesn't seem ideal, but a good compromise. We should record the observable string somewhere for easy reference.

Good find with that bug!

observable = Operator.from_label(obs_str)
if circuit_name == "qaoa":
observable = Operator(
np.diag(
[
1,
-1,
-1,
-1,
-1,
1,
-1,
-1,
-1,
-1,
1,
-1,
-1,
-1,
-1,
1,
-1,
-1,
-1,
1,
]
)
)

else:
obs_str = "Z" * compiled_circuit.num_qubits
observable = Operator.from_label(obs_str)

compiled_ev = np.real(density_matrix.expectation_value(observable))

Expand Down