def model_config_model_name_get(ModelName): # noqa: E501 """Obtain an example model configuration. Submit a model name and receive a model configuration for the given model. # noqa: E501 :param model_name: The name of a model. :type model_name: str :rtype: ModelConfig """ # get model try: api_instance = mint_client.ModelApi( mint_client.ApiClient(configuration)) model = api_instance.get_model(ModelName, username=username) versions = [v['id'] for v in model.has_software_version] # for each model version, obtain configuration ids configuration_ids = [] api_instance = mint_client.ModelversionApi( mint_client.ApiClient(configuration)) for v in versions: version = api_instance.get_model_version(v, username=username) c_ids = [c.id for c in version.has_configuration] configuration_ids.extend(c_ids) # get configurations configurations = [] api_instance = mint_client.ModelconfigurationApi( mint_client.ApiClient(configuration)) for _id in configuration_ids: config = api_instance.get_model_configuraton(_id, username=username) configurations.append({ 'name': ModelName, 'config': config.to_dict() }) return configurations except ApiException as e: return "Exception when calling MINT: %s\n" % e
def _find_model_by_dataset_id(dataset_id, MINTconfiguration, MINTuser): print(f"Searching for models associated with the dataset {dataset_id}") configuration = MINTconfiguration username = MINTuser # Step 1: Obtain all MINT Model configurations # from these configurations, extract the input/output dataset IDs # Step 1 output: a set of Configuration IDs associated with the dataset_id api_instance = mint_client.ModelconfigurationApi( mint_client.ApiClient(configuration)) try: # List modelconfiguration api_response = api_instance.get_model_configurations(username=username) dataset_configs = set() for config in api_response: for io in config.has_input: _id = io.id if _id == dataset_id: dataset_configs.add(config.id) for io in config.has_output: _id = io.id if _id == dataset_id: dataset_configs.add(config.id) print( f"Found {len(dataset_configs)} Model Configuration associated with {dataset_id}" ) except ApiException as e: print( "Exception when calling ModelconfigurationApi->get_model_configurations: %s\n" % e) # Step 2: Obtain all Model Versions and their associated Model Configuration IDs # Step 2 output: a set of Model Version IDs associated with the dataset_id api_instance = mint_client.ModelversionApi( mint_client.ApiClient(configuration)) try: # List All ModelVersions version_ids = set() api_response = api_instance.get_model_versions(username=username) for v in api_response: c_ = v.has_configuration for conf in c_: if conf.id in dataset_configs: # this is a config associated with the dataset_id # so add the version to version_ids version_ids.add(v.id) print( f"Found {len(version_ids)} Model Version associated with {dataset_id}" ) except ApiException as e: print( "Exception when calling ModelversionApi->get_model_versions: %s\n" % e) # Step 3: Obtain all Models and check if their versions match the Version IDs of interest # Step 3 output: api_instance = mint_client.ModelApi(mint_client.ApiClient(configuration)) try: # List All models api_response = api_instance.get_models(username=username) models = set() for m in api_response: for v in m.has_software_version: if v['id'] in version_ids: # this is a model associated with the dataset_id # obtain its name models.add(m.label) print(f"Found {len(models)} Models associated with {dataset_id}") except ApiException as e: print("Exception when calling ModelApi->get_models: %s\n" % e) try: models_output = [] for m in list(models): m_ = _get_model(m, configuration, username) models_output.append(m_) return models_output except Exception as e: print(f"Exception when processing model info: {e}")
def model_io_post(): # noqa: E501 """Obtain information on a given model's inputs or outputs. Submit a model name and receive information about the input or output files required by this model. # noqa: E501 Note that this includes all inputs and all outputs for a given model, irrespective of the configuration. In the future this could be subset to just a specific configuration. :param io_request: The name of a model and an IO type. :type io_request: dict | bytes :rtype: List[IOFile] """ if connexion.request.is_json: io_request = IORequest.from_dict( connexion.request.get_json()) # noqa: E501 name_ = io_request.name type_ = io_request.iotype try: # get model configuration ids api_instance = mint_client.ModelApi( mint_client.ApiClient(configuration)) model = api_instance.get_model(name_, username=username) versions = [v['id'] for v in model.has_software_version] # for each model version, obtain configuration ids configuration_ids = [] api_instance = mint_client.ModelversionApi( mint_client.ApiClient(configuration)) for v in versions: version = api_instance.get_model_version(v, username=username) c_ids = [c.id for c in version.has_configuration] configuration_ids.extend(c_ids) # get IO api_instance = mint_client.ModelconfigurationApi( mint_client.ApiClient(configuration)) inputs_outputs = [] if type_ == 'input': for config_id in configuration_ids: response = requests.get( f"https://api.models.mint.isi.edu/v0.0.2/modelconfiguration/{config_id}/inputs?username=modelservice" ) api_response = response.json() for io in api_response: io_ = util._parse_io(io, url, request_headers) if io_: inputs_outputs.append(io_) elif type_ == 'output': outputs = [] for config_id in configuration_ids: response = requests.get( f"https://api.models.mint.isi.edu/v0.0.2/modelconfiguration/{config_id}/outputs?username=modelservice" ) api_response = response.json() for io in api_response: io_ = util._parse_io(io, url, request_headers) if io_: inputs_outputs.append(io_) return inputs_outputs except ApiException as e: return "Exception when calling MINT API: %s\n" % e
{ "id": "sscyp_temperature_image_directory" }, { "id": "sscyp_output_histogram_directory" } ], "hasOutput": [ { "id": "sscyp_historgram_output" } ], "id": "sscyp_generate_histogram", "label": "Generate histograms for SSCYP" } api_instance = mint_client.ModelconfigurationApi( mint_client.ApiClient(configuration)) # Create a model configuration if it's not already exist try: api_instance.create_model_configuration(model_configuration) except ApiException as e: print("Exception: %s\n" % e) model_config_id = "sscyp_generate_histogram" try: # Get modelconfiguration api_response = api_instance.get_model_configuraton( model_config_id, username=username) pprint(api_response) except ApiException as e: print("Exception when calling ModelconfigurationApi->get_model_configuraton: %s\n" % e)