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

QCQMC Part 5: Add Trial Wavefunction #347

Merged
merged 21 commits into from
Jun 27, 2024
Merged

Conversation

fdmalone
Copy link
Collaborator

@fdmalone fdmalone commented Jun 11, 2024

Add trial wavefunction module.

This is very big and could be split up into several files. WDYT @mpharrigan

@fdmalone fdmalone force-pushed the qcqmc-5 branch 2 times, most recently from 7c82c04 to 06435f4 Compare June 20, 2024 15:18
@fdmalone fdmalone changed the title QCQMC-5 QCQMC-5: Trial Wavefunction Jun 20, 2024
@fdmalone fdmalone changed the title QCQMC-5: Trial Wavefunction QCQMC-5: Add Trial Wavefunction Jun 20, 2024
@fdmalone fdmalone changed the title QCQMC-5: Add Trial Wavefunction QCQMC Part 5: Add Trial Wavefunction Jun 20, 2024
@fdmalone
Copy link
Collaborator Author

@mpharrigan / @dstrain115 PTAL

recirq/qcqmc/conftest.py Show resolved Hide resolved
recirq/qcqmc/trial_wf.py Show resolved Hide resolved
recirq/qcqmc/trial_wf.py Outdated Show resolved Hide resolved
recirq/qcqmc/trial_wf.py Outdated Show resolved Hide resolved
recirq/qcqmc/trial_wf.py Outdated Show resolved Hide resolved
recirq/qcqmc/trial_wf.py Outdated Show resolved Hide resolved
n_optimization_restarts: int = 1,
do_print: bool = True,
use_fast_gradients: bool = False,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also a long and complicated function with no docstring or comments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Split it up and added a reference to the paper.

print("Two Body Rotation Parameters:")
print(two_body_params)

return one_body_params, two_body_params, one_body_basis_change_mat
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. I think this should be split up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Split everything into modules

recirq/qcqmc/trial_wf_test.py Outdated Show resolved Hide resolved
recirq/qcqmc/trial_wf_test.py Outdated Show resolved Hide resolved
@mpharrigan
Copy link
Collaborator

What were you thinking re: splitting it up?

  • Trial WF basic infrastructure (top of file) trial_wf.py
  • Functions for getting explicit instantiations (middle of file, e.g. 8 qubit whatever)
  • Functions for doing the parameter optimization

would be one way

@fdmalone
Copy link
Collaborator Author

Pretty much this yes:

  1. trial_wf (for defs etc + maybe move the optimization function into a factory method)
  2. mode / qubit mappings
  3. optimization

@fdmalone
Copy link
Collaborator Author

optimization might be split too if possible

@fdmalone fdmalone requested a review from dstrain115 June 25, 2024 00:30
@fdmalone
Copy link
Collaborator Author

fdmalone commented Jun 25, 2024

One thing the refactor revealed is a lack of unit tests for quite a few things...

@fdmalone fdmalone requested a review from mpharrigan June 25, 2024 19:33
Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Like you mentioned, it looks like there are a lot of missing tests. Maybe we could add them in a later PR. Otherwise, this seems like much better organization.

recirq/qcqmc/conftest.py Show resolved Hide resolved
assert trial_wf.ansatz_energy < -1.947


# TODO: Speed up this test and add a similar one with non-trivial heuristic layers.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use @pytest.mark.slow on the relevant tests?

Copy link
Collaborator Author

@fdmalone fdmalone Jun 26, 2024

Choose a reason for hiding this comment

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

@wjhuggins, do you remember where this is from? Running these tests only takes 7 seconds total which isn't necessarily slow, but I do see quite significant creep in the CI's duration (from 5m to 13! minutes) since these PRs started to go in. I'll follow up with a PR to make things faster.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah somehow these are exceptionally slow for actions, but only take a few seconds on my laptop. I'll investigate

recirq/qcqmc/optimize_wf_test.py Outdated Show resolved Hide resolved
@fdmalone
Copy link
Collaborator Author

@dstrain115 could we merge and I'll follow up to add some more unit tests and fix the CI slowness.

@dstrain115
Copy link
Collaborator

Yeah, that's fine with me.

@fdmalone
Copy link
Collaborator Author

(I can't merge this myself)

@fdmalone fdmalone merged commit 7198a5d into quantumlib:master Jun 27, 2024
5 checks passed
@fdmalone fdmalone deleted the qcqmc-5 branch June 27, 2024 20:56
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.

3 participants