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

Conversation

Misty-W
Copy link
Collaborator

@Misty-W Misty-W commented Feb 26, 2025

Fixes #255.

A natural choice of observable for the QAOA circuits is the problem Hamiltonian, instead of the default "ZZZZ..." observable.

In https://arxiv.org/pdf/2009.01095, we see that the problem Hamiltonian for a weighted graph with binary encoding is:

$$H_P = \sum_{i,j \in E} w_{i,j}H_{i,j}$$

where the matrix $H_{i,j}$ is a diagonal matrix modeling the interaction between vertices $i$ and $j$, and $w_{i,j}$ is the weight of the edge between vertices i and j as well as the resulting unitary evolution.

For $k = 2$, which corresponds to one qubit per vertex of the graph, the local Hamiltonian is

$$H_{ij} = diag([1, -1, -1, 1])$$

which can be written

$$H_{ij} = \sigma_z(i) \sigma_z(j)$$

@Misty-W Misty-W requested a review from natestemen February 26, 2025 18:31
Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

Can you help me understand how this observable is chosen?

Starting from the circuit we are running: qaoa_barabasi_albert which comes from benchpress. I don't know much about this circuit, but I assume it is trying to solve some problem related to the Barabási-Albert model. Naively, I wouldn't expect this QAOA circuit to have the same Hamiltonian as a QAOA circuit solving a MAXCUT problem. My knowledge of QAOA is quite limited, so I may be missing something.

It's unfortunate that there isn't more documentation on this circuit in benchpress.

@Misty-W
Copy link
Collaborator Author

Misty-W commented Feb 26, 2025

Can you help me understand how this observable is chosen?

It's unfortunate that there isn't more documentation on this circuit in benchpress.

Since I was unable to find the problem Hamiltonian or any other observable used in Benchpress, I looked in the literature for QAOA approaches to solving Barabasi-Albert weighted graphs and found the paper I linked in this PR.
Although the authors use MAXCUT to illustrate the binary encoding and "one-hot" encoding methods, the authors mention that they applied both methods to solving a Barabasi-Albert weighted graph and report the results.

Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

Ah okay, thanks for the explanation, that helps me understand much more (and more than the reading I was doing). I wonder if we should reach out to the benchpress team to get some info on how the qaoa circuits are generated and ask what Hamiltonian they are using.

I have at one blocking comment, and one question.

@@ -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!

Use `qiskit.quantum_info.SparsePauliOp` to construct problem Hamiltonian for QAOA observable
@Misty-W Misty-W requested a review from natestemen March 4, 2025 18:55
Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

Nice! I was initially a little worried about using SparsePauliOp instead of an instance of Operator (since that what density_matrix.expectation_value expects), but it turns out that they are both derived from LinearOp, so all checks out.

How does this impact results?

@Misty-W Misty-W merged commit ac149bd into main Mar 4, 2025
2 checks passed
@Misty-W Misty-W deleted the 170-implement-custom-observables-for-each-benchmark branch March 4, 2025 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom observable for QAOA
3 participants