def validate(): training_job_searched = [] search_filter = Filter(name="TrainingJobName", operator=Operator.EQUALS, value=training_job_name) search_expression = SearchExpression(filters=[search_filter]) for s in TrainingJob.search( search_expression=search_expression, max_results=10, sagemaker_boto_client=sagemaker_boto_client, ): training_job_searched.append(s) assert len(training_job_searched) == 1 assert training_job_searched[0].training_job_name == training_job_name assert training_job_searched[0].input_data_config[0][ "ChannelName"] == "train" assert training_job_searched[0].algorithm_specification == { "TrainingImage": docker_image, "TrainingInputMode": "File", } assert training_job_searched[0].resource_config == { "InstanceType": "ml.m5.large", "InstanceCount": 1, "VolumeSizeInGB": 10, } assert training_job_searched[0].stopping_condition == { "MaxRuntimeInSeconds": 900 } assert training_job_searched # sanity test
def test_nested_filters(): search_filter = Filter(name="learning_rate", operator=Operator.EQUALS, value="0.1") filters = [search_filter] nested_filters = NestedFilter(property_name="hyper_param", filters=filters) assert { "Filters": [{"Name": "learning_rate", "Operator": "Equals", "Value": "0.1"}], "NestedPropertyName": "hyper_param", } == nested_filters.to_boto()
def test_search(sagemaker_boto_client): trial_names_searched = [] search_filter = Filter(name="ExperimentName", operator=Operator.CONTAINS, value="smexperiments-integ-") search_expression = SearchExpression(filters=[search_filter]) for s in trial.Trial.search( search_expression=search_expression, max_results=10, sagemaker_boto_client=sagemaker_boto_client ): trial_names_searched.append(s.trial_name) assert len(trial_names_searched) > 0 assert trial_names_searched # sanity test
def test_nested_search(sagemaker_boto_client): experiment_names_searched = [] search_filter = Filter(name="ExperimentName", operator=Operator.CONTAINS, value="smexperiments-integ-") nested_filter = NestedFilter(property_name="ExperimentName", filters=[search_filter]) search_expression = SearchExpression(nested_filters=[nested_filter]) for s in Experiment.search( search_expression=search_expression, max_results=10, sagemaker_boto_client=sagemaker_boto_client ): experiment_names_searched.append(s.experiment_name) assert len(experiment_names_searched) > 0 assert experiment_names_searched # sanity test
def test_search_expression(): search_filter = Filter(name="learning_rate", operator=Operator.EQUALS, value="0.1") nested_filter = NestedFilter(property_name="hyper_param", filters=[search_filter]) search_expression = SearchExpression( filters=[search_filter], nested_filters=[nested_filter], sub_expressions=[], boolean_operator=BooleanOperator.AND, ) assert { "Filters": [{"Name": "learning_rate", "Operator": "Equals", "Value": "0.1"}], "NestedFilters": [ { "Filters": [{"Name": "learning_rate", "Operator": "Equals", "Value": "0.1"}], "NestedPropertyName": "hyper_param", } ], "SubExpressions": [], "Operator": "And", } == search_expression.to_boto()
def test_filters(): search_filter = Filter(name="learning_rate", operator=Operator.EQUALS, value="0.1") assert {"Name": "learning_rate", "Operator": "Equals", "Value": "0.1"} == search_filter.to_boto()
def test_partial_filters(): search_filter = Filter(name="learning_rate") assert {"Name": "learning_rate"} == search_filter.to_boto()