def _maybe_set_run_terminated(active_run, status): """ If the passed-in active run is defined and still running (i.e. hasn't already been terminated within user code), mark it as terminated with the passed-in status. """ if active_run and not RunStatus.is_terminated(active_run.get_run().info.status): active_run.set_terminated(status)
def _validate_autologging_run(autologging_integration, run_id): """ For testing purposes, verifies that an MLflow run produced by an `autologging_integration` satisfies the following properties: - The run has an autologging tag whose value is the name of the autologging integration - The run has a terminal status (e.g., KILLED, FAILED, FINISHED) """ client = MlflowClient() run = client.get_run(run_id) autologging_tag_value = run.data.tags.get(MLFLOW_AUTOLOGGING) assert autologging_tag_value == autologging_integration, ( "Autologging run with id {} failed to set autologging tag with expected value. Expected: " "'{}', Actual: '{}'".format(run_id, autologging_integration, autologging_tag_value) ) assert RunStatus.is_terminated( RunStatus.from_string(run.info.status) ), "Autologging run with id {} has a non-terminal status '{}'".format(run_id, run.info.status)