Hi @adityab,
You uncovered some really interesting things!
- The hidden factor of 1/4 seems to be coming from a normalization in the edge_driver function (used internally by
qaoa.max_clique). The demo’s cost Hamiltonian formula is missing this 1/4 factor on the edge penalty terms. Both Hamiltonians share the same ground state, so the optimization result is unaffected, but the formula and the code output don’t match. Great catch here! - This is related to the missing factor of 1/4 too (plus another error).
- Since the factor of 1/4 was missing in the formula for Hc, it’s also missing in the commutator and it’s also missing in the
build_hamiltonianformula. The factor there should be 6/4 instead of 6. - In addition to this, the second term in Hc has factor 1 so the second term in the commutator should have factor 1, so the terms in the second sum in
build_hamiltonianshould have factor 2.
- Since the factor of 1/4 was missing in the formula for Hc, it’s also missing in the commutator and it’s also missing in the
Despite these mismatches, the FALQON algorithm converges because:
- The sign of β_k = −⟨i[H_d, H_c]⟩ is preserved (the operator structure is correct, only the magnitudes differ)
- The magnitude difference is effectively absorbed into the hyperparameter Δt
- The guarantee d/dt ⟨H_c⟩ ≤ 0 holds as long as β(t) has the correct sign
For larger/general problems, you can bypass build_hamiltonian entirely and just use qml.commutator. I’m not completely sure that the code below would work but you could give it a try.
cost_h, driver_h = qaoa.max_clique(graph, constrained=False)
comm_h = qml.simplify(1j * qml.commutator(driver_h, cost_h))
This would give the mathematically exact i[H_d, H_c] for the actual cost_h returned by PennyLane, and it should work for any graph.
Let me know if this helps!