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

PythonFunctionContainerJob and ExecutableContainerJob: Use to_dict() and from_dict() #1378

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

jan-janssen
Copy link
Member

Replace to_hdf() and from_hdf() with to_dict() and from_dict()

Comment on lines +101 to 110
def from_dict(self, job_dict):
super().from_dict(job_dict=job_dict)
if "write_input_function" in job_dict.keys():
self._write_input_funct = cloudpickle.loads(
self.project_hdf5["write_input_function"]
job_dict["write_input_function"]
)
if "write_input_function" in self.project_hdf5.list_nodes():
if "write_input_function" in job_dict.keys():
self._collect_output_funct = cloudpickle.loads(
self.project_hdf5["collect_output_function"]
job_dict["collect_output_function"]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly GenericJob.from_hdf calls hdf.read_dict_from_hdf with recursive=False, hence "write_input_function" would never be in job_dict. Same below for the python function container.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are two parts in the from_hdf() method on GenericJob:

    def from_hdf(self, hdf=None, group_name=None):
        """
        Restore the GenericJob from an HDF5 file

        Args:
            hdf (ProjectHDFio): HDF5 group object - optional
            group_name (str): HDF5 subgroup name - optional
        """
        self._set_hdf(hdf=hdf, group_name=group_name)
        job_dict = self._hdf5.read_dict_from_hdf()
        with self._hdf5.open("input") as hdf5_input:
            job_dict["input"] = hdf5_input.read_dict_from_hdf(recursive=True)
        self.from_dict(job_dict=job_dict)

The first read_dict_from_hdf() call reads the nodes at the root level of the job group in the HDF5 file and then the second read_dict_from_hdf(recursive=True) recursively reads the nodes in the group input.

@jan-janssen jan-janssen merged commit 64666ac into main Mar 26, 2024
25 checks passed
@jan-janssen jan-janssen deleted the flex_job_dict branch March 26, 2024 13:29
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.

None yet

2 participants