def _create_snapshot(self): reals = {} for real in self.get_active_reals(): reals[str(real.get_iens())] = Realization( active=True, status=state.REALIZATION_STATE_WAITING, ) for step in real.get_steps(): reals[str(real.get_iens())].steps[str(step.get_id())] = Step( status=state.STEP_STATE_UNKNOWN ) for job in step.get_jobs(): reals[str(real.get_iens())].steps[str(step.get_id())].jobs[ str(job.get_id()) ] = Job( status=state.JOB_STATE_START, data={}, name=job.get_name(), ) top = SnapshotDict( reals=reals, status=state.ENSEMBLE_STATE_UNKNOWN, metadata=self.get_metadata(), ) return Snapshot(top.dict())
def full_snapshot() -> Snapshot: real = Realization( status=REALIZATION_STATE_UNKNOWN, active=True, steps={ "0": Step( status="", jobs={ "0": Job( start_time=dt.now(), end_time=dt.now(), name="poly_eval", status=JOB_STATE_START, error="error", stdout="std_out_file", stderr="std_err_file", data={ CURRENT_MEMORY_USAGE: "123", MAX_MEMORY_USAGE: "312", }, ), "1": Job( start_time=dt.now(), end_time=dt.now(), name="poly_postval", status=JOB_STATE_START, error="error", stdout="std_out_file", stderr="std_err_file", data={ CURRENT_MEMORY_USAGE: "123", MAX_MEMORY_USAGE: "312", }, ), }, ) }, ) snapshot = SnapshotDict( status=ENSEMBLE_STATE_STARTED, reals={}, ) for i in range(0, 100): snapshot.reals[str(i)] = copy.deepcopy(real) return Snapshot(snapshot.dict())
pytest.param( [ CloudEvent( {"source": "/", "type": ids.EVTYPE_EE_SNAPSHOT}, data={ **(build_snapshot(["0", "1"]).to_dict()), "iter": 0, }, ), CloudEvent( {"source": "/", "type": ids.EVTYPE_EE_SNAPSHOT_UPDATE}, data={ **( build_partial(["0", "1"]) .update_step( "0", "0", Step(status=state.STEP_STATE_SUCCESS) ) .to_dict() ), "iter": 0, }, ), ], [("_phase_count", 1)], 0.5, id="ensemble_experiment_50", ), pytest.param( [ CloudEvent( {"source": "/", "type": ids.EVTYPE_EE_SNAPSHOT},
def _create_snapshot_dict( self, run_context: ErtRunContext, detailed_progress: typing.Tuple[typing.Dict, int], iter_: int, ) -> typing.Optional[SnapshotDict]: """create a snapshot of a run_context and detailed_progress. detailed_progress is expected to be a tuple of a realization_progress dict and iteration number. iter_ represents the current assimilation cycle.""" self._set_iter_queue(iter_, self._model._job_queue) snapshot = SnapshotDict( status=ENSEMBLE_STATE_STARTED, reals={}, metadata={"iter": iter_}, ) forward_model = self._model.get_forward_model() iter_to_progress, progress_iter = detailed_progress if progress_iter != iter_: logger.debug( f"run_context iter ({iter_}) and detailed_progress ({progress_iter} iter differed" ) if iter_ in self._iter_queue and self._iter_queue[iter_] is not None: queue_snapshot = self._iter_queue[iter_].snapshot() else: queue_snapshot = None enumerated = 0 for iens, run_arg in _enumerate_run_context(run_context): real_id = str(iens) enumerated += 1 if not _is_iens_active(iens, run_context): continue status = JobStatusType.JOB_QUEUE_UNKNOWN if queue_snapshot is not None and iens in queue_snapshot: status = JobStatusType.from_string(queue_snapshot[iens]) snapshot.reals[real_id] = Realization( status=queue_status_to_real_state(status), active=True, steps={}) step = Step(status="", jobs={}) snapshot.reals[real_id].steps["0"] = step for index in range(0, len(forward_model)): ext_job = forward_model.iget_job(index) step.jobs[str(index)] = Job(name=ext_job.name(), status=JOB_STATE_START, data={}) progress = iter_to_progress[iter_].get(iens, None) if not progress: continue jobs = progress[0] for idx, fm in enumerate(jobs): job = step.jobs[str(idx)] job.start_time = fm.start_time job.end_time = fm.end_time job.name = fm.name job.status = _map_job_state(fm.status) job.error = fm.error job.stdout = fm.std_out_file job.stderr = fm.std_err_file job.data = { CURRENT_MEMORY_USAGE: fm.current_memory_usage, MAX_MEMORY_USAGE: fm.max_memory_usage, } if enumerated == 0: logger.debug("enumerated 0 items from run_context, it is gone") return None return snapshot
"source": "/", "type": ids.EVTYPE_EE_SNAPSHOT }, data={ **(build_snapshot(["0", "1"]).to_dict()), "iter": 0, }, ), CloudEvent( { "source": "/", "type": ids.EVTYPE_EE_SNAPSHOT_UPDATE }, data={ **(build_partial(["0", "1"]).update_step( "0", "0", Step(status=state.STEP_STATE_SUCCESS)).to_dict( )), "iter": 0, }, ), ], [("_phase_count", 1)], 0.5, id="ensemble_experiment_50", ), pytest.param( [ CloudEvent( { "source": "/",