-
Notifications
You must be signed in to change notification settings - Fork 187
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
Fixed Depth Hamiltonian Simulation via Cartan Decomposition demo #1261
base: master
Are you sure you want to change the base?
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
h_0_m = Kc_m @ H_m @ Kc_m.conj().T | ||
h_0 = qml.pauli_decompose(h_0_m) | ||
print(len(h_0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the resulting h_0 is actually not in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it to work.
I did the following tweaks (took some time 😅 )
gammas = [np.pi**i % 2 for i in range(1, len(h)+1)]
instead ofgammas = [np.pi**i for i in range(len(h))]
. The% 2
leads to more uniform gammas, which helps optimization, apparently. This makes sense because we care about numerical stability here and with the previousgammas
, some directions had entirely different scale than others. The shift by1
in thei
might be unnecessary.- Switch from Adam to L-BFGS. This is more expensive, but seems to optimize significantly better.
- Optimize for 2k epochs rather than 500. Together with the optimizer change the optimization then takes 60s instead of 8s.
- Switch
h_0_m = Kc_m @ H_m @ Kc_m.conj().T
toh_0_m = Kc_m.conj().T @ H_m @ Kc_m
(line 314). As we transform thev_m
inloss
byK_m @ v_m @ K_m.conj().T
, we need to do the opposite toH_m
when applying the optimized parameters. I'd suggest to transformH_m
inloss
as well, to be more consistent (I'm aware that this breaks with how the paper writes it down, but transition from paper to code might be nicer than within code?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know whether I should push these changes.
Us_kak = jax.vmap(Us_kak)(ts) | ||
Us_trotter50 = jax.vmap(lambda t: qml.matrix(qml.TrotterProduct(H, time=t, n=50, order=4), wire_order=range(n_wires)))(ts) | ||
Us_trotter500 = jax.vmap(lambda t: qml.matrix(qml.TrotterProduct(H, time=t, n=500, order=4), wire_order=range(n_wires)))(ts) | ||
|
||
res_kak = 1 - jnp.abs(jnp.einsum("bij,bji->b", Us_exact.conj(), Us_kak)) / 2**n_wires | ||
res_trotter50 = 1 - jnp.abs(jnp.einsum("bij,bji->b", Us_exact.conj(), Us_trotter50)) / 2**n_wires | ||
res_trotter500 = 1 - jnp.abs(jnp.einsum("bij,bji->b", Us_exact.conj(), Us_trotter500)) / 2**n_wires | ||
|
||
plt.plot(ts, res_kak, label="KAK") | ||
plt.plot(ts, res_trotter50, "x--", label="50 Trotter steps") | ||
plt.plot(ts, res_trotter500, ".-", label="500 Trotter steps") | ||
plt.ylabel("empirical error") | ||
plt.xlabel("t") | ||
# plt.yscale("log") | ||
plt.legend() | ||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems wild to me that both 50 and 500 steps seem to do equally bad 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to do time=-t
in TrotterProduct
because it implements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out 50 steps is waaay to precise already :D :)
Before submitting
Please complete the following checklist when submitting a PR:
Ensure that your tutorial executes correctly, and conforms to the
guidelines specified in the README.
Remember to do a grammar check of the content you include.
All tutorials conform to
PEP8 standards.
To auto format files, simply
pip install black
, and thenrun
black -l 100 path/to/file.py
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Title:
Summary:
Relevant references:
Possible Drawbacks:
Related GitHub Issues:
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
KEYWORDS — What words should be included in the marketing post?
Which of the following types of documentation is most similar to your file?
(more details here)