def _writeable_value(self, tag_value): if tag_value is None: return "" elif is_string_type(tag_value): return tag_value else: return "%s" % tag_value
def search_runs(self, experiment_ids, filter_string="", run_view_type=ViewType.ACTIVE_ONLY, max_results=SEARCH_MAX_RESULTS_DEFAULT, order_by=None, page_token=None): """ Search experiments that fit the search criteria. :param experiment_ids: List of experiment IDs, or a single int or string id. :param filter_string: Filter query string, defaults to searching all runs. :param run_view_type: one of enum values ACTIVE_ONLY, DELETED_ONLY, or ALL runs defined in :py:class:`mlflow.entities.ViewType`. :param max_results: Maximum number of runs desired. :param order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``. The default ordering is to sort by ``start_time DESC``, then ``run_id``. :param page_token: Token specifying the next page of results. It should be obtained from a ``search_runs`` call. :return: A list of :py:class:`mlflow.entities.Run` objects that satisfy the search expressions. If the underlying tracking store supports pagination, the token for the next page may be obtained via the ``token`` attribute of the returned object. """ if isinstance(experiment_ids, int) or is_string_type(experiment_ids): experiment_ids = [experiment_ids] return self.store.search_runs(experiment_ids=experiment_ids, filter_string=filter_string, run_view_type=run_view_type, max_results=max_results, order_by=order_by, page_token=page_token)
def __init__(self, name, yaml_obj): self.name = name if is_string_type(yaml_obj): self.type = yaml_obj self.default = None else: self.type = yaml_obj.get("type", "string") self.default = yaml_obj.get("default")
def _validate_experiment_name(experiment_name): """Check that `experiment_name` is a valid string and raise an exception if it isn't.""" if experiment_name == "" or experiment_name is None: raise MlflowException("Invalid experiment name: '%s'" % experiment_name, error_code=INVALID_PARAMETER_VALUE) if not is_string_type(experiment_name): raise MlflowException( "Invalid experiment name: %s. Expects a string." % experiment_name, error_code=INVALID_PARAMETER_VALUE)
def get_entry_point(self, entry_point): if entry_point in self._entry_points: return self._entry_points[entry_point] _, file_extension = os.path.splitext(entry_point) ext_to_cmd = {".py": "python", ".sh": os.environ.get("SHELL", "bash")} if file_extension in ext_to_cmd: command = "%s %s" % (ext_to_cmd[file_extension], shlex_quote(entry_point)) if not is_string_type(command): command = command.encode("utf-8") return EntryPoint(name=entry_point, parameters={}, command=command) elif file_extension == ".R": command = "Rscript -e \"mlflow::mlflow_source('%s')\" --args" % shlex_quote( entry_point) return EntryPoint(name=entry_point, parameters={}, command=command) raise ExecutionException( "Could not find {0} among entry points {1} or interpret {0} as a " "runnable script. Supported script file extensions: " "{2}".format(entry_point, list(self._entry_points.keys()), list(ext_to_cmd.keys())))
def _get_request_message(request_message, flask_request=request): if flask_request.method == 'GET' and len(flask_request.query_string) > 0: # This is a hack to make arrays of length 1 work with the parser. # for example experiment_ids%5B%5D=0 should be parsed to {experiment_ids: [0]} # but it gets parsed to {experiment_ids: 0} # but it doesn't. However, experiment_ids%5B0%5D=0 will get parsed to the right # result. query_string = re.sub('%5B%5D', '%5B0%5D', flask_request.query_string.decode("utf-8")) request_dict = parser.parse(query_string, normalized=True) # Convert atomic values of repeated fields to lists before calling protobuf deserialization. # Context: We parse the parameter string into a dictionary outside of protobuf since # protobuf does not know how to read the query parameters directly. The query parser above # has no type information and hence any parameter that occurs exactly once is parsed as an # atomic value. Since protobuf requires that the values of repeated fields are lists, # deserialization will fail unless we do the fix below. for field in request_message.DESCRIPTOR.fields: if (field.label == descriptor.FieldDescriptor.LABEL_REPEATED and field.name in request_dict): if not isinstance(request_dict[field.name], list): request_dict[field.name] = [request_dict[field.name]] parse_dict(request_dict, request_message) return request_message request_json = _get_request_json(flask_request) # Older clients may post their JSON double-encoded as strings, so the get_json # above actually converts it to a string. Therefore, we check this condition # (which we can tell for sure because any proper request should be a dictionary), # and decode it a second time. if is_string_type(request_json): request_json = json.loads(request_json) # If request doesn't have json body then assume it's empty. if request_json is None: request_json = {} parse_dict(request_json, request_message) return request_message
def decorate(s): if is_string_type(s): return "'{}'".format(s) else: return "{}".format(s)