-
Notifications
You must be signed in to change notification settings - Fork 12
Qudit_interface #45
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
Qudit_interface #45
Conversation
refraction-ray
left a comment
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 general implementation now looks good to me, some minor changes required to minimize and clean up the qudit vqe example
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.
Some more fixes required to make the example script more clean, imagine using jax backend on GPU, you will not like the conversion to numpy happen during the computation as it requires CPU-GPU data transfer which is slow, so try to avoid such conversion unless it only happens at the very beginning stage
examples/vqe_qudit_example.py
Outdated
| """ | ||
| bk = tc.backend | ||
| # Keep differentiability by passing backend scalars into gates | ||
| plist = [params_b[i] for i in range(params_b.shape[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.
why not directly use params_b?
examples/vqe_qudit_example.py
Outdated
| ) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, float]: | ||
| N = np.diag(np.arange(d)) | ||
| Xsym = symmetrize_hermitian(tc.backend.numpy(tc.quditgates._x_matrix_func(d))) | ||
| Zsym = symmetrize_hermitian(tc.backend.numpy(tc.quditgates._z_matrix_func(d))) |
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.
no need to transform to numpy?
examples/vqe_qudit_example.py
Outdated
| return bk.real(E) | ||
|
|
||
|
|
||
| def energy_expectation_numpy( |
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 function can be exactly the same with the backend version?
examples/vqe_qudit_example.py
Outdated
| bk = tc.backend | ||
| if jit: | ||
| energy_bk = bk.jit(energy_bk) | ||
| grad_f = bk.grad(energy_bk) |
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.
interchange the order of jit and grad, should be jit(grad(f))
examples/vqe_qudit_example.py
Outdated
| x_b = bk.convert_to_tensor(x_np) # numpy -> backend tensor | ||
| g_b = grad_f(x_b) # backend gradient | ||
| g = to_np(g_b) # backend -> numpy | ||
| x_np = x_np - lr * g # SGD step in numpy |
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.
why sgd in numpy? just keep to the corresponding backend and avoid those conversions from and to numpy
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.
if the logic is complicated with random search, you can remove the random search and numpy backend
|
Hi, Shixin. I tried to make a ``new'' file here. This should be totally different and cleaner without any complicated conversion. |
|
nice work, LGTM! |
|
Some remaining work for a new PR:
|
|
@all-contributors please add @WeiguoMa for examples |
|
I've put up a pull request to add @WeiguoMa! 🎉 |
This PR makes following changes: