Пример #1
0
    def test_serialization(self):
        """Test the serialization/deserialization of JobInfo classes."""
        from aiida.schedulers.datastructures import JobInfo, JobState
        from datetime import datetime

        dict_serialized_content = {
            'job_id': '12723',
            'title': 'some title',
            'queue_name': 'some_queue',
            'account': 'my_account'
        }

        to_serialize = {'job_state': (JobState.QUEUED, 'job_state'), 'submission_time': (datetime.now(), 'date')}

        job_info = JobInfo()
        for key, val in dict_serialized_content.items():
            setattr(job_info, key, val)

        for key, (val, field_type) in to_serialize.items():
            setattr(job_info, key, val)
            # Also append to the dictionary for easier comparison later
            dict_serialized_content[key] = JobInfo.serialize_field(value=val, field_type=field_type)

        self.assertEqual(job_info.get_dict(), dict_serialized_content)
        # Full loop via JSON, moving data from job_info to job_info2;
        # we check that the content is fully preserved
        job_info2 = JobInfo.load_from_serialized(job_info.serialize())
        self.assertEqual(job_info2.get_dict(), dict_serialized_content)

        # Check that fields are properly re-serialized with the correct type
        self.assertEqual(job_info2.job_state, to_serialize['job_state'][0])
        # Check that fields are properly re-serialized with the correct type
        self.assertEqual(job_info2.submission_time, to_serialize['submission_time'][0])
Пример #2
0
    def get_last_job_info(self):
        """Return the last information asked to the scheduler about the status of the job.

        :return: a `JobInfo` object (that closely resembles a dictionary) or None.
        """
        from aiida.schedulers.datastructures import JobInfo

        last_job_info_serialized = self.get_attribute(
            self.SCHEUDLER_LAST_JOB_INFO_KEY, None)

        if last_job_info_serialized is not None:
            job_info = JobInfo()
            job_info.load_from_serialized(last_job_info_serialized)
        else:
            job_info = None

        return job_info