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

Bugfix: Interactive calculation array comparison #1542

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions pyiron_base/jobs/job/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,21 @@ def interactive_flush(self, path="interactive", include_last_step=False):
step=self.interactive_write_frequency,
include_last=include_last_step,
)
if (
len(data) > 0
and isinstance(data[0], list)
and len(np.shape(data)) == 1
):
self._extend_hdf(h5=h5, path=path, key=key, data=data)
elif np.array(data).dtype == np.dtype("O"):
self._extend_hdf(h5=h5, path=path, key=key, data=data)
else:
self._extend_hdf(h5=h5, path=path, key=key, data=np.array(data))
try:
if (
len(data) > 0
and isinstance(data[0], list)
and len(np.shape(data)) == 1
):
self._extend_hdf(h5=h5, path=path, key=key, data=data)
elif np.array(data).dtype == np.dtype("O"):
self._extend_hdf(h5=h5, path=path, key=key, data=data)
else:
self._extend_hdf(h5=h5, path=path, key=key, data=np.array(data))
Copy link
Member

Choose a reason for hiding this comment

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

All these calls to the same function are very similar. Actually, why can the stuff from the except clause not be done here? If not a dtype=O, then construct such an array instead of a regular one?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the recent numpy version np.array(data) fails, unless np.array(data, dtype="object") is set.

Copy link
Contributor

Choose a reason for hiding this comment

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

This probably means that this clause elif np.array(data).dtype == np.dtype("O") is never trigger, because it raises an exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but I am not sure. The clean way would require the user to specify if the number of atoms is going to change in their simulation or not and then choose the corresponding approach for storing the structures. So this is really just a quick fix to use interactive jobs to evaluate machine learned interatomic potentials to calculate the energies and forces for the test and training set.

except ValueError:
self._extend_hdf(
h5=h5, path=path, key=key, data=np.array(data, dtype="object")
)
self.interactive_cache[key] = []

def interactive_open(self):
Expand Down
Loading