Closed dariavh closed 1 year ago
Hi Daria,
the reason is the error resulting from the finite sampling of the expectation value.
energy = tq.compile(E)
exact_expectation_value = energy(variables)
finite_sampling_value1 = energy(variables, samples=1000)
finite_sampling_value2 = energy(variables, samples=1000)
the finite_sampling_valueX
results will fluctuate around exact_expectation_value
.
It depends a bit, on what you are interested in with the current simulation, but in general, I would recommend exact simulation: Faster, and you get a deterministic result corresponding to the samples-->infinity limit.
As a ballpark number, I think most experiments use ~10k samples.
Hope that helps.
Hi Jakob,
The finite sampling is just something I am testing out for a research idea 🙂thank you for the prompt reply and resolving my issue!
Describe the bug I optimized the expectation value of a simple toy Hamiltonian over a quantum circuit with four adjustable variables and got an optimal VQE energy of approx. -1.645. When I try to simulate the expectation value of the same Hamiltonian with the optimal VQE parameters, I get a different value from the optimal VQE energy. I'm not sure if I might be overlooking something fundamental or if there's a potential issue in my approach.
To Reproduce Steps to reproduce the behavior:
This code block prints:
Expected behavior I expect the last line in the code block to print two identical expectation values.
Computer: