class_docstr: A collection of parameters, metrics, and artifacts to create a ML model.
class_docstr_tok: ["A","collection","of","parameters",",","metrics",",","and","artifacts","to","create","a","ML","model","."]
docstr: Construct a `Run` instance.
  
  SageMaker Experiments automatically tracks the inputs, parameters, configurations,
  and results of your iterations as runs.
  You can assign, group, and organize these runs into experiments.
  You can also create, compare, and evaluate runs.
  
  The code sample below shows how to initialize a run, log parameters to the Run object
  and invoke a training job under the context of this Run object, which automatically
  passes the run's ``experiment_config`` (including the experiment name, run name etc.)
  to the training job.
  
  Note:
      All log methods (e.g. ``log_parameter``, ``log_metric``, etc.) have to be called within
      the run context (i.e. the ``with`` statement). Otherwise, a ``RuntimeError`` is thrown.
  
  .. code:: python
  
      with Run(experiment_name="my-exp", run_name="my-run", ...) as run:
          run.log_parameter(...)
          ...
          estimator.fit(job_name="my-job")  # Create a training job
  
  In order to reuse an existing run to log extra data, ``load_run`` is recommended.
  For example, instead of the ``Run`` constructor, the ``load_run`` is recommended to use
  in a job script to load the existing run created before the job launch.
  Otherwise, a new run may be created each time you launch a job.
  
  The code snippet below displays how to load the run initialized above
  in a custom training job script, where no ``run_name`` or ``experiment_name``
  is presented as they are automatically retrieved from the experiment config
  in the job environment.
  
  .. code:: python
  
      with load_run(sagemaker_session=sagemaker_session) as run:
          run.log_metric(...)
          ...
  
  Args:
      experiment_name (str): The name of the experiment. The name must be unique
          within an account.
      run_name (str): The name of the run. If it is not specified, one is auto generated.
      experiment_display_name (str): Name of the experiment that will appear in UI,
          such as SageMaker Studio. (default: None). This display name is used in
          a create experiment call. If an experiment with the specified name already exists,
          this display name won't take effect.
      run_display_name (str): The display name of the run used in UI (default: None).
          This display name is used in a create run call. If a run with the
          specified name already exists, this display name won't take effect.
      tags (Optional[Tags]): Tags to be used for all create calls,
          e.g. to create an experiment, a run group, etc. (default: None).
      sagemaker_session (sagemaker.session.Session): Session object which
          manages interactions with Amazon SageMaker APIs and any other
          AWS services needed. If not specified, one is created using the
          default AWS configuration chain.
      artifact_bucket (str): The S3 bucket to upload the artifact to.
          If not specified, the default bucket defined in `sagemaker_session`
          will be used.
      artifact_prefix (str): The S3 key prefix used to generate the S3 path
          to upload the artifact to (default: "trial-component-artifacts").
docstr_tok: ["Construct","a","`","Run","`","instance",".","SageMaker","Experiments","automatically","tracks","the","inputs",",","parameters",",","configurations",",","and","results","of","your","iterations","as","runs",".","You","can","assign",",","group",",","and","organize","these","runs","into","experiments",".","You","can","also","create",",","compare",",","and","evaluate","runs",".","The","code","sample","below","shows","how","to","initialize","a","run",",","log","parameters","to","the","Run","object","and","invoke","a","training","job","under","the","context","of","this","Run","object",",","which","automatically","passes","the","run","'s","``","experiment_config","``","(","including","the","experiment","name",",","run","name","etc",".",")","to","the","training","job",".","Note",":","All","log","methods","(","e.g",".","``","log_parameter","``",",","``","log_metric","``",",","etc",".",")","have","to","be","called","within","the","run","context","(","i.e",".","the","``","with","``","statement",")",".","Otherwise",",","a","``","RuntimeError","``","is","thrown",".","..","code",":",":","python","with","Run","(","experiment_name=","''","my-exp","''",",","run_name=","''","my-run","''",",","...",")","as","run",":","run.log_parameter","(","...",")","...","estimator.fit","(","job_name=","''","my-job","''",")","#","Create","a","training","job","In","order","to","reuse","an","existing","run","to","log","extra","data",",","``","load_run","``","is","recommended",".","For","example",",","instead","of","the","``","Run","``","constructor",",","the","``","load_run","``","is","recommended","to","use","in","a","job","script","to","load","the","existing","run","created","before","the","job","launch",".","Otherwise",",","a","new","run","may","be","created","each","time","you","launch","a","job",".","The","code","snippet","below","displays","how","to","load","the","run","initialized","above","in","a","custom","training","job","script",",","where","no","``","run_name","``","or","``","experiment_name","``","is","presented","as","they","are","automatically","retrieved","from","the","experiment","config","in","the","job","environment",".","..","code",":",":","python","with","load_run","(","sagemaker_session=sagemaker_session",")","as","run",":","run.log_metric","(","...",")","...","Args",":","experiment_name","(","str",")",":","The","name","of","the","experiment",".","The","name","must","be","unique","within","an","account",".","run_name","(","str",")",":","The","name","of","the","run",".","If","it","is","not","specified",",","one","is","auto","generated",".","experiment_display_name","(","str",")",":","Name","of","the","experiment","that","will","appear","in","UI",",","such","as","SageMaker","Studio",".","(","default",":","None",")",".","This","display","name","is","used","in","a","create","experiment","call",".","If","an","experiment","with","the","specified","name","already","exists",",","this","display","name","wo","n't","take","effect",".","run_display_name","(","str",")",":","The","display","name","of","the","run","used","in","UI","(","default",":","None",")",".","This","display","name","is","used","in","a","create","run","call",".","If","a","run","with","the","specified","name","already","exists",",","this","display","name","wo","n't","take","effect",".","tags","(","Optional","[","Tags","]",")",":","Tags","to","be","used","for","all","create","calls",",","e.g",".","to","create","an","experiment",",","a","run","group",",","etc",".","(","default",":","None",")",".","sagemaker_session","(","sagemaker.session.Session",")",":","Session","object","which","manages","interactions","with","Amazon","SageMaker","APIs","and","any","other","AWS","services","needed",".","If","not","specified",",","one","is","created","using","the","default","AWS","configuration","chain",".","artifact_bucket","(","str",")",":","The","S3","bucket","to","upload","the","artifact","to",".","If","not","specified",",","the","default","bucket","defined","in","`","sagemaker_session","`","will","be","used",".","artifact_prefix","(","str",")",":","The","S3","key","prefix","used","to","generate","the","S3","path","to","upload","the","artifact","to","(","default",":","``","trial-component-artifacts","''",")","."]
code: def __init__(
      self,
      experiment_name: str,
      run_name: Optional[str] = None,
      experiment_display_name: Optional[str] = None,
      run_display_name: Optional[str] = None,
      tags: Optional[Tags] = None,
      sagemaker_session: Optional["Session"] = None,
      artifact_bucket: Optional[str] = None,
      artifact_prefix: Optional[str] = None,
  ):
      """Construct a `Run` instance.
  
      SageMaker Experiments automatically tracks the inputs, parameters, configurations,
      and results of your iterations as runs.
      You can assign, group, and organize these runs into experiments.
      You can also create, compare, and evaluate runs.
  
      The code sample below shows how to initialize a run, log parameters to the Run object
      and invoke a training job under the context of this Run object, which automatically
      passes the run's ``experiment_config`` (including the experiment name, run name etc.)
      to the training job.
  
      Note:
          All log methods (e.g. ``log_parameter``, ``log_metric``, etc.) have to be called within
          the run context (i.e. the ``with`` statement). Otherwise, a ``RuntimeError`` is thrown.
  
      .. code:: python
  
          with Run(experiment_name="my-exp", run_name="my-run", ...) as run:
              run.log_parameter(...)
              ...
              estimator.fit(job_name="my-job")  # Create a training job
  
      In order to reuse an existing run to log extra data, ``load_run`` is recommended.
      For example, instead of the ``Run`` constructor, the ``load_run`` is recommended to use
      in a job script to load the existing run created before the job launch.
      Otherwise, a new run may be created each time you launch a job.
  
      The code snippet below displays how to load the run initialized above
      in a custom training job script, where no ``run_name`` or ``experiment_name``
      is presented as they are automatically retrieved from the experiment config
      in the job environment.
  
      .. code:: python
  
          with load_run(sagemaker_session=sagemaker_session) as run:
              run.log_metric(...)
              ...
  
      Args:
          experiment_name (str): The name of the experiment. The name must be unique
              within an account.
          run_name (str): The name of the run. If it is not specified, one is auto generated.
          experiment_display_name (str): Name of the experiment that will appear in UI,
              such as SageMaker Studio. (default: None). This display name is used in
              a create experiment call. If an experiment with the specified name already exists,
              this display name won't take effect.
          run_display_name (str): The display name of the run used in UI (default: None).
              This display name is used in a create run call. If a run with the
              specified name already exists, this display name won't take effect.
          tags (Optional[Tags]): Tags to be used for all create calls,
              e.g. to create an experiment, a run group, etc. (default: None).
          sagemaker_session (sagemaker.session.Session): Session object which
              manages interactions with Amazon SageMaker APIs and any other
              AWS services needed. If not specified, one is created using the
              default AWS configuration chain.
          artifact_bucket (str): The S3 bucket to upload the artifact to.
              If not specified, the default bucket defined in `sagemaker_session`
              will be used.
          artifact_prefix (str): The S3 key prefix used to generate the S3 path
              to upload the artifact to (default: "trial-component-artifacts").
      """
      # TODO: we should revert the lower casting once backend fix reaches prod
      self.experiment_name = experiment_name.lower()
      sagemaker_session = sagemaker_session or _utils.default_session()
      self.run_name = run_name or unique_name_from_base(RUN_NAME_BASE)
  
      # avoid confusion due to mis-match in casing between run name and TC name
      self.run_name = self.run_name.lower()
  
      tags = format_tags(tags)
  
      trial_component_name = Run._generate_trial_component_name(
          run_name=self.run_name, experiment_name=self.experiment_name
      )
      self.run_group_name = Run._generate_trial_name(
          self.experiment_name
      )
  
      self._experiment = Experiment._load_or_create(
          experiment_name=self.experiment_name,
          display_name=experiment_display_name,
          tags=tags,
          sagemaker_session=sagemaker_session,
      )
  
      self._trial = _Trial._load_or_create(
          experiment_name=self.experiment_name,
          trial_name=self.run_group_name,
          tags=tags,
          sagemaker_session=sagemaker_session,
      )
  
      (
          self._trial_component,
          is_existed,
      ) = _TrialComponent._load_or_create(
          trial_component_name=trial_component_name,
          display_name=run_display_name,
          tags=Run._append_run_tc_label_to_tags(tags),
          sagemaker_session=sagemaker_session,
      )
      if is_existed:
          logger.info(
              "The run (%s) under experiment (%s) already exists. Loading it.",
              self.run_name,
              self.experiment_name,
          )
  
      if not _TrialComponent._trial_component_is_associated_to_trial(
          self._trial_component.trial_component_name,
          self._trial.trial_name,
          sagemaker_session,
      ):
          self._trial.add_trial_component(self._trial_component)
  
      self._artifact_uploader = _ArtifactUploader(
          trial_component_name=self._trial_component.trial_component_name,
          sagemaker_session=sagemaker_session,
          artifact_bucket=artifact_bucket,
          artifact_prefix=_DEFAULT_ARTIFACT_PREFIX
          if artifact_prefix is None
          else artifact_prefix,
      )
      self._lineage_artifact_tracker = _LineageArtifactTracker(
          trial_component_arn=self._trial_component.trial_component_arn,
          sagemaker_session=sagemaker_session,
      )
      self._metrics_manager = _MetricsManager(
          trial_component_name=self._trial_component.trial_component_name,
          sagemaker_session=sagemaker_session,
      )
      self._inside_init_context = False
      self._inside_load_context = False
      self._in_load = False
  
imports: from __future__ import absolute_import
  import datetime
  import logging
  from enum import Enum
  from math import isnan, isinf
  from numbers import Number
  from typing import Optional, List, Dict, TYPE_CHECKING, Union
  import dateutil
  from numpy import array
  from sagemaker.apiutils import _utils
  from sagemaker.experiments import _api_types
  from sagemaker.experiments._api_types import TrialComponentArtifact, _TrialComponentStatusType
  from sagemaker.experiments._helper import _ArtifactUploader, _LineageArtifactTracker, _DEFAULT_ARTIFACT_PREFIX
  from sagemaker.experiments._environment import _RunEnvironment
  from sagemaker.experiments._run_context import _RunContext
  from sagemaker.experiments.experiment import Experiment
  from sagemaker.experiments._metrics import _MetricsManager
  from sagemaker.experiments.trial import _Trial
  from sagemaker.experiments.trial_component import _TrialComponent
  from sagemaker.utils import get_module, unique_name_from_base, format_tags, Tags, TagsDict
  from sagemaker.experiments._utils import guess_media_type, resolve_artifact_name, verify_length_of_true_and_predicted, validate_invoked_inside_run_context, get_tc_and_exp_config_from_job_env, verify_load_input_names, is_run_trial_component
label_desc: Use image node_id 1 to create a new Run object from inherited base classes: object with example: obj = Run(experiment_name, run_name, experiment_display_name, run_display_name, tags, sagemaker_session, artifact_bucket, artifact_prefix)