-
Notifications
You must be signed in to change notification settings - Fork 2
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
sanity check all pickled non-interacting Hamiltonians in h0 directory #52
Conversation
JohanSchott
commented
Mar 25, 2024
- Move sanity checking code of pickled Hamiltonian to a unit-test
- Test all pickled Hamiltonians in h0 directory
- Add sanity checks
assert len(process) == 2 # two events in non-interacting Hamiltonian | ||
assert process[1][1] == "a" # First event is annihilation | ||
assert process[0][1] == "c" # Second event is creation | ||
for event in process[::-1]: |
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 check events in any particular order.
for event in process[::-1]: | |
for event in process: |
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 order does not matter in this for-loop. But when a process is used for real, i.e. applied on a product state, the order matters.
The order is chosen such that ((i, 'c'), (j, 'a'))
operating on the state 'c'
denoting creation and 'a'
annihilation). So the right-most "event" is first applied, and finally the left-most "event", just like the math expression.
Relevant documentation e.g. https://github.com/JohanSchott/impurityModel/blob/master/impurityModel/ed/finite.py#L1320
https://github.com/JohanSchott/impurityModel/blob/master/impurityModel/ed/finite.py#L1395
And in the same way is the Coulomb interaction process between two electrons:
((i, 'c'), (j, 'c'), (k, 'a'), (l, 'a'))
https://github.com/JohanSchott/impurityModel/blob/master/impurityModel/ed/finite.py#L1322
Because of this I think it might be good to consistently loop over events "from right to left" in this repo.
Co-authored-by: kalvdans <github@kalvdans.no-ip.org>
Co-authored-by: kalvdans <github@kalvdans.no-ip.org>
…and does not give any output or error message...
…s MPI processes in child processes, which is not ok.
Thanks for your review @kalvdans ! I struggled to understand why the unit-tests failed in this PR. MPI can't be run both in a parent process and a child process. I the last commits I solve this issue by ignoring
Small reproducer of the problem: But without |
It seems MPI is automatically initialized when you import So just refrain from importing
|
It would be good to test some MPI stuff but not sure how to do that. I guess one way to test MPI stuff is something like: def test_MPI_stuff_of_function_XXX():
tot = []
for ranks in [1,2,4,8]:
subproces.run(f"mpiexec -n {ranks} python a_script_that_calls_function_XXX_and_save_its_output.py output_{ranks}", shell=True)
tot.append(read_file(f"output_{ranks}"))
compare_data(tot) where |
Seems it is the same solution pytest-mpi have chosen, and have two decorators to mark up which test should be run in which invocation. |
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.
Small items left, LGTM!
x_ref = ref_file_handle[key][()] | ||
abs_diff = np.abs(x - x_ref) | ||
i = np.argmax(abs_diff) | ||
print("Max abs diff:", np.ravel(abs_diff)[i]) |
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.
assert_allclose
will already print the maximum absolute diff.
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.
true. I'll remove the print statement
Co-authored-by: kalvdans <github@kalvdans.no-ip.org>
Co-authored-by: kalvdans <github@kalvdans.no-ip.org>