def create(cls, experiment_name, trial_name=None, sagemaker_boto_client=None, trial_components=None, tags=None): """Create a new trial and return a ``Trial`` object. Args: experiment_name: (str): Name of the experiment to create this trial in. trial_name: (str, optional): Name of the Trial. If not specified, an auto-generated name will be used. sagemaker_boto_client (SageMaker.Client, optional): Boto3 client for SageMaker. If not supplied, a default boto3 client will be created and used. trial_components (list): A list of trial component names, trial components, or trial component trackers. tags (List[dict[str, str]]): A list of tags to associate with the trial. Returns: smexperiments.trial.Trial: A SageMaker ``Trial`` object """ trial_name = trial_name or _utils.name("Trial") trial = super(Trial, cls)._construct( cls._boto_create_method, trial_name=trial_name, experiment_name=experiment_name, tags=tags, sagemaker_boto_client=sagemaker_boto_client, ) if trial_components: for tc in trial_components: trial.add_trial_component(tc) return trial
def create_trial(self, trial_name=None, trial_name_prefix="SageMakerTrial"): """Create a trial in this experiment. Since trial names are expected to be unique in an account, ``trial_name_prefix`` can be provided instead of ``trial_name``. In this case a unique name will be generated that begins with the specified prefix. Args: trial_name (str): Name of the trial. trial_name_prefix (str): Prefix for the trial name if you want SageMaker to auto-generate the trial name. Returns: sagemaker.experiments.trial.Trial : A SageMaker ``Trial`` object representing the created trial. """ if not trial_name: trial_name = _utils.name(trial_name_prefix) return trial.Trial.create( trial_name=trial_name, experiment_name=self.experiment_name, sagemaker_boto_client=self.sagemaker_boto_client, )
def test_create_default_bucket(boto3_session): bucket_name_prefix=_utils.name('sm-test') bucket = _utils.get_or_create_default_bucket(boto3_session, default_bucket_prefix=bucket_name_prefix) s3_client = boto3_session.client('s3') try: s3_client.head_bucket(Bucket=bucket) finally: s3_client.delete_bucket(Bucket=bucket)
def create( cls, display_name=None, artifact_bucket=None, artifact_prefix=None, boto3_session=None, sagemaker_boto_client=None, ): """Create a new ``Tracker`` by creating a new trial component. Examples .. code-block:: python from smexperiments import tracker my_tracker = tracker.Tracker.create() Args: display_name: (str, optional). The display name of the trial component to track. artifact_bucket: (str, optional) The name of the S3 bucket to store artifacts to. artifact_prefix: (str, optional) The prefix to write artifacts to within ``artifact_bucket`` boto3_session: (boto3.Session, optional) The boto3.Session to use to interact with AWS services. If not specified a new default boto3 session will be created. sagemaker_boto_client: (boto3.Client, optional) The SageMaker AWS service client to use. If not specified a new client will be created from the specified ``boto3_session`` or default boto3.Session. Returns: Tracker: The tracker for the new trial component. """ boto3_session = boto3_session or _utils.boto_session() sagemaker_boto_client = sagemaker_boto_client or _utils.sagemaker_client( ) tc = trial_component.TrialComponent.create( trial_component_name=_utils.name("TrialComponent"), display_name=display_name, sagemaker_boto_client=sagemaker_boto_client, ) metrics_writer = metrics.SageMakerFileMetricsWriter() return cls( tc, metrics_writer, _ArtifactUploader(tc.trial_component_name, artifact_bucket, artifact_prefix, boto3_session), )
def _resolve_artifact_name(file_path): _, filename = os.path.split(file_path) if filename: return filename else: return _utils.name("artifact")