Skip to content

Commit 000d787

Browse files
committed
additional detail in documentation
1 parent 236160a commit 000d787

File tree

12 files changed

+308
-56
lines changed

12 files changed

+308
-56
lines changed

docs/index.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
Amazon SageMaker Experiments Python SDK
22
=======================================
33

4+
Amazon SageMaker Experiments Python SDK is an open source library for tracking machine learning experiments.
5+
6+
With the SDK you can track and organize your machine learning workflow across SageMaker with jobs such as Processing, Training, and Transform.
7+
8+
Here you'll find an overview and API documentation. The project homepage is on GitHub: https://github.com/aws/sagemaker-experiments, where you can find the SDK source and installation instructions for the library.
9+
410
.. toctree::
511
:maxdepth: 1
612

713
tracker
814
experiment
915
trial
1016
trial_component
11-
metrics
17+
metrics
18+
links

docs/links.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Links
2+
-----
3+
4+
* `Manage Machine Learning with Amazon SageMaker Experiments <https://docs.aws.amazon.com/sagemaker/latest/dg/experiments.html>`_
5+
* `Track and Evaluate a Model Training Experiment <https://docs.aws.amazon.com/sagemaker/latest/dg/experiments-mnist.html>`_
6+
* `SageMaker Experiments example notebooks <https://github.com/awslabs/amazon-sagemaker-examples/tree/master/sagemaker-experiments>`_

src/smexperiments/_base_types.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717

1818
class ApiObject(object):
19-
"""A Python class representation of a boto API object. Converts boto dicts of 'UpperCamelCase' names
19+
"""
20+
A Python class representation of a boto API object. Converts boto dicts of 'UpperCamelCase' names
2021
to dicts into/from a Python object with standard python members. Clients invoke to_boto on an instance
2122
of ApiObject to transform the ApiObject into a boto representation. Clients invoke from_boto on a sub-class of
22-
ApiObject to instantiate an instance of that class from a boto representation."""
23+
ApiObject to instantiate an instance of that class from a boto representation.
24+
"""
2325

2426
# A map from boto 'UpperCamelCase' name to member name. If a boto name does not appear in this dict then
2527
# it is converted to lower_snake_case.
@@ -37,7 +39,12 @@ def _boto_ignore(cls):
3739

3840
@classmethod
3941
def from_boto(cls, boto_dict, **kwargs):
40-
"""Construct an instance of this ApiObject from a boto response."""
42+
"""Construct an instance of this ApiObject from a boto response.
43+
44+
Args:
45+
boto_dict (dict): A dictionary of a boto response.
46+
**kwargs: Arbitrary keyword arguments
47+
"""
4148
boto_dict = {k: v for k, v in boto_dict.items() if k not in cls._boto_ignore()}
4249
custom_boto_names_to_member_names = {a: b for b, a in cls._custom_boto_names.items()}
4350
cls_kwargs = _boto_functions.from_boto(boto_dict, custom_boto_names_to_member_names, cls._custom_boto_types)
@@ -46,7 +53,11 @@ def from_boto(cls, boto_dict, **kwargs):
4653

4754
@classmethod
4855
def to_boto(cls, obj):
49-
"""Convert an object to a boto representation."""
56+
"""Convert an object to a boto representation.
57+
58+
Args:
59+
obj (dict): The object to convert to boto.
60+
"""
5061
if not isinstance(obj, dict):
5162
var_dict = vars(obj)
5263
else:
@@ -127,7 +138,11 @@ def _construct(cls, boto_method_name, sagemaker_boto_client=None, **kwargs):
127138
return instance._invoke_api(boto_method_name, kwargs)
128139

129140
def with_boto(self, boto_dict):
130-
"""Update this ApiObject with a boto response."""
141+
"""Update this ApiObject with a boto response.
142+
143+
Args:
144+
boto_dict (dict): A dictionary of a boto response.
145+
"""
131146
custom_boto_names_to_member_names = {a: b for b, a in self._custom_boto_names.items()}
132147
self.__dict__.update(
133148
**_boto_functions.from_boto(boto_dict, custom_boto_names_to_member_names, self._custom_boto_types)

src/smexperiments/_boto_functions.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,45 @@
1515

1616

1717
def to_camel_case(snake_case):
18-
"""Convert a snake case string to camel case"""
18+
"""Convert a snake case string to camel case.
19+
20+
Args:
21+
snake_case (str): String to convert to camel case.
22+
23+
Returns:
24+
str: String converted to camel case.
25+
"""
1926
return "".join([x.title() for x in snake_case.split("_")])
2027

2128

2229
def to_snake_case(name):
23-
"""Convert a camel case string to snake case"""
30+
"""Convert a camel case string to snake case
31+
32+
Args:
33+
name (str): String to convert to snake case.
34+
35+
Returns:
36+
str: String converted to snake case.
37+
"""
2438
# https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
2539
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
2640
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
2741

2842

2943
def from_boto(boto_dict, boto_name_to_member_name, member_name_to_type):
30-
"""Convert an UpperCamelCase boto response to a snake case representation.
44+
"""
45+
Convert an UpperCamelCase boto response to a snake case representation.
3146
32-
Args:
33-
boto_dict dict[str, ?]: A boto response dictionary.
34-
boto_name_to_member_name dict[str, str]: A map from boto name to snake_case name. If a given boto name is
35-
not in the map then a default mapping is applied.
36-
member_name_to_type dict[str, (_base_types.ApiObject, boolean)]: A map from snake case name to a type
37-
description tuple. The first element of the tuple, a sublcass of ApiObject, is the type of the mapped
38-
object. The second element indicates whether the mapped element is a collection or singleton.
47+
Args:
48+
boto_dict (dict[str, ?]): A boto response dictionary.
49+
boto_name_to_member_name (dict[str, str]): A map from boto name to snake_case name. If a given boto name is
50+
not in the map then a default mapping is applied.
51+
member_name_to_type (dict[str, (_base_types.ApiObject, boolean)]): A map from snake case name to a type
52+
description tuple. The first element of the tuple, a subclass of ApiObject, is the type of the mapped
53+
object. The second element indicates whether the mapped element is a collection or singleton.
54+
55+
Returns:
56+
dict: Boto response in snake case.
3957
"""
4058
from_boto_values = {}
4159
for boto_name, boto_value in boto_dict.items():
@@ -68,6 +86,10 @@ def to_boto(member_vars, member_name_to_boto_name, member_name_to_type):
6886
Args:
6987
member_vars dict[str, ?]: A map from snake case name to value.
7088
member_name_to_boto_name dict[str, ?]: A map from snake_case name to boto name.
89+
90+
Returns:
91+
dict: boto dict converted to snake case
92+
7193
"""
7294
to_boto_values = {}
7395
# Strip out all entries in member_vars that have a None value. None values are treated as not having a value

src/smexperiments/_environment.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@
1010

1111

1212
class EnvironmentType(enum.Enum):
13+
"""
14+
SageMaker jobs which data can be pulled from the environment.
15+
"""
16+
1317
SageMakerTrainingJob = 1
1418
SageMakerProcessingJob = 2
1519

1620

1721
class TrialComponentEnvironment(object):
22+
"""Retrieves job specific data from the environment.
23+
24+
Attributes:
25+
environment_type (EnvironmentType): The environment type.
26+
source_arn (str): The arn of the current job.
27+
"""
1828

1929
environment_type = None
2030
source_arn = None
@@ -25,6 +35,15 @@ def __init__(self, environment_type, source_arn):
2535

2636
@classmethod
2737
def load(cls, training_job_arn_env=TRAINING_JOB_ARN_ENV, processing_job_config_path=PROCESSING_JOB_CONFIG_PATH):
38+
"""Loads source arn of current job from environment.
39+
40+
Args:
41+
training_job_arn_env (str): The environment key for training job arn.
42+
processing_job_config_path (str): The processing job config path.
43+
44+
Returns:
45+
TrialComponentEnvironment: Job data loaded from the environment. None if config does not exist.
46+
"""
2847
if training_job_arn_env in os.environ:
2948
environment_type = EnvironmentType.SageMakerTrainingJob
3049
source_arn = os.environ.get(training_job_arn_env)
@@ -37,6 +56,14 @@ def load(cls, training_job_arn_env=TRAINING_JOB_ARN_ENV, processing_job_config_p
3756
return None
3857

3958
def get_trial_component(self, sagemaker_boto_client):
59+
"""Retrieves the trial component from the job in the environment.
60+
61+
Args:
62+
sagemaker_boto_client (SageMaker.Client): SageMaker boto client.
63+
64+
Returns:
65+
TrialComponent: The trial component created from the job. None if not found.
66+
"""
4067
start = time.time()
4168
while time.time() - start < 300:
4269
summaries = list(

src/smexperiments/_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,23 @@
2020

2121

2222
def sagemaker_client():
23+
"""Instantiates a SageMaker client.
24+
25+
Returns:
26+
SageMaker.Client
27+
"""
2328
if os.environ.get("SAGEMAKER_ENDPOINT", "").strip():
2429
return boto_session().client("sagemaker", endpoint_url=os.environ.get("SAGEMAKER_ENDPOINT"))
2530
else:
2631
return boto_session().client("sagemaker")
2732

2833

2934
def boto_session():
35+
"""Instantiates a boto Session.
36+
37+
Returns:
38+
boto3.Session
39+
"""
3040
return boto3.Session(region_name=os.environ.get("AWS_REGION"))
3141

3242

@@ -42,6 +52,16 @@ def name(prefix):
4252

4353

4454
def get_or_create_default_bucket(boto_session, default_bucket_prefix="sagemaker"):
55+
"""Creates a default bucket if not already exists. The bucket name is a combination of a prefix, the region, and
56+
account.
57+
58+
Args:
59+
boto_session (boto3.Session): boto session
60+
default_bucket_prefix (str): prefix to the bucket name
61+
62+
Returns:
63+
str: The default bucket name.
64+
"""
4565
account = boto_session.client("sts").get_caller_identity()["Account"]
4666
region = boto_session.region_name
4767
default_bucket = "{}-{}-{}".format(default_bucket_prefix, region, account)

0 commit comments

Comments
 (0)