From 9fbdcca0b3e8cda11f8fe167e5252001b77d5cf6 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Wed, 31 Aug 2022 13:06:48 +0200 Subject: [PATCH 01/13] Experimenting --- ansys/rep/client/jms/api/project_api.py | 26 +++- generate_resources.py | 183 ++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 generate_resources.py diff --git a/ansys/rep/client/jms/api/project_api.py b/ansys/rep/client/jms/api/project_api.py index 1cfdbf439..75fb7aa21 100644 --- a/ansys/rep/client/jms/api/project_api.py +++ b/ansys/rep/client/jms/api/project_api.py @@ -1,5 +1,6 @@ import logging import os +import json from pathlib import Path from typing import Callable, List @@ -8,7 +9,7 @@ from ..resource.algorithm import Algorithm from ..resource.base import Object from ..resource.file import File -from ..resource.job import Job, copy_jobs, sync_jobs +from ..resource.job import Job, JobSchema from ..resource.job_definition import JobDefinition from ..resource.license_context import LicenseContext from ..resource.parameter_definition import ParameterDefinition @@ -489,3 +490,26 @@ def archive_project(project_api: ProjectApi, target_path, include_job_files=True log.info(f"Done saving project archive to disk") return file_path + +def copy_jobs(project_api: ProjectApi, jobs: List[Job], as_objects=True, **query_params): + """Create new jobs by copying existing ones""" + + url = f"{project_api.url}/jobs" + + query_params.setdefault("fields", "all") + + json_data = json.dumps({"source_ids": [obj.id for obj in jobs]}) + r = project_api.client.session.post(f"{url}", data=json_data, params=query_params) + + data = r.json()["jobs"] + if not as_objects: + return data + + return JobSchema(many=True).load(data) + + +def sync_jobs(project_api: ProjectApi, jobs: List[Job]): + + url = f"{project_api.url}/jobs:sync" + json_data = json.dumps({"job_ids": [obj.id for obj in jobs]}) + r = project_api.client.session.put(f"{url}", data=json_data) \ No newline at end of file diff --git a/generate_resources.py b/generate_resources.py new file mode 100644 index 000000000..3aa216bc5 --- /dev/null +++ b/generate_resources.py @@ -0,0 +1,183 @@ +import os +import json +import importlib +import marshmallow +from ansys.rep.client.jms.schema.object_reference import IdReferenceList + +resources = [ + { + "schema" : "JobDefinitionSchema", + "schema_filename" : "job_definition", + "rest_name": "job_definitions", + "additional_fields": [], + "class": "JobDefinition", + "resource_filename" : "job_definition", + }, + { + "schema" : "ResourceRequirementsSchema", + "schema_filename" : "task_definition", + "rest_name": None, + "additional_fields": [], + "class": "ResourceRequirements", + "resource_filename" : "resource_requirements", + }, + { + "schema" : "JobSchema", + "schema_filename" : "job", + "rest_name": "jobs", + "additional_fields": [], + "class": "Job", + "resource_filename" : "job", + }, + { + "schema" : "EvaluatorSchema", + "schema_filename" : "evaluator", + "rest_name": "evaluators", + "additional_fields": [], + "class": "Evaluator", + "resource_filename" : "evaluator", + } +] + +FIELD_MAPPING = { + marshmallow.fields.Integer: "int", + marshmallow.fields.Float: "float", + marshmallow.fields.String: "str", + marshmallow.fields.Boolean: "bool", + marshmallow.fields.DateTime: "datetime", + marshmallow.fields.Dict: "dict", + marshmallow.fields.List: "list", + IdReferenceList: "list" +} + +def declared_fields(schema): + """ + Helper function to retrieve the fields that will be defined as class members for an object + """ + fields = [] + fields_doc = [] + for k, v in schema._declared_fields.items(): + field = k + # Ensure that we use the attribute name if defined + if getattr(v, "attribute", None) is not None: + field = v.attribute + fields.append(field) + field_doc = f"{field}" + type = FIELD_MAPPING.get(v.__class__, None) + if type: + field_doc += f" ({type})" + desc = v.metadata.get("description", None) + if desc: + field_doc += f": {desc}" + fields_doc.append(field_doc) + return fields, fields_doc + +def get_generated_code(resource, fields, field_docs): + + code =\ +f''' +from marshmallow.utils import missing +from .base import Object +from ..schema.{resource['schema_filename']} import {resource['schema']} + +class {resource['class']}(Object): + """{resource['class']} resource. + + Parameters: +{field_docs} + + The {resource['class']} schema has the following fields: + + .. jsonschema:: schemas/{resource['class']}.json + + """ + + class Meta: + schema = {resource['schema']} + rest_name = "{resource['rest_name']}" + + def __init__(self, **kwargs): +{fields} + super().__init__(**kwargs) + +{resource['schema']}.Meta.object_class = {resource['class']} +''' + return code + + +targe_folder = os.path.join("ansys", "rep", "client", "jms", "resource") + +for resource in resources: + + print(f"Processing resource {resource['class']}") + + module = importlib.import_module(f"ansys.rep.client.jms.schema.{resource['schema_filename']}") + resource_class = getattr(module, resource['schema']) + + fields, field_docs = declared_fields(resource_class) + + fields_str = "" + for k in fields: + fields_str += f" self.{k} = missing\n" + + field_docs_str = "" + for k in field_docs: + field_docs_str += f" {k}\n" + + print(f"Attributes:\n{field_docs_str}") + + code = get_generated_code(resource, fields_str, field_docs_str) + + file_path = os.path.join(targe_folder, f"{resource['resource_filename']}.py") + with open(file_path, 'w') as file: + file.write(code) + + + +# imports=\ +# f""" +# from marshmallow.utils import missing +# from .base import Object +# from ..schema.{resource['schema_filename']} import {resource['schema']} +# """ + +# docstring = f'''"""{resource['class']} resource. + +# Args: +# **kwargs: Arbitrary keyword arguments, see the {resource['class']} schema below. + +# The {resource['class']} schema has the following fields: + +# .. jsonschema:: schemas/{resource['class']}.json + +# """ +# ''' + +# class_definition=\ +# f""" +# class {resource['class']}(Object): +# {docstring} +# class Meta: +# schema = {resource['schema']} +# rest_name = "{resource['rest_name']}" + +# def __init__(self, **kwargs): +# """ + +# set_meta=\ +# f""" +# {resource['schema']}.Meta.object_class = {resource['class']} +# """ + +# module = importlib.import_module(f"ansys.rep.client.jms.schema.{resource['schema_filename']}") +# resource_class = getattr(module, resource['schema']) +# with open(os.path.join("ansys", "rep", "client", "jms", "resource", f"{resource['resource_filename']}.py"), 'w') as file: +# file.write(imports) +# file.write(class_definition) + +# for k in declared_fields(resource_class): +# file.write(f" self.{k} = missing\n") + +# file.write(f" super().__init__(**kwargs)\n") + +# file.write(set_meta) \ No newline at end of file From 79eefdb565fc8d8715b7db231c0b8562bc8b6a64 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 13:49:17 +0200 Subject: [PATCH 02/13] Update resource gen code --- generate_resources.py | 158 +++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 65 deletions(-) diff --git a/generate_resources.py b/generate_resources.py index 3aa216bc5..75af4188c 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -2,9 +2,41 @@ import json import importlib import marshmallow -from ansys.rep.client.jms.schema.object_reference import IdReferenceList +from ansys.rep.client.jms.schema.object_reference import IdReferenceList, IdReference resources = [ + { + "schema" : "AlgorithmSchema", + "schema_filename" : "algorithm", + "rest_name": "algorithms", + "additional_fields": [], + "class": "Algorithm", + "resource_filename" : "algorithm", + }, + { + "schema" : "EvaluatorSchema", + "schema_filename" : "evaluator", + "rest_name": "evaluators", + "additional_fields": [], + "class": "Evaluator", + "resource_filename" : "evaluator", + }, + { + "schema" : "FileSchema", + "schema_filename" : "file", + "rest_name": "files", + "additional_fields": [], + "class": "FileBase", + "resource_filename" : "file_base", + }, + { + "schema" : "JobSchema", + "schema_filename" : "job", + "rest_name": "jobs", + "additional_fields": [], + "class": "Job", + "resource_filename" : "job", + }, { "schema" : "JobDefinitionSchema", "schema_filename" : "job_definition", @@ -13,6 +45,38 @@ "class": "JobDefinition", "resource_filename" : "job_definition", }, + { + "schema" : "LicenseContextSchema", + "schema_filename" : "license_context", + "rest_name": "license_contexts", + "additional_fields": [], + "class": "LicenseContext", + "resource_filename" : "license_context", + }, + { + "schema" : "OperationSchema", + "schema_filename" : "operation", + "rest_name": "operations", + "additional_fields": [], + "class": "Operation", + "resource_filename" : "operation", + }, + { + "schema" : "ParameterMappingSchema", + "schema_filename" : "parameter_mapping", + "rest_name": "parameter_mappings", + "additional_fields": [], + "class": "ParameterMapping", + "resource_filename" : "parameter_mapping", + }, + { + "schema" : "ProjectPermissionSchema", + "schema_filename" : "project_permission", + "rest_name": "permissions", + "additional_fields": [], + "class": "ProjectPermission", + "resource_filename" : "project_permission", + }, { "schema" : "ResourceRequirementsSchema", "schema_filename" : "task_definition", @@ -22,21 +86,29 @@ "resource_filename" : "resource_requirements", }, { - "schema" : "JobSchema", - "schema_filename" : "job", - "rest_name": "jobs", + "schema" : "JobSelectionSchema", + "schema_filename" : "selection", + "rest_name": "job_selections", "additional_fields": [], - "class": "Job", - "resource_filename" : "job", + "class": "JobSelection", + "resource_filename" : "selection", }, { - "schema" : "EvaluatorSchema", - "schema_filename" : "evaluator", - "rest_name": "evaluators", + "schema" : "TaskDefinitionTemplateSchema", + "schema_filename" : "task_definition_template", + "rest_name": "task_definition_templates", "additional_fields": [], - "class": "Evaluator", - "resource_filename" : "evaluator", - } + "class": "TaskDefinitionTemplate", + "resource_filename" : "task_definition_template", + }, + { + "schema" : "TaskSchema", + "schema_filename" : "task", + "rest_name": "tasks", + "additional_fields": [], + "class": "Task", + "resource_filename" : "task", + }, ] FIELD_MAPPING = { @@ -47,7 +119,8 @@ marshmallow.fields.DateTime: "datetime", marshmallow.fields.Dict: "dict", marshmallow.fields.List: "list", - IdReferenceList: "list" + IdReferenceList: "list", + IdReference: "str" } def declared_fields(schema): @@ -62,10 +135,15 @@ def declared_fields(schema): if getattr(v, "attribute", None) is not None: field = v.attribute fields.append(field) + + # build attribute doc field_doc = f"{field}" type = FIELD_MAPPING.get(v.__class__, None) if type: - field_doc += f" ({type})" + field_doc += f" ({type}" + if v.allow_none: + field_doc += ", optional" + field_doc += ")" desc = v.metadata.get("description", None) if desc: field_doc += f": {desc}" @@ -130,54 +208,4 @@ def __init__(self, **kwargs): file_path = os.path.join(targe_folder, f"{resource['resource_filename']}.py") with open(file_path, 'w') as file: - file.write(code) - - - -# imports=\ -# f""" -# from marshmallow.utils import missing -# from .base import Object -# from ..schema.{resource['schema_filename']} import {resource['schema']} -# """ - -# docstring = f'''"""{resource['class']} resource. - -# Args: -# **kwargs: Arbitrary keyword arguments, see the {resource['class']} schema below. - -# The {resource['class']} schema has the following fields: - -# .. jsonschema:: schemas/{resource['class']}.json - -# """ -# ''' - -# class_definition=\ -# f""" -# class {resource['class']}(Object): -# {docstring} -# class Meta: -# schema = {resource['schema']} -# rest_name = "{resource['rest_name']}" - -# def __init__(self, **kwargs): -# """ - -# set_meta=\ -# f""" -# {resource['schema']}.Meta.object_class = {resource['class']} -# """ - -# module = importlib.import_module(f"ansys.rep.client.jms.schema.{resource['schema_filename']}") -# resource_class = getattr(module, resource['schema']) -# with open(os.path.join("ansys", "rep", "client", "jms", "resource", f"{resource['resource_filename']}.py"), 'w') as file: -# file.write(imports) -# file.write(class_definition) - -# for k in declared_fields(resource_class): -# file.write(f" self.{k} = missing\n") - -# file.write(f" super().__init__(**kwargs)\n") - -# file.write(set_meta) \ No newline at end of file + file.write(code) \ No newline at end of file From 11d28d04cfcc143b47bb08bdec3f579df60381f5 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 13:52:02 +0200 Subject: [PATCH 03/13] Style --- generate_resources.py | 132 +++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/generate_resources.py b/generate_resources.py index 75af4188c..ff0b7b83b 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -1,128 +1,130 @@ -import os -import json import importlib +import os + import marshmallow -from ansys.rep.client.jms.schema.object_reference import IdReferenceList, IdReference + +from ansys.rep.client.jms.schema.object_reference import IdReference, IdReferenceList resources = [ - { - "schema" : "AlgorithmSchema", - "schema_filename" : "algorithm", + { + "schema": "AlgorithmSchema", + "schema_filename": "algorithm", "rest_name": "algorithms", "additional_fields": [], "class": "Algorithm", - "resource_filename" : "algorithm", + "resource_filename": "algorithm", }, - { - "schema" : "EvaluatorSchema", - "schema_filename" : "evaluator", + { + "schema": "EvaluatorSchema", + "schema_filename": "evaluator", "rest_name": "evaluators", "additional_fields": [], "class": "Evaluator", - "resource_filename" : "evaluator", + "resource_filename": "evaluator", }, - { - "schema" : "FileSchema", - "schema_filename" : "file", + { + "schema": "FileSchema", + "schema_filename": "file", "rest_name": "files", "additional_fields": [], "class": "FileBase", - "resource_filename" : "file_base", + "resource_filename": "file_base", }, - { - "schema" : "JobSchema", - "schema_filename" : "job", + { + "schema": "JobSchema", + "schema_filename": "job", "rest_name": "jobs", "additional_fields": [], "class": "Job", - "resource_filename" : "job", + "resource_filename": "job", }, - { - "schema" : "JobDefinitionSchema", - "schema_filename" : "job_definition", + { + "schema": "JobDefinitionSchema", + "schema_filename": "job_definition", "rest_name": "job_definitions", "additional_fields": [], "class": "JobDefinition", - "resource_filename" : "job_definition", + "resource_filename": "job_definition", }, - { - "schema" : "LicenseContextSchema", - "schema_filename" : "license_context", + { + "schema": "LicenseContextSchema", + "schema_filename": "license_context", "rest_name": "license_contexts", "additional_fields": [], "class": "LicenseContext", - "resource_filename" : "license_context", + "resource_filename": "license_context", }, - { - "schema" : "OperationSchema", - "schema_filename" : "operation", + { + "schema": "OperationSchema", + "schema_filename": "operation", "rest_name": "operations", "additional_fields": [], "class": "Operation", - "resource_filename" : "operation", + "resource_filename": "operation", }, - { - "schema" : "ParameterMappingSchema", - "schema_filename" : "parameter_mapping", + { + "schema": "ParameterMappingSchema", + "schema_filename": "parameter_mapping", "rest_name": "parameter_mappings", "additional_fields": [], "class": "ParameterMapping", - "resource_filename" : "parameter_mapping", + "resource_filename": "parameter_mapping", }, - { - "schema" : "ProjectPermissionSchema", - "schema_filename" : "project_permission", + { + "schema": "ProjectPermissionSchema", + "schema_filename": "project_permission", "rest_name": "permissions", "additional_fields": [], "class": "ProjectPermission", - "resource_filename" : "project_permission", + "resource_filename": "project_permission", }, - { - "schema" : "ResourceRequirementsSchema", - "schema_filename" : "task_definition", + { + "schema": "ResourceRequirementsSchema", + "schema_filename": "task_definition", "rest_name": None, "additional_fields": [], "class": "ResourceRequirements", - "resource_filename" : "resource_requirements", + "resource_filename": "resource_requirements", }, - { - "schema" : "JobSelectionSchema", - "schema_filename" : "selection", + { + "schema": "JobSelectionSchema", + "schema_filename": "selection", "rest_name": "job_selections", "additional_fields": [], "class": "JobSelection", - "resource_filename" : "selection", + "resource_filename": "selection", }, - { - "schema" : "TaskDefinitionTemplateSchema", - "schema_filename" : "task_definition_template", + { + "schema": "TaskDefinitionTemplateSchema", + "schema_filename": "task_definition_template", "rest_name": "task_definition_templates", "additional_fields": [], "class": "TaskDefinitionTemplate", - "resource_filename" : "task_definition_template", + "resource_filename": "task_definition_template", }, - { - "schema" : "TaskSchema", - "schema_filename" : "task", + { + "schema": "TaskSchema", + "schema_filename": "task", "rest_name": "tasks", "additional_fields": [], "class": "Task", - "resource_filename" : "task", + "resource_filename": "task", }, ] FIELD_MAPPING = { marshmallow.fields.Integer: "int", marshmallow.fields.Float: "float", - marshmallow.fields.String: "str", + marshmallow.fields.String: "str", marshmallow.fields.Boolean: "bool", marshmallow.fields.DateTime: "datetime", marshmallow.fields.Dict: "dict", marshmallow.fields.List: "list", IdReferenceList: "list", - IdReference: "str" + IdReference: "str", } + def declared_fields(schema): """ Helper function to retrieve the fields that will be defined as class members for an object @@ -150,17 +152,17 @@ def declared_fields(schema): fields_doc.append(field_doc) return fields, fields_doc + def get_generated_code(resource, fields, field_docs): - code =\ -f''' + code = f''' from marshmallow.utils import missing from .base import Object from ..schema.{resource['schema_filename']} import {resource['schema']} class {resource['class']}(Object): """{resource['class']} resource. - + Parameters: {field_docs} @@ -190,7 +192,7 @@ def __init__(self, **kwargs): print(f"Processing resource {resource['class']}") module = importlib.import_module(f"ansys.rep.client.jms.schema.{resource['schema_filename']}") - resource_class = getattr(module, resource['schema']) + resource_class = getattr(module, resource["schema"]) fields, field_docs = declared_fields(resource_class) @@ -203,9 +205,9 @@ def __init__(self, **kwargs): field_docs_str += f" {k}\n" print(f"Attributes:\n{field_docs_str}") - + code = get_generated_code(resource, fields_str, field_docs_str) - + file_path = os.path.join(targe_folder, f"{resource['resource_filename']}.py") - with open(file_path, 'w') as file: - file.write(code) \ No newline at end of file + with open(file_path, "w") as file: + file.write(code) From 79ccf76fe324dcb5f7e184b28cf4c264c6b955b7 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 15:18:31 +0200 Subject: [PATCH 04/13] Improvements --- ansys/rep/client/jms/api/project_api.py | 48 ++++++++++++++++-- ansys/rep/client/jms/resource/file.py | 67 +++++++++++++++---------- generate_resources.py | 21 +++++--- 3 files changed, 97 insertions(+), 39 deletions(-) diff --git a/ansys/rep/client/jms/api/project_api.py b/ansys/rep/client/jms/api/project_api.py index 75fb7aa21..6d396bc14 100644 --- a/ansys/rep/client/jms/api/project_api.py +++ b/ansys/rep/client/jms/api/project_api.py @@ -1,9 +1,13 @@ +import json import logging import os -import json from pathlib import Path from typing import Callable, List +from cachetools import TTLCache, cached +from marshmallow.utils import missing +import requests + from ansys.rep.client.exceptions import ClientError, REPError from ..resource.algorithm import Algorithm @@ -14,8 +18,8 @@ from ..resource.license_context import LicenseContext from ..resource.parameter_definition import ParameterDefinition from ..resource.parameter_mapping import ParameterMapping -from ..resource.project import get_fs_url -from ..resource.project_permission import ProjectPermission, update_permissions +from ..resource.project import Project +from ..resource.project_permission import ProjectPermission, ProjectPermissionSchema from ..resource.selection import JobSelection from ..resource.task import Task from ..resource.task_definition import TaskDefinition @@ -491,6 +495,7 @@ def archive_project(project_api: ProjectApi, target_path, include_job_files=True log.info(f"Done saving project archive to disk") return file_path + def copy_jobs(project_api: ProjectApi, jobs: List[Job], as_objects=True, **query_params): """Create new jobs by copying existing ones""" @@ -512,4 +517,39 @@ def sync_jobs(project_api: ProjectApi, jobs: List[Job]): url = f"{project_api.url}/jobs:sync" json_data = json.dumps({"job_ids": [obj.id for obj in jobs]}) - r = project_api.client.session.put(f"{url}", data=json_data) \ No newline at end of file + r = project_api.client.session.put(f"{url}", data=json_data) + + +def update_permissions(client, project_api_url, permissions): + + if not permissions: + return + + url = f"{project_api_url}/permissions" + + schema = ProjectPermissionSchema(many=True) + serialized_data = schema.dump(permissions) + json_data = json.dumps({"permissions": serialized_data}) + r = client.session.put(f"{url}", data=json_data) + + +@cached(cache=TTLCache(1024, 60), key=lambda project: project.id) +def get_fs_url(project: Project): + if project.file_storages == missing: + raise REPError(f"The project object has no file storages information.") + rest_gateways = [fs for fs in project.file_storages if fs["obj_type"] == "RestGateway"] + rest_gateways.sort(key=lambda fs: fs["priority"], reverse=True) + + if not rest_gateways: + raise REPError(f"Project {project.name} (id={project.id}) has no Rest Gateway defined.") + + for d in rest_gateways: + url = d["url"] + try: + r = requests.get(url, verify=False, timeout=2) + except Exception as ex: + log.debug(ex) + continue + if r.status_code == 200: + return url + return None diff --git a/ansys/rep/client/jms/resource/file.py b/ansys/rep/client/jms/resource/file.py index 5edad4409..4e58fd147 100644 --- a/ansys/rep/client/jms/resource/file.py +++ b/ansys/rep/client/jms/resource/file.py @@ -1,37 +1,34 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging +from marshmallow.utils import missing from ..schema.file import FileSchema from .base import Object -log = logging.getLogger(__name__) - class File(Object): """File resource. - Args: - src (str, optional): Path to the local file. Defaults to None. - **kwargs: Arbitrary keyword arguments, see the File schema below. - - Example: - - >>> # input file - >>> f1 = File(name="mac", evaluation_path="demo_project.mac", - type="text/plain", src=os.path.join(os.getcwd(), "motorbike_frame.mac") - >>> # output file - >>> f2 = File(name="img", evaluation_path="file000.jpg", type="image/jpeg") ) - - The File schema has the following fields: - - .. jsonschema:: schemas/File.json - + Parameters: + id (str, optional): Unique ID to access the resource, + generated internally by the server on creation. + name (str): Name of the file resource. + type (str, optional): Type of the file. + This can be any string but using a correct media type for the + given resource is advisable. + storage_id (str, optional): File's identifier in the (orthogonal) file storage system + size (int, optional) + hash (str, optional) + creation_time (datetime, optional): The date and time the file resource was created. + modification_time (datetime, optional): The date and time the file resource + was last modified. + format (str, optional) + evaluation_path (str, optional): Relative path under which the file instance + for a design point evaluation will be stored. + monitor (bool, optional): Whether to live monitor the file's content. + collect (bool, optional): Whether file should be collected per design point + collect_interval (int, optional): Collect frequency for a file with collect=True. + Min value limited by the evaluator's settings. 0/None - let the evaluator decide, + other value - interval in seconds + reference_id (str, optional): Reference file from which this one was created """ class Meta: @@ -41,7 +38,23 @@ class Meta: def __init__(self, src=None, **kwargs): self.src = src self.content = None - super(File, self).__init__(**kwargs) + + self.id = missing + self.name = missing + self.type = missing + self.storage_id = missing + self.size = missing + self.hash = missing + self.creation_time = missing + self.modification_time = missing + self.format = missing + self.evaluation_path = missing + self.monitor = missing + self.collect = missing + self.collect_interval = missing + self.reference_id = missing + + super().__init__(**kwargs) FileSchema.Meta.object_class = File diff --git a/generate_resources.py b/generate_resources.py index ff0b7b83b..e27bb9263 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -70,6 +70,14 @@ "class": "ParameterMapping", "resource_filename": "parameter_mapping", }, + { + "schema": "ProjectSchema", + "schema_filename": "project", + "rest_name": "projects", + "additional_fields": [], + "class": "Project", + "resource_filename": "project", + }, { "schema": "ProjectPermissionSchema", "schema_filename": "project_permission", @@ -143,9 +151,11 @@ def declared_fields(schema): type = FIELD_MAPPING.get(v.__class__, None) if type: field_doc += f" ({type}" - if v.allow_none: - field_doc += ", optional" - field_doc += ")" + if v.allow_none: + field_doc += ", optional" + field_doc += ")" + elif v.allow_none: + field_doc += " (optional)" desc = v.metadata.get("description", None) if desc: field_doc += f": {desc}" @@ -165,11 +175,6 @@ class {resource['class']}(Object): Parameters: {field_docs} - - The {resource['class']} schema has the following fields: - - .. jsonschema:: schemas/{resource['class']}.json - """ class Meta: From e85f50d4cef4ceba4dc868213edf0eaf040d9509 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 15:28:23 +0200 Subject: [PATCH 05/13] Fix encoding issue --- ansys/rep/client/jms/schema/algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansys/rep/client/jms/schema/algorithm.py b/ansys/rep/client/jms/schema/algorithm.py index e88d5eb95..3567ca505 100644 --- a/ansys/rep/client/jms/schema/algorithm.py +++ b/ansys/rep/client/jms/schema/algorithm.py @@ -31,6 +31,6 @@ class Meta(ObjectSchema.Meta): data = fields.String( allow_none=True, description="Generic string field to hold arbitrary algorithm job_definition data," - " e.g. as JSON dict​ionary.", + " e.g. as JSON dictionary.", ) job_ids = IdReferenceList("Job", attribute="jobs", description="List of design point IDs.") From 3104fb43aea87bd51456e15065951290ec4ead9b Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 17:17:44 +0200 Subject: [PATCH 06/13] Commit generated files --- .pre-commit-config.yaml | 3 + ansys/rep/client/jms/resource/.gitignore | 1 + ansys/rep/client/jms/resource/__init__.py | 23 +- ansys/rep/client/jms/resource/algorithm.py | 45 ++-- .../jms/resource/bool_parameter_definition.py | 37 ++++ ansys/rep/client/jms/resource/evaluator.py | 49 +++-- .../client/jms/resource/fitness_definition.py | 39 ++-- .../resource/float_parameter_definition.py | 47 ++++ .../jms/resource/int_parameter_definition.py | 45 ++++ ansys/rep/client/jms/resource/job.py | 89 ++++---- .../rep/client/jms/resource/job_definition.py | 51 ++--- .../client/jms/resource/license_context.py | 35 +-- ansys/rep/client/jms/resource/licensing.py | 23 ++ ansys/rep/client/jms/resource/operation.py | 35 ++- .../jms/resource/parameter_definition.py | 141 +----------- .../client/jms/resource/parameter_mapping.py | 63 +++--- ansys/rep/client/jms/resource/project.py | 75 ++----- .../client/jms/resource/project_permission.py | 42 ++-- .../jms/resource/resource_requirements.py | 31 +++ ansys/rep/client/jms/resource/selection.py | 41 ++-- ansys/rep/client/jms/resource/software.py | 25 +++ .../resource/string_parameter_definition.py | 39 ++++ .../client/jms/resource/success_criteria.py | 33 +++ ansys/rep/client/jms/resource/task.py | 61 ++++-- .../client/jms/resource/task_definition.py | 203 ++++-------------- .../jms/resource/task_definition_template.py | 73 +++---- generate_resources.py | 120 ++++++++++- tests/jms/test_parameter_definitions.py | 5 +- 28 files changed, 795 insertions(+), 679 deletions(-) create mode 100644 ansys/rep/client/jms/resource/.gitignore create mode 100644 ansys/rep/client/jms/resource/bool_parameter_definition.py create mode 100644 ansys/rep/client/jms/resource/float_parameter_definition.py create mode 100644 ansys/rep/client/jms/resource/int_parameter_definition.py create mode 100644 ansys/rep/client/jms/resource/licensing.py create mode 100644 ansys/rep/client/jms/resource/resource_requirements.py create mode 100644 ansys/rep/client/jms/resource/software.py create mode 100644 ansys/rep/client/jms/resource/string_parameter_definition.py create mode 100644 ansys/rep/client/jms/resource/success_criteria.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ac9135be..d85c0d812 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,16 +4,19 @@ repos: rev: 22.3.0 hooks: - id: black + exclude: ^ansys/rep/client/jms/resource/ - repo: https://github.com/pycqa/isort rev: 5.10.1 hooks: - id: isort + exclude: ^ansys/rep/client/jms/resource/ - repo: https://gitlab.com/PyCQA/flake8 rev: 4.0.1 hooks: - id: flake8 + exclude: ^ansys/rep/client/jms/resource/ - repo: https://github.com/codespell-project/codespell rev: v2.1.0 diff --git a/ansys/rep/client/jms/resource/.gitignore b/ansys/rep/client/jms/resource/.gitignore new file mode 100644 index 000000000..1a3af6606 --- /dev/null +++ b/ansys/rep/client/jms/resource/.gitignore @@ -0,0 +1 @@ +*_base.py \ No newline at end of file diff --git a/ansys/rep/client/jms/resource/__init__.py b/ansys/rep/client/jms/resource/__init__.py index 96c13354c..5b6f44714 100644 --- a/ansys/rep/client/jms/resource/__init__.py +++ b/ansys/rep/client/jms/resource/__init__.py @@ -7,29 +7,26 @@ # ---------------------------------------------------------- from .algorithm import Algorithm +from .bool_parameter_definition import BoolParameterDefinition from .evaluator import Evaluator from .file import File from .fitness_definition import FitnessDefinition, FitnessTermDefinition +from .float_parameter_definition import FloatParameterDefinition +from .int_parameter_definition import IntParameterDefinition from .job import Job from .job_definition import JobDefinition from .license_context import LicenseContext +from .licensing import Licensing from .operation import Operation -from .parameter_definition import ( - BoolParameterDefinition, - FloatParameterDefinition, - IntParameterDefinition, - StringParameterDefinition, -) +from .parameter_definition import ParameterDefinition from .parameter_mapping import ParameterMapping from .project import Project from .project_permission import ProjectPermission +from .resource_requirements import ResourceRequirements from .selection import JobSelection +from .software import Software +from .string_parameter_definition import StringParameterDefinition +from .success_criteria import SuccessCriteria from .task import Task -from .task_definition import ( - Licensing, - ResourceRequirements, - Software, - SuccessCriteria, - TaskDefinition, -) +from .task_definition import TaskDefinition from .task_definition_template import TaskDefinitionTemplate diff --git a/ansys/rep/client/jms/resource/algorithm.py b/ansys/rep/client/jms/resource/algorithm.py index 7b0f82c50..4970040dd 100644 --- a/ansys/rep/client/jms/resource/algorithm.py +++ b/ansys/rep/client/jms/resource/algorithm.py @@ -1,33 +1,19 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.algorithm import AlgorithmSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.algorithm import AlgorithmSchema class Algorithm(Object): """Algorithm resource. - Args: - **kwargs: Arbitrary keyword arguments, see the Algorithm schema below. - - Example: - - >>> algo = Algorithm(name="gradient_descent") - >>> algo.description = "Gradient descent is an iterative optimization algorithm." - >>> algo.data = "{\"step_size\": 0.2,\"max_iterations\":10}" - - The Algorithm schema has the following fields: - - .. jsonschema:: schemas/Algorithm.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name of the algorithm. + description (str, optional): Description of the algorithm. + creation_time (datetime, optional): The date and time the algorithm was created. + modification_time (datetime, optional): The date and time the algorithm was last modified. + data (str, optional): Generic string field to hold arbitrary algorithm job_definition data, e.g. as JSON dictionary. + jobs (list): List of design point IDs. """ @@ -36,7 +22,14 @@ class Meta: rest_name = "algorithms" def __init__(self, **kwargs): - super(Algorithm, self).__init__(**kwargs) - + self.id = missing + self.name = missing + self.description = missing + self.creation_time = missing + self.modification_time = missing + self.data = missing + self.jobs = missing + + super().__init__(**kwargs) AlgorithmSchema.Meta.object_class = Algorithm diff --git a/ansys/rep/client/jms/resource/bool_parameter_definition.py b/ansys/rep/client/jms/resource/bool_parameter_definition.py new file mode 100644 index 000000000..875e639e1 --- /dev/null +++ b/ansys/rep/client/jms/resource/bool_parameter_definition.py @@ -0,0 +1,37 @@ + +from marshmallow.utils import missing +from .parameter_definition import ParameterDefinition +from ..schema.parameter_definition import BoolParameterDefinitionSchema + +class BoolParameterDefinition(ParameterDefinition): + """BoolParameterDefinition resource. + + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name (ID) of the parameter. + quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. + units (str, optional): Units for the parameter. + display_text (str, optional): Text to display as the parameter name. + mode (str): Indicates whether it's an input or output parameter. Filled server side. + type + default (bool, optional): Default parameter value. + + """ + + class Meta: + schema = BoolParameterDefinitionSchema + rest_name = "parameter_definitions" + + def __init__(self, **kwargs): + self.id = missing + self.name = missing + self.quantity_name = missing + self.units = missing + self.display_text = missing + self.mode = missing + self.type = missing + self.default = missing + + super().__init__(**kwargs) + +BoolParameterDefinitionSchema.Meta.object_class = BoolParameterDefinition diff --git a/ansys/rep/client/jms/resource/evaluator.py b/ansys/rep/client/jms/resource/evaluator.py index ff33909e2..54065106d 100644 --- a/ansys/rep/client/jms/resource/evaluator.py +++ b/ansys/rep/client/jms/resource/evaluator.py @@ -1,23 +1,25 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): F.Negri -# ---------------------------------------------------------- -from ..schema.evaluator import EvaluatorSchema -from .base import Object +from marshmallow.utils import missing +from .base import Object +from ..schema.evaluator import EvaluatorSchema class Evaluator(Object): """Evaluator resource. - Args: - **kwargs: Arbitrary keyword arguments, see the Evaluator schema below. - - The Evaluator schema has the following fields: - - .. jsonschema:: schemas/Evaluator.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + host_id (str): Unique identifier built from hardware information and selected job_definition details of an evaluator. + name (str, optional): Name of the evaluator. + hostname (str, optional): Name of the host on which the evaluator is running. + platform (str, optional): Operating system on which the evaluator is running. + task_manager_type (str, optional): Type of the task manager used by the evaluator. + project_server_select (bool, optional): Whether the evaluator allows server-driven assignment of projects or uses it's own local settings. + alive_update_interval (int, optional): Minimal time (in seconds) between evaluator registration updates. + update_time (datetime, optional): Last time the evaluator updated it's registration details. Used to check which evaluators are alive. + external_access_port (int, optional): Port number for external access to the evaluator. + project_assignment_mode (str, optional): Which strategy to use for selecting projects to work on. + project_list (list): List of projects on which this evaluator should be working. + configuration (dict, optional): Details of the evaluator configuration, including hardware info and available applications. """ @@ -26,7 +28,20 @@ class Meta: rest_name = "evaluators" def __init__(self, **kwargs): - super(Evaluator, self).__init__(**kwargs) - + self.id = missing + self.host_id = missing + self.name = missing + self.hostname = missing + self.platform = missing + self.task_manager_type = missing + self.project_server_select = missing + self.alive_update_interval = missing + self.update_time = missing + self.external_access_port = missing + self.project_assignment_mode = missing + self.project_list = missing + self.configuration = missing + + super().__init__(**kwargs) EvaluatorSchema.Meta.object_class = Evaluator diff --git a/ansys/rep/client/jms/resource/fitness_definition.py b/ansys/rep/client/jms/resource/fitness_definition.py index b4faee72f..406111178 100644 --- a/ansys/rep/client/jms/resource/fitness_definition.py +++ b/ansys/rep/client/jms/resource/fitness_definition.py @@ -18,12 +18,12 @@ class FitnessTermDefinition(Object): """FitnessTermDefinition resource. - Args: - **kwargs: Arbitrary keyword arguments, see the FitnessTermDefinition schema below. - - The FitnessTermDefinition schema has the following fields: - - .. jsonschema:: schemas/FitnessTermDefinition.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name of the fitness term. + expression (str, optional): The Python expression that defines the fitness term. + type (str, optional): Fitness term type. + weighting_factor (float, optional): Relative importance of the fitness term in comparison to other fitness terms. Example: @@ -51,9 +51,16 @@ class FitnessTermDefinition(Object): class Meta: schema = FitnessTermDefinitionSchema + rest_name = "None" def __init__(self, **kwargs): - super(FitnessTermDefinition, self).__init__(**kwargs) + self.id = missing + self.name = missing + self.expression = missing + self.type = missing + self.weighting_factor = missing + + super().__init__(**kwargs) FitnessTermDefinitionSchema.Meta.object_class = FitnessTermDefinition @@ -62,8 +69,10 @@ def __init__(self, **kwargs): class FitnessDefinition(Object): """FitnessDefinition resource. - Args: - **kwargs: Arbitrary keyword arguments, see the Job schema below. + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + fitness_term_definitions: List of :class:`ansys.rep.client.jms.FitnessTermDefinition`. + error_fitness (float): The default fitness value assigned to failed design points. Example: @@ -78,18 +87,18 @@ class FitnessDefinition(Object): 1313.0, 5.0, 30.0 )" ) - - The FitnessDefinition schema has the following fields: - - .. jsonschema:: schemas/FitnessDefinition.json - """ class Meta: schema = FitnessDefinitionSchema + rest_name = "None" def __init__(self, **kwargs): - super(FitnessDefinition, self).__init__(**kwargs) + self.id = missing + self.fitness_term_definitions = missing + self.error_fitness = missing + + super().__init__(**kwargs) def add_fitness_term(self, **kwargs): """ diff --git a/ansys/rep/client/jms/resource/float_parameter_definition.py b/ansys/rep/client/jms/resource/float_parameter_definition.py new file mode 100644 index 000000000..5d768014a --- /dev/null +++ b/ansys/rep/client/jms/resource/float_parameter_definition.py @@ -0,0 +1,47 @@ + +from marshmallow.utils import missing +from .parameter_definition import ParameterDefinition +from ..schema.parameter_definition import FloatParameterDefinitionSchema + +class FloatParameterDefinition(ParameterDefinition): + """FloatParameterDefinition resource. + + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name (ID) of the parameter. + quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. + units (str, optional): Units for the parameter. + display_text (str, optional): Text to display as the parameter name. + mode (str): Indicates whether it's an input or output parameter. Filled server side. + type + default (float, optional): Default parameter value. + lower_limit (float, optional): Lower bound for the parameter value. + upper_limit (float, optional): Upper bound for the parameter value. + step (float, optional): If provided, allowable values are given by: AllowableValue = lower_limit + n * step, where n is an integer and AllowableValue <= upper_limit. + cyclic (bool, optional): Indicates if the parameter is cyclic. + value_list (list, optional): A list of allowed values, alternative to providing upper and lower limits. + + """ + + class Meta: + schema = FloatParameterDefinitionSchema + rest_name = "parameter_definitions" + + def __init__(self, **kwargs): + self.id = missing + self.name = missing + self.quantity_name = missing + self.units = missing + self.display_text = missing + self.mode = missing + self.type = missing + self.default = missing + self.lower_limit = missing + self.upper_limit = missing + self.step = missing + self.cyclic = missing + self.value_list = missing + + super().__init__(**kwargs) + +FloatParameterDefinitionSchema.Meta.object_class = FloatParameterDefinition diff --git a/ansys/rep/client/jms/resource/int_parameter_definition.py b/ansys/rep/client/jms/resource/int_parameter_definition.py new file mode 100644 index 000000000..aa97133b6 --- /dev/null +++ b/ansys/rep/client/jms/resource/int_parameter_definition.py @@ -0,0 +1,45 @@ + +from marshmallow.utils import missing +from .parameter_definition import ParameterDefinition +from ..schema.parameter_definition import IntParameterDefinitionSchema + +class IntParameterDefinition(ParameterDefinition): + """IntParameterDefinition resource. + + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name (ID) of the parameter. + quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. + units (str, optional): Units for the parameter. + display_text (str, optional): Text to display as the parameter name. + mode (str): Indicates whether it's an input or output parameter. Filled server side. + type + default (int, optional): Default parameter value. + lower_limit (int, optional): Lower bound for the parameter value. + upper_limit (int, optional): Upper bound for the parameter value. + step (int, optional): Equal to 1 by default. + cyclic (bool, optional): Indicates if the parameter is cyclic. + + """ + + class Meta: + schema = IntParameterDefinitionSchema + rest_name = "parameter_definitions" + + def __init__(self, **kwargs): + self.id = missing + self.name = missing + self.quantity_name = missing + self.units = missing + self.display_text = missing + self.mode = missing + self.type = missing + self.default = missing + self.lower_limit = missing + self.upper_limit = missing + self.step = missing + self.cyclic = missing + + super().__init__(**kwargs) + +IntParameterDefinitionSchema.Meta.object_class = IntParameterDefinition diff --git a/ansys/rep/client/jms/resource/job.py b/ansys/rep/client/jms/resource/job.py index fa38d628c..906a6c1d6 100644 --- a/ansys/rep/client/jms/resource/job.py +++ b/ansys/rep/client/jms/resource/job.py @@ -1,35 +1,28 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import json -import logging -from ..schema.job import JobSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.job import JobSchema class Job(Object): """Job resource. - Args: - **kwargs: Arbitrary keyword arguments, see the Job schema below. - - Example: - - >>> jobs = [] - >>> jobs.append( Job( name="job_1", eval_status="pending", job_definition_id=job_def.id) ) - >>> jobs.append( Job( name="job_2", eval_status="pending", job_definition_id=job_def.id) ) - >>> project_api.create_jobs( jobs ) - - The Job schema has the following fields: - - .. jsonschema:: schemas/Job.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name of the design point. + eval_status (str): Evaluation status. + job_definition_id (str): ID of the linked job_definition, see :class:`ansys.rep.client.jms.JobDefinition`. + priority (int, optional): Priority with which design points are evaluated. The default is 0, which is the highest priority. Assigning a higher value to a design point makes it a lower priority. + values (dict, optional): Dictionary with (name,value) pairs for all parameters defined in the linked job_definition. + fitness (float, optional): Fitness value computed. + fitness_term_values (dict, optional): Dictionary with (name,value) pairs for all fitness terms computed. + note (str, optional): Optional note for this design point. + creator (str, optional): Optional name/ID of the creator of this design point. + executed_task_definition_level (int, optional): Execution level of the last executed process step (-1 if none has been executed yet). + creation_time (datetime, optional): The date and time the design point was created. + modification_time (datetime, optional): The date and time the design point was last modified. + elapsed_time (float): Number of seconds it took the evaluator(s) to update the design point. + evaluators (list, optional): List of UUID strings of the evaluators that updated the design point. + file_ids (list): List of IDs of all files of this design point. """ @@ -38,31 +31,23 @@ class Meta: rest_name = "jobs" def __init__(self, **kwargs): - super(Job, self).__init__(**kwargs) - + self.id = missing + self.name = missing + self.eval_status = missing + self.job_definition_id = missing + self.priority = missing + self.values = missing + self.fitness = missing + self.fitness_term_values = missing + self.note = missing + self.creator = missing + self.executed_task_definition_level = missing + self.creation_time = missing + self.modification_time = missing + self.elapsed_time = missing + self.evaluators = missing + self.file_ids = missing + + super().__init__(**kwargs) JobSchema.Meta.object_class = Job - - -def copy_jobs(project_api, jobs, as_objects=True, **query_params): - """Create new jobs by copying existing ones""" - - url = f"{project_api.url}/jobs" - - query_params.setdefault("fields", "all") - - json_data = json.dumps({"source_ids": [obj.id for obj in jobs]}) - r = project_api.client.session.post(f"{url}", data=json_data, params=query_params) - - data = r.json()["jobs"] - if not as_objects: - return data - - return JobSchema(many=True).load(data) - - -def sync_jobs(project_api, jobs): - - url = f"{project_api.url}/jobs:sync" - json_data = json.dumps({"job_ids": [obj.id for obj in jobs]}) - r = project_api.client.session.put(f"{url}", data=json_data) diff --git a/ansys/rep/client/jms/resource/job_definition.py b/ansys/rep/client/jms/resource/job_definition.py index eb71d4f3e..af19c3c73 100644 --- a/ansys/rep/client/jms/resource/job_definition.py +++ b/ansys/rep/client/jms/resource/job_definition.py @@ -1,35 +1,21 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.job_definition import JobDefinitionSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.job_definition import JobDefinitionSchema class JobDefinition(Object): """JobDefinition resource. - Args: - **kwargs: Arbitrary keyword arguments, see the JobDefinition schema below. - - Example: - - >>> job_def = JobDefinition(name="JobDefinition.1", active=True) - >>> job_def.add_float_parameter_definition(name='tube_radius', - lower_limit=4.0, - upper_limit=20.0, - default=12.0 ) - - The JobDefinition schema has the following fields: - - .. jsonschema:: schemas/JobDefinition.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name of the job_definition + active (bool): Defines whether this is the active job_definition in the project where evaluators will evaluate pending design points + creation_time (datetime, optional): The date and time the job_definition was created. + modification_time (datetime, optional): The date and time the job_definition was last modified. + parameter_definition_ids (list) + parameter_mapping_ids (list) + task_definition_ids (list) + fitness_definition (optional): An :class:`ansys.rep.client.jms.FitnessDefinition` object. """ @@ -38,7 +24,16 @@ class Meta: rest_name = "job_definitions" def __init__(self, **kwargs): - super(JobDefinition, self).__init__(**kwargs) - + self.id = missing + self.name = missing + self.active = missing + self.creation_time = missing + self.modification_time = missing + self.parameter_definition_ids = missing + self.parameter_mapping_ids = missing + self.task_definition_ids = missing + self.fitness_definition = missing + + super().__init__(**kwargs) JobDefinitionSchema.Meta.object_class = JobDefinition diff --git a/ansys/rep/client/jms/resource/license_context.py b/ansys/rep/client/jms/resource/license_context.py index 890bf6c58..f921f89ec 100644 --- a/ansys/rep/client/jms/resource/license_context.py +++ b/ansys/rep/client/jms/resource/license_context.py @@ -1,33 +1,14 @@ -# ---------------------------------------------------------- -# Copyright (C) 2021 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.license_context import LicenseContextSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.license_context import LicenseContextSchema class LicenseContext(Object): - """ - License context resource - - Example: - - >>> lc = LicenseContext( - environment={"ANSYS_HPC_PARAMETRIC_ID": "my_id", - "ANSYS_HPC_PARAMETRIC_SERVER":"my_server" } - ) - ) - - The LicenseContext schema has the following fields: + """LicenseContext resource. - .. jsonschema:: schemas/LicenseContext.json + Parameters: + context_id (str, optional): License context ID + environment (dict, optional): License context environment dict """ @@ -36,7 +17,9 @@ class Meta: rest_name = "license_contexts" def __init__(self, **kwargs): - super(LicenseContext, self).__init__(**kwargs) + self.context_id = missing + self.environment = missing + super().__init__(**kwargs) LicenseContextSchema.Meta.object_class = LicenseContext diff --git a/ansys/rep/client/jms/resource/licensing.py b/ansys/rep/client/jms/resource/licensing.py new file mode 100644 index 000000000..8144a9a10 --- /dev/null +++ b/ansys/rep/client/jms/resource/licensing.py @@ -0,0 +1,23 @@ + +from marshmallow.utils import missing +from .base import Object +from ..schema.task_definition import LicensingSchema + +class Licensing(Object): + """Licensing resource. + + Parameters: + enable_shared_licensing (bool, optional): Whether to enable shared licensing contexts for Ansys simulations + + """ + + class Meta: + schema = LicensingSchema + rest_name = "None" + + def __init__(self, **kwargs): + self.enable_shared_licensing = missing + + super().__init__(**kwargs) + +LicensingSchema.Meta.object_class = Licensing diff --git a/ansys/rep/client/jms/resource/operation.py b/ansys/rep/client/jms/resource/operation.py index b60b341df..72e0266d3 100644 --- a/ansys/rep/client/jms/resource/operation.py +++ b/ansys/rep/client/jms/resource/operation.py @@ -1,17 +1,22 @@ -import logging -from ..schema.operation import OperationSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.operation import OperationSchema class Operation(Object): """Operation resource. - The operation schema has the following fields: - - .. jsonschema:: schemas/Operation.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional) + finished (bool, optional) + succeeded (bool, optional) + progress (float, optional) + status (str, optional) + result (dict, optional) + messages (list, optional) + start_time (datetime, optional) + end_time (datetime, optional) """ @@ -20,7 +25,17 @@ class Meta: rest_name = "operations" def __init__(self, **kwargs): - super(Operation, self).__init__(**kwargs) - + self.id = missing + self.name = missing + self.finished = missing + self.succeeded = missing + self.progress = missing + self.status = missing + self.result = missing + self.messages = missing + self.start_time = missing + self.end_time = missing + + super().__init__(**kwargs) OperationSchema.Meta.object_class = Operation diff --git a/ansys/rep/client/jms/resource/parameter_definition.py b/ansys/rep/client/jms/resource/parameter_definition.py index 46bedf2f8..3fa644bc4 100644 --- a/ansys/rep/client/jms/resource/parameter_definition.py +++ b/ansys/rep/client/jms/resource/parameter_definition.py @@ -1,146 +1,21 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.parameter_definition import ( - BoolParameterDefinitionSchema, - FloatParameterDefinitionSchema, - IntParameterDefinitionSchema, - ParameterDefinitionSchema, - StringParameterDefinitionSchema, -) +from marshmallow.utils import missing from .base import Object +from ..schema.parameter_definition import ParameterDefinitionSchema -log = logging.getLogger(__name__) +class ParameterDefinition(Object): + """ParameterDefinition resource. + Parameters: + + """ -class ParameterDefinition(Object): class Meta: schema = ParameterDefinitionSchema rest_name = "parameter_definitions" def __init__(self, **kwargs): - super(ParameterDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) ParameterDefinitionSchema.Meta.object_class = ParameterDefinition - - -class FloatParameterDefinition(ParameterDefinition): - """FloatParameterDefinition resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the FloatParameterDefinition schema below. - - Example: - - >>> # A continuous parameter - >>> pd1 = FloatParameterDefinition(name='param_1', lower_limit=4.0, - upper_limit=20.0, default=12.0) - >>> # In case of e.g. a manifacturing variable which can only take some values - >>> pd2 = FloatParameterDefinition(name='param_2', - value_list=[4.7, 12.0, 15.5, 20.0], - default=12.0) - - The FloatParameterDefinition schema has the following fields: - - .. jsonschema:: schemas/FloatParameterDefinition.json - - """ - - class Meta(ParameterDefinition.Meta): - schema = FloatParameterDefinitionSchema - - def __init__(self, **kwargs): - super(FloatParameterDefinition, self).__init__(**kwargs) - - -FloatParameterDefinitionSchema.Meta.object_class = FloatParameterDefinition - - -class IntParameterDefinition(ParameterDefinition): - """IntParameterDefinition resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the IntParameterDefinition schema below. - - Example: - - >>> pd1 = IntParameterDefinition(name='ply_angle', - value_list=[-60, -45, 0, 45, 60], - default=0) - >>> pd2 = IntParameterDefinition(name='number_of_layers', - lower_limit=1, - upper_limit=5, - default=2, - step=1) - - The IntParameterDefinition schema has the following fields: - - .. jsonschema:: schemas/IntParameterDefinition.json - - """ - - class Meta(ParameterDefinition.Meta): - schema = IntParameterDefinitionSchema - - def __init__(self, **kwargs): - super(IntParameterDefinition, self).__init__(**kwargs) - - -IntParameterDefinitionSchema.Meta.object_class = IntParameterDefinition - - -class BoolParameterDefinition(ParameterDefinition): - """BoolParameterDefinition resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the BoolParameterDefinition schema below. - - The BoolParameterDefinition schema has the following fields: - - .. jsonschema:: schemas/BoolParameterDefinition.json - - """ - - class Meta(ParameterDefinition.Meta): - schema = BoolParameterDefinitionSchema - - def __init__(self, **kwargs): - super(BoolParameterDefinition, self).__init__(**kwargs) - - -BoolParameterDefinitionSchema.Meta.object_class = BoolParameterDefinition - - -class StringParameterDefinition(ParameterDefinition): - """StringParameterDefinition resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the StringParameterDefinition schema below. - - Example: - - >>> pd = StringParameterDefinition(name='DiameterDistribution', - value_list=['Constant', 'Uniform', 'Log-Normal'], - default='Constant') - - The StringParameterDefinition schema has the following fields: - - .. jsonschema:: schemas/StringParameterDefinition.json - - """ - - class Meta(ParameterDefinition.Meta): - schema = StringParameterDefinitionSchema - - def __init__(self, **kwargs): - super(StringParameterDefinition, self).__init__(**kwargs) - - -StringParameterDefinitionSchema.Meta.object_class = StringParameterDefinition diff --git a/ansys/rep/client/jms/resource/parameter_mapping.py b/ansys/rep/client/jms/resource/parameter_mapping.py index 2b0d43eb0..6aec5ec07 100644 --- a/ansys/rep/client/jms/resource/parameter_mapping.py +++ b/ansys/rep/client/jms/resource/parameter_mapping.py @@ -1,33 +1,28 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.parameter_mapping import ParameterMappingSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.parameter_mapping import ParameterMappingSchema class ParameterMapping(Object): """ParameterMapping resource. - Args: - **kwargs: Arbitrary keyword arguments, see the ParameterMapping schema below. - - Example: - - >>> pl = ParameterMapping(key_string='radius(0)', - tokenizer="=", - parameter_definition_name="tube_radius") - - The ParameterMapping schema has the following fields: - - .. jsonschema:: schemas/ParameterMapping.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + line (int, optional) + column (int, optional) + key_string (str, optional) + float_field (str, optional) + width (int, optional) + precision (int, optional) + tokenizer (str, optional) + decimal_symbol (str, optional) + digit_grouping_symbol (str, optional) + string_quote (str, optional) + true_string (str, optional) + false_string (str, optional) + parameter_definition_id (str, optional): ID of the linked parameter definition, see :class:`ansys.rep.client.jms.ParameterDefinition`. + task_definition_property (str, optional) + file_id (str, optional): ID of the file resource. """ @@ -36,7 +31,23 @@ class Meta: rest_name = "parameter_mappings" def __init__(self, **kwargs): - super(ParameterMapping, self).__init__(**kwargs) - + self.id = missing + self.line = missing + self.column = missing + self.key_string = missing + self.float_field = missing + self.width = missing + self.precision = missing + self.tokenizer = missing + self.decimal_symbol = missing + self.digit_grouping_symbol = missing + self.string_quote = missing + self.true_string = missing + self.false_string = missing + self.parameter_definition_id = missing + self.task_definition_property = missing + self.file_id = missing + + super().__init__(**kwargs) ParameterMappingSchema.Meta.object_class = ParameterMapping diff --git a/ansys/rep/client/jms/resource/project.py b/ansys/rep/client/jms/resource/project.py index 146c0fa18..76d0d19f9 100644 --- a/ansys/rep/client/jms/resource/project.py +++ b/ansys/rep/client/jms/resource/project.py @@ -1,68 +1,37 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from cachetools import TTLCache, cached from marshmallow.utils import missing -import requests - -from ansys.rep.client.exceptions import REPError - -from ..schema.project import ProjectSchema from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.project import ProjectSchema class Project(Object): - """Project resource - - Args: - **kwargs: Arbitrary keyword arguments, see the Project schema below. - - Example: - - >>> proj = Project(id="demo_project", active=True, priority=10) - >>> proj = client.create_project(proj, replace=True) - - The Project schema has the following fields: - - .. jsonschema:: schemas/Project.json + """Project resource. + + Parameters: + id (str): Unique ID to access the project, specified on creation of the project. + name (str): Name of the project. + active (bool): Defines whether the project is active for evaluation. + priority (int): Priority to pick the project for evaluation. + creation_time (datetime, optional): The date and time the project was created. + modification_time (datetime, optional): The date and time the project was last modified. + file_storages (list): List of file storages defined for the project. + statistics (dict): Optional dictionary containing various project statistics. """ class Meta: schema = ProjectSchema + rest_name = "projects" def __init__(self, **kwargs): - super(Project, self).__init__(**kwargs) + self.id = missing + self.name = missing + self.active = missing + self.priority = missing + self.creation_time = missing + self.modification_time = missing + self.file_storages = missing + self.statistics = missing + super().__init__(**kwargs) ProjectSchema.Meta.object_class = Project - - -@cached(cache=TTLCache(1024, 60), key=lambda project: project.id) -def get_fs_url(project: Project): - if project.file_storages == missing: - raise REPError(f"The project object has no file storages information.") - rest_gateways = [fs for fs in project.file_storages if fs["obj_type"] == "RestGateway"] - rest_gateways.sort(key=lambda fs: fs["priority"], reverse=True) - - if not rest_gateways: - raise REPError(f"Project {project.name} (id={project.id}) has no Rest Gateway defined.") - - for d in rest_gateways: - url = d["url"] - try: - r = requests.get(url, verify=False, timeout=2) - except Exception as ex: - log.debug(ex) - continue - if r.status_code == 200: - return url - return None diff --git a/ansys/rep/client/jms/resource/project_permission.py b/ansys/rep/client/jms/resource/project_permission.py index dee6da352..013f9c2be 100644 --- a/ansys/rep/client/jms/resource/project_permission.py +++ b/ansys/rep/client/jms/resource/project_permission.py @@ -1,39 +1,29 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): F.Negri -# ---------------------------------------------------------- -import json -import logging -from ..schema.project_permission import ProjectPermissionSchema +from marshmallow.utils import missing from .base import Object +from ..schema.project_permission import ProjectPermissionSchema -log = logging.getLogger(__name__) +class ProjectPermission(Object): + """ProjectPermission resource. + Parameters: + permission_type (str) + value_id (str) + value_name (str, optional) + role (str) + + """ -class ProjectPermission(Object): class Meta: schema = ProjectPermissionSchema rest_name = "permissions" def __init__(self, **kwargs): - super(ProjectPermission, self).__init__(**kwargs) + self.permission_type = missing + self.value_id = missing + self.value_name = missing + self.role = missing + super().__init__(**kwargs) ProjectPermissionSchema.Meta.object_class = ProjectPermission - - -def update_permissions(client, project_api_url, permissions): - - if not permissions: - return - - url = f"{project_api_url}/permissions" - - schema = ProjectPermissionSchema(many=True) - serialized_data = schema.dump(permissions) - json_data = json.dumps({"permissions": serialized_data}) - r = client.session.put(f"{url}", data=json_data) diff --git a/ansys/rep/client/jms/resource/resource_requirements.py b/ansys/rep/client/jms/resource/resource_requirements.py new file mode 100644 index 000000000..801c4197b --- /dev/null +++ b/ansys/rep/client/jms/resource/resource_requirements.py @@ -0,0 +1,31 @@ + +from marshmallow.utils import missing +from .base import Object +from ..schema.task_definition import ResourceRequirementsSchema + +class ResourceRequirements(Object): + """ResourceRequirements resource. + + Parameters: + platform (str, optional) + memory (int, optional) + cpu_core_usage (float, optional) + disk_space (int, optional) + custom (dict, optional) + + """ + + class Meta: + schema = ResourceRequirementsSchema + rest_name = "None" + + def __init__(self, **kwargs): + self.platform = missing + self.memory = missing + self.cpu_core_usage = missing + self.disk_space = missing + self.custom = missing + + super().__init__(**kwargs) + +ResourceRequirementsSchema.Meta.object_class = ResourceRequirements diff --git a/ansys/rep/client/jms/resource/selection.py b/ansys/rep/client/jms/resource/selection.py index 06fcf25e1..45029ad8b 100644 --- a/ansys/rep/client/jms/resource/selection.py +++ b/ansys/rep/client/jms/resource/selection.py @@ -1,31 +1,18 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.selection import JobSelectionSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.selection import JobSelectionSchema class JobSelection(Object): """JobSelection resource. - Args: - **kwargs: Arbitrary keyword arguments, see the Selection schema below. - - Example: - - >>> sel = JobSelection(name="selection_0", jobs=[1,2,15,28,45]) - - The JobSelection schema has the following fields: - - .. jsonschema:: schemas/JobSelection.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str): Name of the selection. + creation_time (datetime, optional): The date and time the selection was created. + modification_time (datetime, optional): The date and time the selection was last modified. + algorithm_id (str, optional): ID of the :class:`ansys.rep.client.jms.Algorithm` the selection belongs to (optional). + jobs (list): List of design point IDs. """ @@ -34,7 +21,13 @@ class Meta: rest_name = "job_selections" def __init__(self, **kwargs): - super(JobSelection, self).__init__(**kwargs) - + self.id = missing + self.name = missing + self.creation_time = missing + self.modification_time = missing + self.algorithm_id = missing + self.jobs = missing + + super().__init__(**kwargs) JobSelectionSchema.Meta.object_class = JobSelection diff --git a/ansys/rep/client/jms/resource/software.py b/ansys/rep/client/jms/resource/software.py new file mode 100644 index 000000000..6b11c937b --- /dev/null +++ b/ansys/rep/client/jms/resource/software.py @@ -0,0 +1,25 @@ + +from marshmallow.utils import missing +from .base import Object +from ..schema.task_definition import SoftwareSchema + +class Software(Object): + """Software resource. + + Parameters: + name (str): Application's name. + version (str, optional): Application's version. + + """ + + class Meta: + schema = SoftwareSchema + rest_name = "None" + + def __init__(self, **kwargs): + self.name = missing + self.version = missing + + super().__init__(**kwargs) + +SoftwareSchema.Meta.object_class = Software diff --git a/ansys/rep/client/jms/resource/string_parameter_definition.py b/ansys/rep/client/jms/resource/string_parameter_definition.py new file mode 100644 index 000000000..0db0f2936 --- /dev/null +++ b/ansys/rep/client/jms/resource/string_parameter_definition.py @@ -0,0 +1,39 @@ + +from marshmallow.utils import missing +from .parameter_definition import ParameterDefinition +from ..schema.parameter_definition import StringParameterDefinitionSchema + +class StringParameterDefinition(ParameterDefinition): + """StringParameterDefinition resource. + + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name (ID) of the parameter. + quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. + units (str, optional): Units for the parameter. + display_text (str, optional): Text to display as the parameter name. + mode (str): Indicates whether it's an input or output parameter. Filled server side. + type + default (str, optional): Default parameter value. + value_list (list, optional): A list of allowed values. + + """ + + class Meta: + schema = StringParameterDefinitionSchema + rest_name = "parameter_definitions" + + def __init__(self, **kwargs): + self.id = missing + self.name = missing + self.quantity_name = missing + self.units = missing + self.display_text = missing + self.mode = missing + self.type = missing + self.default = missing + self.value_list = missing + + super().__init__(**kwargs) + +StringParameterDefinitionSchema.Meta.object_class = StringParameterDefinition diff --git a/ansys/rep/client/jms/resource/success_criteria.py b/ansys/rep/client/jms/resource/success_criteria.py new file mode 100644 index 000000000..bb4f45d56 --- /dev/null +++ b/ansys/rep/client/jms/resource/success_criteria.py @@ -0,0 +1,33 @@ + +from marshmallow.utils import missing +from .base import Object +from ..schema.task_definition import SuccessCriteriaSchema + +class SuccessCriteria(Object): + """SuccessCriteria resource. + + Parameters: + return_code (int, optional): The process exit code that must be returned by the executed command. + expressions (list, optional): A list of expressions to be evaluated. + required_output_file_ids (list, optional): List of IDs of required output files. + require_all_output_files (bool, optional): Flag to require all output files. + required_output_parameter_ids (list, optional): List of names of required output parameters. + require_all_output_parameters (bool, optional): Flag to require all output parameters. + + """ + + class Meta: + schema = SuccessCriteriaSchema + rest_name = "None" + + def __init__(self, **kwargs): + self.return_code = missing + self.expressions = missing + self.required_output_file_ids = missing + self.require_all_output_files = missing + self.required_output_parameter_ids = missing + self.require_all_output_parameters = missing + + super().__init__(**kwargs) + +SuccessCriteriaSchema.Meta.object_class = SuccessCriteria diff --git a/ansys/rep/client/jms/resource/task.py b/ansys/rep/client/jms/resource/task.py index b3bce0974..c1e3e3fc8 100644 --- a/ansys/rep/client/jms/resource/task.py +++ b/ansys/rep/client/jms/resource/task.py @@ -1,27 +1,30 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): F.Negri -# ---------------------------------------------------------- -import logging -from ..schema.task import TaskSchema +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - +from ..schema.task import TaskSchema class Task(Object): """Task resource. - Args: - **kwargs: Arbitrary keyword arguments, see the Task schema below. - - The Task schema has the following fields: - - .. jsonschema:: schemas/Task.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + modification_time (datetime, optional): The date and time the task was last modified. + creation_time (datetime, optional): The date and time the task was created. + pending_time (datetime, optional): The date and time the task was set to pending. + prolog_time (datetime, optional): The date and time the task was set to prolog. + running_time (datetime, optional): The date and time the task was set to running. + finished_time (datetime, optional): The date and time the task was completed. + eval_status (str, optional): Evaluation status. + trial_number (int, optional): Which attempt to execute the process step this task represent. + elapsed_time (float, optional): Number of seconds it took the evaluator to execute the task. + task_definition_id (str): ('ID of the :class:`ansys.rep.client.jms.TaskDefinition` the task is linked to.',) + task_definition_snapshot (optional): Snapshot of :class:`ansys.rep.client.jms.TaskDefinition` created when task status changes to prolog, before evaluation. + job_id (str): ID of the :class:`ansys.rep.client.jms.Job` the task is linked to. + evaluator_id (str, optional): UUID of the :class:`ansys.rep.client.jms.Evaluator` that updated the task. + input_file_ids (list): List of IDs of input files of task. + output_file_ids (list): List of IDs of output files of task. + inherited_file_ids (list): List of IDs of inherited files of task. + owned_file_ids (list): List of IDs of owned files of task. """ @@ -30,7 +33,25 @@ class Meta: rest_name = "tasks" def __init__(self, **kwargs): - super(Task, self).__init__(**kwargs) - + self.id = missing + self.modification_time = missing + self.creation_time = missing + self.pending_time = missing + self.prolog_time = missing + self.running_time = missing + self.finished_time = missing + self.eval_status = missing + self.trial_number = missing + self.elapsed_time = missing + self.task_definition_id = missing + self.task_definition_snapshot = missing + self.job_id = missing + self.evaluator_id = missing + self.input_file_ids = missing + self.output_file_ids = missing + self.inherited_file_ids = missing + self.owned_file_ids = missing + + super().__init__(**kwargs) TaskSchema.Meta.object_class = Task diff --git a/ansys/rep/client/jms/resource/task_definition.py b/ansys/rep/client/jms/resource/task_definition.py index b01d892f7..0c5f156b3 100644 --- a/ansys/rep/client/jms/resource/task_definition.py +++ b/ansys/rep/client/jms/resource/task_definition.py @@ -1,171 +1,29 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): O.Koenig -# ---------------------------------------------------------- -import logging -from ..schema.task_definition import ( - LicensingSchema, - ResourceRequirementsSchema, - SoftwareSchema, - SuccessCriteriaSchema, - TaskDefinitionSchema, -) +from marshmallow.utils import missing from .base import Object - -log = logging.getLogger(__name__) - - -class Software(Object): - """Software resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the Software schema below. - - Example: - - >>> software = Software( - name="ANSYS Mechanical APDL" - version="2022 R2" - ) - >>> task_definition.software_requirements.append(software) - - The Software schema has the following fields: - - .. jsonschema:: schemas/Software.json - - """ - - class Meta: - schema = SoftwareSchema - - def __init__(self, **kwargs): - super(Software, self).__init__(**kwargs) - - -SoftwareSchema.Meta.object_class = Software - - -class ResourceRequirements(Object): - """Compute Resource Requirements. - - Args: - **kwargs: Arbitrary keyword arguments, see the ResourceRequirements schema below. - - Example: - - >>> reqs = ResourceRequirements( - cpu_core_usage=12.0, - memory=250, - disk_space=50, - ) - >>> task_definition.resource_requirements = reqs - - The ResourceRequirements schema has the following fields: - - .. jsonschema:: schemas/ResourceRequirements.json - - """ - - class Meta: - schema = ResourceRequirementsSchema - - def __init__(self, **kwargs): - super(ResourceRequirements, self).__init__(**kwargs) - - -ResourceRequirementsSchema.Meta.object_class = ResourceRequirements - - -class SuccessCriteria(Object): - """SuccessCriteria resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the SuccessCriteria schema below. - - Example: - - >>> sc = SuccessCriteria( - return_code=0, - expressions= ["values['tube1_radius']>=4.0", "values['tube1_thickness']>=0.5"], - required_output_file_ids=[ f.id for f in files[2:] ], - require_all_output_files=False, - required_output_parameter_ids=[...], - require_all_output_parameters=False - ) - - The SuccessCriteria schema has the following fields: - - .. jsonschema:: schemas/SuccessCriteria.json - - """ - - class Meta: - schema = SuccessCriteriaSchema - - def __init__(self, **kwargs): - super(SuccessCriteria, self).__init__(**kwargs) - - -SuccessCriteriaSchema.Meta.object_class = SuccessCriteria - - -class Licensing(Object): - """Licensing resource. - - Args: - **kwargs: Arbitrary keyword arguments, see the Licensing schema below. - - Example: - - >>> lic = Licensing(enable_shared_licensing=true) - - The Licensing schema has the following fields: - - .. jsonschema:: schemas/Licensing.json - - """ - - class Meta: - schema = LicensingSchema - - def __init__(self, **kwargs): - super(Licensing, self).__init__(**kwargs) - - -LicensingSchema.Meta.object_class = Licensing - +from ..schema.task_definition import TaskDefinitionSchema class TaskDefinition(Object): """TaskDefinition resource. - Args: - **kwargs: Arbitrary keyword arguments, see the TaskDefinition schema below. - - Example: - - >>> td = TaskDefinition( - name="MAPDL_run", - software_requirements=[ - Software(name="ANSYS Mechanical APDL", version="2022 R2"), - ], - execution_command="%executable% -b -i %file:mac% - -o file.out -np %resource:num_cores%", - max_execution_time=20.0, - execution_level=0, - resource_requirements=ResourceRequirements( - cpu_core_usage=1.0, - memory=250, - disk_space=5, - ) - ) - - The TaskDefinition schema has the following fields: - - .. jsonschema:: schemas/TaskDefinition.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + name (str, optional): Name. + execution_command (str, optional): Command to execute (command or execution script is required). + use_execution_script (bool, optional): Whether to run task with the execution command or the execution script. + execution_script_id (str, optional): Script to execute (command or execution script is required). + execution_level (int): Define execution level for this task. + execution_context (dict, optional): Additional arguments to pass to the executing command + environment (dict, optional): Environment variables to set for the executed process + max_execution_time (float, optional): Maximum time in seconds for executing the task. + num_trials (int, optional): Maximum number of attempts to execute the task. + store_output (bool, optional): Specify whether to store the standard output of the task. + input_file_ids (list): List of IDs of input files. + output_file_ids (list): List of IDs of output files. + success_criteria (optional): A :class:`ansys.rep.client.jms.SuccessCriteria` object. + licensing (optional): A :class:`ansys.rep.client.jms.Licensing` object. + software_requirements (optional): A list of :class:`ansys.rep.client.jms.Software` objects. + resource_requirements (optional): A :class:`ansys.rep.client.jms.ResourceRequirements` object. """ @@ -174,7 +32,24 @@ class Meta: rest_name = "task_definitions" def __init__(self, **kwargs): - super(TaskDefinition, self).__init__(**kwargs) - + self.id = missing + self.name = missing + self.execution_command = missing + self.use_execution_script = missing + self.execution_script_id = missing + self.execution_level = missing + self.execution_context = missing + self.environment = missing + self.max_execution_time = missing + self.num_trials = missing + self.store_output = missing + self.input_file_ids = missing + self.output_file_ids = missing + self.success_criteria = missing + self.licensing = missing + self.software_requirements = missing + self.resource_requirements = missing + + super().__init__(**kwargs) TaskDefinitionSchema.Meta.object_class = TaskDefinition diff --git a/ansys/rep/client/jms/resource/task_definition_template.py b/ansys/rep/client/jms/resource/task_definition_template.py index 76d5b925e..350fa9166 100644 --- a/ansys/rep/client/jms/resource/task_definition_template.py +++ b/ansys/rep/client/jms/resource/task_definition_template.py @@ -1,47 +1,26 @@ -# ---------------------------------------------------------- -# Copyright (C) 2021 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): F.Negri -# ---------------------------------------------------------- -from ..schema.task_definition_template import TaskDefinitionTemplateSchema +from marshmallow.utils import missing from .base import Object - +from ..schema.task_definition_template import TaskDefinitionTemplateSchema class TaskDefinitionTemplate(Object): """TaskDefinitionTemplate resource. - Args: - **kwargs: Arbitrary keyword arguments, see the TaskDefinitionTemplate schema below. - - Example: - - >>> template = TaskDefinitionTemplate( - name="MAPDL_run", - application_name="ANSYS Mechanical APDL", - application_version="2022 R2", - data = { - "execution_command": "%executable% -b - -i %file:mac% -o file.out - -np %resource:num_cores%", - "output_files": [ - { - "name": "out", - "obj_type": "File", - "evaluation_path": "solve.out", - "type": "text/plain", - "collect": true, - "monitor": true - } - ] - } - ) - - The TaskDefinitionTemplate schema has the following fields: - - .. jsonschema:: schemas/TaskDefinitionTemplate.json + Parameters: + id (str, optional): Unique ID to access the resource, generated internally by the server on creation. + modification_time (datetime, optional): Last time the object was modified, in UTC + creation_time (datetime, optional): Time when the object was created, in UTC + name (str): Name of the template + version (str, optional): version of the template + software_requirements (optional) + resource_requirements (optional) + execution_context (dict, optional): Additional arguments to pass to the executing command + environment (dict, optional): Environment variables to set for the executed process + execution_command (str, optional): Command to execute (command or execution script is required). + use_execution_script (bool, optional): Whether to run task with the execution command or the execution script. + execution_script_storage_id (str, optional): Storage ID of the script to execute (command or execution script is required). + input_files (optional) + output_files (optional) """ @@ -50,7 +29,21 @@ class Meta: rest_name = "task_definition_templates" def __init__(self, **kwargs): - super(TaskDefinitionTemplate, self).__init__(**kwargs) - + self.id = missing + self.modification_time = missing + self.creation_time = missing + self.name = missing + self.version = missing + self.software_requirements = missing + self.resource_requirements = missing + self.execution_context = missing + self.environment = missing + self.execution_command = missing + self.use_execution_script = missing + self.execution_script_storage_id = missing + self.input_files = missing + self.output_files = missing + + super().__init__(**kwargs) TaskDefinitionTemplateSchema.Meta.object_class = TaskDefinitionTemplate diff --git a/generate_resources.py b/generate_resources.py index e27bb9263..599a7eaba 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -1,3 +1,9 @@ +""" +Script to auto generate (most of the) JMS Resources. +Main aim is to auto-generate the class docstrings and +allows code completion (intellisense). +""" + import importlib import os @@ -5,6 +11,11 @@ from ansys.rep.client.jms.schema.object_reference import IdReference, IdReferenceList +parameter_definition_base_class = { + "name": "ParameterDefinition", + "file_name": "parameter_definition", +} + resources = [ { "schema": "AlgorithmSchema", @@ -30,6 +41,22 @@ "class": "FileBase", "resource_filename": "file_base", }, + { + "schema": "FitnessDefinitionSchema", + "schema_filename": "fitness_definition", + "rest_name": None, + "additional_fields": [], + "class": "FitnessDefinitionBase", + "resource_filename": "fitness_definition_base", + }, + { + "schema": "FitnessTermDefinitionSchema", + "schema_filename": "fitness_definition", + "rest_name": None, + "additional_fields": [], + "class": "FitnessTermDefinitionBase", + "resource_filename": "fitness_term_definition_base", + }, { "schema": "JobSchema", "schema_filename": "job", @@ -94,6 +121,30 @@ "class": "ResourceRequirements", "resource_filename": "resource_requirements", }, + { + "schema": "SoftwareSchema", + "schema_filename": "task_definition", + "rest_name": None, + "additional_fields": [], + "class": "Software", + "resource_filename": "software", + }, + { + "schema": "SuccessCriteriaSchema", + "schema_filename": "task_definition", + "rest_name": None, + "additional_fields": [], + "class": "SuccessCriteria", + "resource_filename": "success_criteria", + }, + { + "schema": "LicensingSchema", + "schema_filename": "task_definition", + "rest_name": None, + "additional_fields": [], + "class": "Licensing", + "resource_filename": "licensing", + }, { "schema": "JobSelectionSchema", "schema_filename": "selection", @@ -110,6 +161,14 @@ "class": "TaskDefinitionTemplate", "resource_filename": "task_definition_template", }, + { + "schema": "TaskDefinitionSchema", + "schema_filename": "task_definition", + "rest_name": "task_definitions", + "additional_fields": [], + "class": "TaskDefinition", + "resource_filename": "task_definition", + }, { "schema": "TaskSchema", "schema_filename": "task", @@ -118,6 +177,50 @@ "class": "Task", "resource_filename": "task", }, + { + "schema": "ParameterDefinitionSchema", + "schema_filename": "parameter_definition", + "rest_name": "parameter_definitions", + "additional_fields": [], + "class": "ParameterDefinition", + "resource_filename": "parameter_definition", + }, + { + "schema": "FloatParameterDefinitionSchema", + "schema_filename": "parameter_definition", + "rest_name": "parameter_definitions", + "additional_fields": [], + "base_class": "ParameterDefinition", + "class": "FloatParameterDefinition", + "resource_filename": "float_parameter_definition", + }, + { + "schema": "IntParameterDefinitionSchema", + "schema_filename": "parameter_definition", + "rest_name": "parameter_definitions", + "additional_fields": [], + "base_class": "ParameterDefinition", + "class": "IntParameterDefinition", + "resource_filename": "int_parameter_definition", + }, + { + "schema": "BoolParameterDefinitionSchema", + "schema_filename": "parameter_definition", + "rest_name": "parameter_definitions", + "additional_fields": [], + "base_class": "ParameterDefinition", + "class": "BoolParameterDefinition", + "resource_filename": "bool_parameter_definition", + }, + { + "schema": "StringParameterDefinitionSchema", + "schema_filename": "parameter_definition", + "rest_name": "parameter_definitions", + "additional_fields": [], + "base_class": "ParameterDefinition", + "class": "StringParameterDefinition", + "resource_filename": "string_parameter_definition", + }, ] FIELD_MAPPING = { @@ -163,14 +266,16 @@ def declared_fields(schema): return fields, fields_doc -def get_generated_code(resource, fields, field_docs): +def get_generated_code(resource, base_class, fields, field_docs): + + base_class_import = f"from .{base_class['filename']} import {base_class['name']}" code = f''' from marshmallow.utils import missing -from .base import Object +{base_class_import} from ..schema.{resource['schema_filename']} import {resource['schema']} -class {resource['class']}(Object): +class {resource['class']}({base_class["name"]}): """{resource['class']} resource. Parameters: @@ -211,7 +316,14 @@ def __init__(self, **kwargs): print(f"Attributes:\n{field_docs_str}") - code = get_generated_code(resource, fields_str, field_docs_str) + base_class = {"name": "Object", "filename": "base"} + if resource.get("base_class", None): + base_class["name"] = resource["base_class"] + base_class["filename"] = next( + (r["resource_filename"] for r in resources if r["class"] == resource["base_class"]), + None, + ) + code = get_generated_code(resource, base_class, fields_str, field_docs_str) file_path = os.path.join(targe_folder, f"{resource['resource_filename']}.py") with open(file_path, "w") as file: diff --git a/tests/jms/test_parameter_definitions.py b/tests/jms/test_parameter_definitions.py index 332077392..428329ae3 100644 --- a/tests/jms/test_parameter_definitions.py +++ b/tests/jms/test_parameter_definitions.py @@ -11,11 +11,12 @@ from marshmallow.utils import missing from ansys.rep.client.jms import JmsApi, ProjectApi -from ansys.rep.client.jms.resource import JobDefinition, Project -from ansys.rep.client.jms.resource.parameter_definition import ( +from ansys.rep.client.jms.resource import ( BoolParameterDefinition, FloatParameterDefinition, IntParameterDefinition, + JobDefinition, + Project, StringParameterDefinition, ) from ansys.rep.client.jms.schema.parameter_definition import ( From 140f10a321aa5ac900b23156a961074f406ff555 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 17:55:28 +0200 Subject: [PATCH 07/13] Clean up --- ansys/rep/client/jms/resource/algorithm.py | 3 +- .../jms/resource/bool_parameter_definition.py | 1 + ansys/rep/client/jms/resource/evaluator.py | 1 + .../resource/float_parameter_definition.py | 1 + .../jms/resource/int_parameter_definition.py | 1 + ansys/rep/client/jms/resource/job.py | 3 +- .../rep/client/jms/resource/job_definition.py | 7 +- .../client/jms/resource/license_context.py | 1 + ansys/rep/client/jms/resource/licensing.py | 1 + ansys/rep/client/jms/resource/operation.py | 1 + .../jms/resource/parameter_definition.py | 1 + .../client/jms/resource/parameter_mapping.py | 1 + ansys/rep/client/jms/resource/project.py | 1 + .../client/jms/resource/project_permission.py | 1 + .../jms/resource/resource_requirements.py | 1 + ansys/rep/client/jms/resource/selection.py | 3 +- ansys/rep/client/jms/resource/software.py | 1 + .../resource/string_parameter_definition.py | 1 + .../client/jms/resource/success_criteria.py | 5 +- ansys/rep/client/jms/resource/task.py | 9 ++- .../client/jms/resource/task_definition.py | 5 +- .../jms/resource/task_definition_template.py | 1 + doc/source/changelog/index.rst | 7 -- doc/source/index_templ.rst | 6 -- generate_resources.py | 79 +++++++++++-------- 25 files changed, 83 insertions(+), 59 deletions(-) delete mode 100644 doc/source/changelog/index.rst delete mode 100644 doc/source/index_templ.rst diff --git a/ansys/rep/client/jms/resource/algorithm.py b/ansys/rep/client/jms/resource/algorithm.py index 4970040dd..9d23a916b 100644 --- a/ansys/rep/client/jms/resource/algorithm.py +++ b/ansys/rep/client/jms/resource/algorithm.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on AlgorithmSchema from marshmallow.utils import missing from .base import Object @@ -13,7 +14,7 @@ class Algorithm(Object): creation_time (datetime, optional): The date and time the algorithm was created. modification_time (datetime, optional): The date and time the algorithm was last modified. data (str, optional): Generic string field to hold arbitrary algorithm job_definition data, e.g. as JSON dictionary. - jobs (list): List of design point IDs. + jobs (list[str]): List of design point IDs. """ diff --git a/ansys/rep/client/jms/resource/bool_parameter_definition.py b/ansys/rep/client/jms/resource/bool_parameter_definition.py index 875e639e1..7480c09e3 100644 --- a/ansys/rep/client/jms/resource/bool_parameter_definition.py +++ b/ansys/rep/client/jms/resource/bool_parameter_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on BoolParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/evaluator.py b/ansys/rep/client/jms/resource/evaluator.py index 54065106d..fbc876583 100644 --- a/ansys/rep/client/jms/resource/evaluator.py +++ b/ansys/rep/client/jms/resource/evaluator.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on EvaluatorSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/float_parameter_definition.py b/ansys/rep/client/jms/resource/float_parameter_definition.py index 5d768014a..3d010b886 100644 --- a/ansys/rep/client/jms/resource/float_parameter_definition.py +++ b/ansys/rep/client/jms/resource/float_parameter_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on FloatParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/int_parameter_definition.py b/ansys/rep/client/jms/resource/int_parameter_definition.py index aa97133b6..c75441c5e 100644 --- a/ansys/rep/client/jms/resource/int_parameter_definition.py +++ b/ansys/rep/client/jms/resource/int_parameter_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on IntParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/job.py b/ansys/rep/client/jms/resource/job.py index 906a6c1d6..e51ea1828 100644 --- a/ansys/rep/client/jms/resource/job.py +++ b/ansys/rep/client/jms/resource/job.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on JobSchema from marshmallow.utils import missing from .base import Object @@ -22,7 +23,7 @@ class Job(Object): modification_time (datetime, optional): The date and time the design point was last modified. elapsed_time (float): Number of seconds it took the evaluator(s) to update the design point. evaluators (list, optional): List of UUID strings of the evaluators that updated the design point. - file_ids (list): List of IDs of all files of this design point. + file_ids (list[str]): List of IDs of all files of this design point. """ diff --git a/ansys/rep/client/jms/resource/job_definition.py b/ansys/rep/client/jms/resource/job_definition.py index af19c3c73..3794ab16e 100644 --- a/ansys/rep/client/jms/resource/job_definition.py +++ b/ansys/rep/client/jms/resource/job_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on JobDefinitionSchema from marshmallow.utils import missing from .base import Object @@ -12,9 +13,9 @@ class JobDefinition(Object): active (bool): Defines whether this is the active job_definition in the project where evaluators will evaluate pending design points creation_time (datetime, optional): The date and time the job_definition was created. modification_time (datetime, optional): The date and time the job_definition was last modified. - parameter_definition_ids (list) - parameter_mapping_ids (list) - task_definition_ids (list) + parameter_definition_ids (list[str]) + parameter_mapping_ids (list[str]) + task_definition_ids (list[str]) fitness_definition (optional): An :class:`ansys.rep.client.jms.FitnessDefinition` object. """ diff --git a/ansys/rep/client/jms/resource/license_context.py b/ansys/rep/client/jms/resource/license_context.py index f921f89ec..681d06e26 100644 --- a/ansys/rep/client/jms/resource/license_context.py +++ b/ansys/rep/client/jms/resource/license_context.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on LicenseContextSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/licensing.py b/ansys/rep/client/jms/resource/licensing.py index 8144a9a10..f146d2659 100644 --- a/ansys/rep/client/jms/resource/licensing.py +++ b/ansys/rep/client/jms/resource/licensing.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on LicensingSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/operation.py b/ansys/rep/client/jms/resource/operation.py index 72e0266d3..0785c11b3 100644 --- a/ansys/rep/client/jms/resource/operation.py +++ b/ansys/rep/client/jms/resource/operation.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on OperationSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/parameter_definition.py b/ansys/rep/client/jms/resource/parameter_definition.py index 3fa644bc4..ecbc48f29 100644 --- a/ansys/rep/client/jms/resource/parameter_definition.py +++ b/ansys/rep/client/jms/resource/parameter_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on ParameterDefinitionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/parameter_mapping.py b/ansys/rep/client/jms/resource/parameter_mapping.py index 6aec5ec07..603849a27 100644 --- a/ansys/rep/client/jms/resource/parameter_mapping.py +++ b/ansys/rep/client/jms/resource/parameter_mapping.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on ParameterMappingSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/project.py b/ansys/rep/client/jms/resource/project.py index 76d0d19f9..b4f4acc60 100644 --- a/ansys/rep/client/jms/resource/project.py +++ b/ansys/rep/client/jms/resource/project.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on ProjectSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/project_permission.py b/ansys/rep/client/jms/resource/project_permission.py index 013f9c2be..a42bc6c4b 100644 --- a/ansys/rep/client/jms/resource/project_permission.py +++ b/ansys/rep/client/jms/resource/project_permission.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on ProjectPermissionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/resource_requirements.py b/ansys/rep/client/jms/resource/resource_requirements.py index 801c4197b..42dd1a3ab 100644 --- a/ansys/rep/client/jms/resource/resource_requirements.py +++ b/ansys/rep/client/jms/resource/resource_requirements.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on ResourceRequirementsSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/selection.py b/ansys/rep/client/jms/resource/selection.py index 45029ad8b..0d2320523 100644 --- a/ansys/rep/client/jms/resource/selection.py +++ b/ansys/rep/client/jms/resource/selection.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on JobSelectionSchema from marshmallow.utils import missing from .base import Object @@ -12,7 +13,7 @@ class JobSelection(Object): creation_time (datetime, optional): The date and time the selection was created. modification_time (datetime, optional): The date and time the selection was last modified. algorithm_id (str, optional): ID of the :class:`ansys.rep.client.jms.Algorithm` the selection belongs to (optional). - jobs (list): List of design point IDs. + jobs (list[str]): List of design point IDs. """ diff --git a/ansys/rep/client/jms/resource/software.py b/ansys/rep/client/jms/resource/software.py index 6b11c937b..0d7f6f961 100644 --- a/ansys/rep/client/jms/resource/software.py +++ b/ansys/rep/client/jms/resource/software.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on SoftwareSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/string_parameter_definition.py b/ansys/rep/client/jms/resource/string_parameter_definition.py index 0db0f2936..6a5b2acd3 100644 --- a/ansys/rep/client/jms/resource/string_parameter_definition.py +++ b/ansys/rep/client/jms/resource/string_parameter_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on StringParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/success_criteria.py b/ansys/rep/client/jms/resource/success_criteria.py index bb4f45d56..21cb8d87e 100644 --- a/ansys/rep/client/jms/resource/success_criteria.py +++ b/ansys/rep/client/jms/resource/success_criteria.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on SuccessCriteriaSchema from marshmallow.utils import missing from .base import Object @@ -9,9 +10,9 @@ class SuccessCriteria(Object): Parameters: return_code (int, optional): The process exit code that must be returned by the executed command. expressions (list, optional): A list of expressions to be evaluated. - required_output_file_ids (list, optional): List of IDs of required output files. + required_output_file_ids (list[str], optional): List of IDs of required output files. require_all_output_files (bool, optional): Flag to require all output files. - required_output_parameter_ids (list, optional): List of names of required output parameters. + required_output_parameter_ids (list[str], optional): List of names of required output parameters. require_all_output_parameters (bool, optional): Flag to require all output parameters. """ diff --git a/ansys/rep/client/jms/resource/task.py b/ansys/rep/client/jms/resource/task.py index c1e3e3fc8..706bd58f0 100644 --- a/ansys/rep/client/jms/resource/task.py +++ b/ansys/rep/client/jms/resource/task.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on TaskSchema from marshmallow.utils import missing from .base import Object @@ -21,10 +22,10 @@ class Task(Object): task_definition_snapshot (optional): Snapshot of :class:`ansys.rep.client.jms.TaskDefinition` created when task status changes to prolog, before evaluation. job_id (str): ID of the :class:`ansys.rep.client.jms.Job` the task is linked to. evaluator_id (str, optional): UUID of the :class:`ansys.rep.client.jms.Evaluator` that updated the task. - input_file_ids (list): List of IDs of input files of task. - output_file_ids (list): List of IDs of output files of task. - inherited_file_ids (list): List of IDs of inherited files of task. - owned_file_ids (list): List of IDs of owned files of task. + input_file_ids (list[str]): List of IDs of input files of task. + output_file_ids (list[str]): List of IDs of output files of task. + inherited_file_ids (list[str]): List of IDs of inherited files of task. + owned_file_ids (list[str]): List of IDs of owned files of task. """ diff --git a/ansys/rep/client/jms/resource/task_definition.py b/ansys/rep/client/jms/resource/task_definition.py index 0c5f156b3..8d44dcdf7 100644 --- a/ansys/rep/client/jms/resource/task_definition.py +++ b/ansys/rep/client/jms/resource/task_definition.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on TaskDefinitionSchema from marshmallow.utils import missing from .base import Object @@ -18,8 +19,8 @@ class TaskDefinition(Object): max_execution_time (float, optional): Maximum time in seconds for executing the task. num_trials (int, optional): Maximum number of attempts to execute the task. store_output (bool, optional): Specify whether to store the standard output of the task. - input_file_ids (list): List of IDs of input files. - output_file_ids (list): List of IDs of output files. + input_file_ids (list[str]): List of IDs of input files. + output_file_ids (list[str]): List of IDs of output files. success_criteria (optional): A :class:`ansys.rep.client.jms.SuccessCriteria` object. licensing (optional): A :class:`ansys.rep.client.jms.Licensing` object. software_requirements (optional): A list of :class:`ansys.rep.client.jms.Software` objects. diff --git a/ansys/rep/client/jms/resource/task_definition_template.py b/ansys/rep/client/jms/resource/task_definition_template.py index 350fa9166..2e761eacb 100644 --- a/ansys/rep/client/jms/resource/task_definition_template.py +++ b/ansys/rep/client/jms/resource/task_definition_template.py @@ -1,3 +1,4 @@ +# autogenerated on 2022-09-01 17:37 based on TaskDefinitionTemplateSchema from marshmallow.utils import missing from .base import Object diff --git a/doc/source/changelog/index.rst b/doc/source/changelog/index.rst deleted file mode 100644 index c204b69ea..000000000 --- a/doc/source/changelog/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _changelog: - -Changelog -========= - -.. toctree:: - :maxdepth: 1 \ No newline at end of file diff --git a/doc/source/index_templ.rst b/doc/source/index_templ.rst deleted file mode 100644 index d2824a5f6..000000000 --- a/doc/source/index_templ.rst +++ /dev/null @@ -1,6 +0,0 @@ -.. - Just reuse the root readme to avoid duplicating the documentation. - Provide any documentation specific to your online documentation - here. - -.. include:: ../../README.rst diff --git a/generate_resources.py b/generate_resources.py index 599a7eaba..5d4ac6be0 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -4,6 +4,7 @@ allows code completion (intellisense). """ +from datetime import datetime import importlib import os @@ -11,12 +12,10 @@ from ansys.rep.client.jms.schema.object_reference import IdReference, IdReferenceList -parameter_definition_base_class = { - "name": "ParameterDefinition", - "file_name": "parameter_definition", -} - -resources = [ +# we define here which resources to auto-generate +# some are excluded or done only partially (e.g. File) +# because they require more customization +RESOURCES = [ { "schema": "AlgorithmSchema", "schema_filename": "algorithm", @@ -223,6 +222,7 @@ }, ] +# mapping of marshmallow field types to doc types FIELD_MAPPING = { marshmallow.fields.Integer: "int", marshmallow.fields.Float: "float", @@ -231,7 +231,7 @@ marshmallow.fields.DateTime: "datetime", marshmallow.fields.Dict: "dict", marshmallow.fields.List: "list", - IdReferenceList: "list", + IdReferenceList: "list[str]", IdReference: "str", } @@ -270,7 +270,8 @@ def get_generated_code(resource, base_class, fields, field_docs): base_class_import = f"from .{base_class['filename']} import {base_class['name']}" - code = f''' + code = f'''# autogenerated on {datetime.now().strftime("%Y-%m-%d %H:%M")} based on {resource["schema"]} + from marshmallow.utils import missing {base_class_import} from ..schema.{resource['schema_filename']} import {resource['schema']} @@ -295,36 +296,50 @@ def __init__(self, **kwargs): return code -targe_folder = os.path.join("ansys", "rep", "client", "jms", "resource") +def run(): + + targe_folder = os.path.join("ansys", "rep", "client", "jms", "resource") -for resource in resources: + for resource in RESOURCES: + print(f"Processing resource {resource['class']}") - print(f"Processing resource {resource['class']}") + # dynamically load resource schema + module = importlib.import_module( + f"ansys.rep.client.jms.schema.{resource['schema_filename']}" + ) + resource_class = getattr(module, resource["schema"]) - module = importlib.import_module(f"ansys.rep.client.jms.schema.{resource['schema_filename']}") - resource_class = getattr(module, resource["schema"]) + # query schema field names and doc + fields, field_docs = declared_fields(resource_class) - fields, field_docs = declared_fields(resource_class) + fields_str = "" + for k in fields: + fields_str += f" self.{k} = missing\n" - fields_str = "" - for k in fields: - fields_str += f" self.{k} = missing\n" + field_docs_str = "" + for k in field_docs: + field_docs_str += f" {k}\n" - field_docs_str = "" - for k in field_docs: - field_docs_str += f" {k}\n" + print(f"Class init parameters:\n{field_docs_str}") - print(f"Attributes:\n{field_docs_str}") + # if a base class other than Object need to be used, + # we need to make sure to properly import it in the generated code + base_class = {"name": "Object", "filename": "base"} + if resource.get("base_class", None): + base_class["name"] = resource["base_class"] + base_class["filename"] = next( + (r["resource_filename"] for r in RESOURCES if r["class"] == resource["base_class"]), + None, + ) + + # we're ready to put the pieces together + code = get_generated_code(resource, base_class, fields_str, field_docs_str) + + # dump generated code to file + file_path = os.path.join(targe_folder, f"{resource['resource_filename']}.py") + with open(file_path, "w") as file: + file.write(code) - base_class = {"name": "Object", "filename": "base"} - if resource.get("base_class", None): - base_class["name"] = resource["base_class"] - base_class["filename"] = next( - (r["resource_filename"] for r in resources if r["class"] == resource["base_class"]), - None, - ) - code = get_generated_code(resource, base_class, fields_str, field_docs_str) - file_path = os.path.join(targe_folder, f"{resource['resource_filename']}.py") - with open(file_path, "w") as file: - file.write(code) +if __name__ == "__main__": + run() From dd3fd2f75979870ff0ad186f0cb0d25150172441 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 18:15:44 +0200 Subject: [PATCH 08/13] Clean auth api --- ansys/rep/client/auth/api/auth_api.py | 83 +++++++++++++++++++++++++- ansys/rep/client/auth/resource/user.py | 81 ------------------------- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/ansys/rep/client/auth/api/auth_api.py b/ansys/rep/client/auth/api/auth_api.py index ef9b9af37..0c9141c59 100644 --- a/ansys/rep/client/auth/api/auth_api.py +++ b/ansys/rep/client/auth/api/auth_api.py @@ -6,7 +6,9 @@ # Author(s): F.Negri, O.Koenig # ---------------------------------------------------------- -from ..resource.user import create_user, delete_user, get_users, update_user +from keycloak import KeycloakAdmin + +from ..schema.user import UserSchema class AuthApi: @@ -71,3 +73,82 @@ def delete_user(self, user): user (:class:`ansys.rep.client.auth.User`): A User object. Defaults to None. """ return delete_user(self.client, user) + + +def _admin_client(client): + + custom_headers = { + "Authorization": "Bearer " + client.access_token, + "Content-Type": "application/json", + } + keycloak_admin = KeycloakAdmin( + server_url=client.auth_api_url, + username=None, + password=None, + realm_name=client.realm, + client_id=client.client_id, + verify=False, + custom_headers=custom_headers, + ) + return keycloak_admin + + +def get_users(client, as_objects=True): + admin = _admin_client(client) + data = admin.get_users({}) + for d in data: + uid = d["id"] + groups = admin.get_user_groups(uid) + d["groups"] = [g["name"] for g in groups] + realm_roles = admin.get_realm_roles_of_user(uid) + d["realm_roles"] = [r["name"] for r in realm_roles] + d["is_admin"] = d # Force admin check + + schema = UserSchema(many=True) + users = schema.load(data) + return users + + +def create_user(client, user, as_objects=True): + schema = UserSchema(many=False) + data = schema.dump(user) + + pwd = data.pop("password", None) + if pwd is not None: + data["credentials"] = [ + { + "type": "password", + "value": pwd, + } + ] + data["enabled"] = True + + admin = _admin_client(client) + uid = admin.create_user(data) + data = admin.get_user(uid) + user = schema.load(data) + return user + + +def update_user(client, user, as_objects=True): + schema = UserSchema(many=False) + data = schema.dump(user) + + pwd = data.pop("password", None) + if pwd is not None: + data["credentials"] = [ + { + "type": "password", + "value": pwd, + } + ] + + admin = _admin_client(client) + data = admin.update_user(user.id, data) + user = schema.load(data) + return user + + +def delete_user(client, user): + admin = _admin_client(client) + admin.delete_user(user.id) diff --git a/ansys/rep/client/auth/resource/user.py b/ansys/rep/client/auth/resource/user.py index 2cc0d0d58..10a42d279 100644 --- a/ansys/rep/client/auth/resource/user.py +++ b/ansys/rep/client/auth/resource/user.py @@ -7,8 +7,6 @@ # ---------------------------------------------------------- import logging -from keycloak import KeycloakAdmin - from ansys.rep.client.jms.resource.base import Object from ..schema.user import UserSchema @@ -42,82 +40,3 @@ def __init__(self, **kwargs): UserSchema.Meta.object_class = User - - -def _admin_client(client): - - custom_headers = { - "Authorization": "Bearer " + client.access_token, - "Content-Type": "application/json", - } - keycloak_admin = KeycloakAdmin( - server_url=client.auth_api_url, - username=None, - password=None, - realm_name=client.realm, - client_id=client.client_id, - verify=False, - custom_headers=custom_headers, - ) - return keycloak_admin - - -def get_users(client, as_objects=True): - admin = _admin_client(client) - data = admin.get_users({}) - for d in data: - uid = d["id"] - groups = admin.get_user_groups(uid) - d["groups"] = [g["name"] for g in groups] - realm_roles = admin.get_realm_roles_of_user(uid) - d["realm_roles"] = [r["name"] for r in realm_roles] - d["is_admin"] = d # Force admin check - - schema = UserSchema(many=True) - users = schema.load(data) - return users - - -def create_user(client, user, as_objects=True): - schema = UserSchema(many=False) - data = schema.dump(user) - - pwd = data.pop("password", None) - if pwd is not None: - data["credentials"] = [ - { - "type": "password", - "value": pwd, - } - ] - data["enabled"] = True - - admin = _admin_client(client) - uid = admin.create_user(data) - data = admin.get_user(uid) - user = schema.load(data) - return user - - -def update_user(client, user, as_objects=True): - schema = UserSchema(many=False) - data = schema.dump(user) - - pwd = data.pop("password", None) - if pwd is not None: - data["credentials"] = [ - { - "type": "password", - "value": pwd, - } - ] - - admin = _admin_client(client) - data = admin.update_user(user.id, data) - user = schema.load(data) - return user - - -def delete_user(client, user): - admin = _admin_client(client) - admin.delete_user(user.id) From 2a9e44870fb660325715351b4fbb58313880762d Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 18:28:17 +0200 Subject: [PATCH 09/13] Generate auth resources --- generate_resources.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/generate_resources.py b/generate_resources.py index 5d4ac6be0..4f4c44f54 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -4,7 +4,6 @@ allows code completion (intellisense). """ -from datetime import datetime import importlib import os @@ -15,7 +14,7 @@ # we define here which resources to auto-generate # some are excluded or done only partially (e.g. File) # because they require more customization -RESOURCES = [ +JMS_RESOURCES = [ { "schema": "AlgorithmSchema", "schema_filename": "algorithm", @@ -222,6 +221,18 @@ }, ] +AUTH_RESOURCES = [ + { + "schema": "UserSchema", + "schema_filename": "user", + "rest_name": None, + "additional_fields": [], + "base_class": "Object", + "class": "User", + "resource_filename": "user", + }, +] + # mapping of marshmallow field types to doc types FIELD_MAPPING = { marshmallow.fields.Integer: "int", @@ -268,9 +279,11 @@ def declared_fields(schema): def get_generated_code(resource, base_class, fields, field_docs): - base_class_import = f"from .{base_class['filename']} import {base_class['name']}" + base_class_import = ( + f"from {base_class['path']}.{base_class['filename']} import {base_class['name']}" + ) - code = f'''# autogenerated on {datetime.now().strftime("%Y-%m-%d %H:%M")} based on {resource["schema"]} + code = f'''# autogenerated code based on {resource["schema"]} from marshmallow.utils import missing {base_class_import} @@ -296,16 +309,15 @@ def __init__(self, **kwargs): return code -def run(): - - targe_folder = os.path.join("ansys", "rep", "client", "jms", "resource") +def process_resources(subpackage, resources, base_class_path=""): - for resource in RESOURCES: + targe_folder = os.path.join("ansys", "rep", "client", subpackage, "resource") + for resource in resources: print(f"Processing resource {resource['class']}") # dynamically load resource schema module = importlib.import_module( - f"ansys.rep.client.jms.schema.{resource['schema_filename']}" + f"ansys.rep.client.{subpackage}.schema.{resource['schema_filename']}" ) resource_class = getattr(module, resource["schema"]) @@ -324,11 +336,11 @@ def run(): # if a base class other than Object need to be used, # we need to make sure to properly import it in the generated code - base_class = {"name": "Object", "filename": "base"} + base_class = {"name": "Object", "filename": "base", "path": base_class_path} if resource.get("base_class", None): base_class["name"] = resource["base_class"] base_class["filename"] = next( - (r["resource_filename"] for r in RESOURCES if r["class"] == resource["base_class"]), + (r["resource_filename"] for r in resources if r["class"] == resource["base_class"]), None, ) @@ -341,5 +353,10 @@ def run(): file.write(code) +def run(): + process_resources("jms", JMS_RESOURCES) + process_resources("auth", AUTH_RESOURCES, base_class_path="ansys.rep.client.jms.resource") + + if __name__ == "__main__": run() From 8b3f45708e90d5dea17fc45aa193dc0d37d0554d Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 1 Sep 2022 18:47:04 +0200 Subject: [PATCH 10/13] Adjust auth resources --- .pre-commit-config.yaml | 6 +-- ansys/rep/client/auth/resource/user.py | 54 +++++++++---------- ansys/rep/client/jms/resource/algorithm.py | 2 +- .../jms/resource/bool_parameter_definition.py | 2 +- ansys/rep/client/jms/resource/evaluator.py | 2 +- .../resource/float_parameter_definition.py | 2 +- .../jms/resource/int_parameter_definition.py | 2 +- ansys/rep/client/jms/resource/job.py | 2 +- .../rep/client/jms/resource/job_definition.py | 2 +- .../client/jms/resource/license_context.py | 2 +- ansys/rep/client/jms/resource/licensing.py | 2 +- ansys/rep/client/jms/resource/operation.py | 2 +- .../jms/resource/parameter_definition.py | 2 +- .../client/jms/resource/parameter_mapping.py | 2 +- ansys/rep/client/jms/resource/project.py | 2 +- .../client/jms/resource/project_permission.py | 2 +- .../jms/resource/resource_requirements.py | 2 +- ansys/rep/client/jms/resource/selection.py | 2 +- ansys/rep/client/jms/resource/software.py | 2 +- .../resource/string_parameter_definition.py | 2 +- .../client/jms/resource/success_criteria.py | 2 +- ansys/rep/client/jms/resource/task.py | 2 +- .../client/jms/resource/task_definition.py | 2 +- .../jms/resource/task_definition_template.py | 2 +- generate_resources.py | 1 - 25 files changed, 51 insertions(+), 54 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d85c0d812..d459f4b23 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,19 +4,19 @@ repos: rev: 22.3.0 hooks: - id: black - exclude: ^ansys/rep/client/jms/resource/ + exclude: ^(ansys/rep/client/jms/resource/|ansys/rep/client/auth/resource/) - repo: https://github.com/pycqa/isort rev: 5.10.1 hooks: - id: isort - exclude: ^ansys/rep/client/jms/resource/ + exclude: ^(ansys/rep/client/jms/resource/|ansys/rep/client/auth/resource/) - repo: https://gitlab.com/PyCQA/flake8 rev: 4.0.1 hooks: - id: flake8 - exclude: ^ansys/rep/client/jms/resource/ + exclude: ^(ansys/rep/client/jms/resource/|ansys/rep/client/auth/resource/) - repo: https://github.com/codespell-project/codespell rev: v2.1.0 diff --git a/ansys/rep/client/auth/resource/user.py b/ansys/rep/client/auth/resource/user.py index 10a42d279..e147a8f16 100644 --- a/ansys/rep/client/auth/resource/user.py +++ b/ansys/rep/client/auth/resource/user.py @@ -1,42 +1,40 @@ -# ---------------------------------------------------------- -# Copyright (C) 2019 by -# ANSYS Switzerland GmbH -# www.ansys.com -# -# Author(s): F.Negri -# ---------------------------------------------------------- -import logging +# autogenerated code based on UserSchema +from marshmallow.utils import missing from ansys.rep.client.jms.resource.base import Object - from ..schema.user import UserSchema -log = logging.getLogger(__name__) - - class User(Object): - """User resource - - Args: - **kwargs: Arbitrary keyword arguments, see the User schema below. - - Example: - - >>> new_user = User(username='test_user', password='dummy', - >>> email='test_user@test.com', fullname='Test User', - >>> is_admin=False) - - The User schema has the following fields: - - .. jsonschema:: schemas/User.json + """User resource. + + Parameters: + id (str): Unique user ID, generated internally by the server on creation. + username (str): Username. + password (str): Password. + first_name (str, optional): First name + last_name (str, optional): Last name + email (str, optional): E-mail address (optional). + groups (str): Groups the user belongs to + realm_roles (str): Realm roles assigned to the user + is_admin: Whether the user has admin rights or not. """ class Meta: schema = UserSchema + rest_name = "None" def __init__(self, **kwargs): - super(User, self).__init__(**kwargs) - + self.id = missing + self.username = missing + self.password = missing + self.first_name = missing + self.last_name = missing + self.email = missing + self.groups = missing + self.realm_roles = missing + self.is_admin = missing + + super().__init__(**kwargs) UserSchema.Meta.object_class = User diff --git a/ansys/rep/client/jms/resource/algorithm.py b/ansys/rep/client/jms/resource/algorithm.py index 9d23a916b..0d1c58acf 100644 --- a/ansys/rep/client/jms/resource/algorithm.py +++ b/ansys/rep/client/jms/resource/algorithm.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on AlgorithmSchema +# autogenerated code based on AlgorithmSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/bool_parameter_definition.py b/ansys/rep/client/jms/resource/bool_parameter_definition.py index 7480c09e3..8b7896665 100644 --- a/ansys/rep/client/jms/resource/bool_parameter_definition.py +++ b/ansys/rep/client/jms/resource/bool_parameter_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on BoolParameterDefinitionSchema +# autogenerated code based on BoolParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/evaluator.py b/ansys/rep/client/jms/resource/evaluator.py index fbc876583..8240e96da 100644 --- a/ansys/rep/client/jms/resource/evaluator.py +++ b/ansys/rep/client/jms/resource/evaluator.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on EvaluatorSchema +# autogenerated code based on EvaluatorSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/float_parameter_definition.py b/ansys/rep/client/jms/resource/float_parameter_definition.py index 3d010b886..457e68c35 100644 --- a/ansys/rep/client/jms/resource/float_parameter_definition.py +++ b/ansys/rep/client/jms/resource/float_parameter_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on FloatParameterDefinitionSchema +# autogenerated code based on FloatParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/int_parameter_definition.py b/ansys/rep/client/jms/resource/int_parameter_definition.py index c75441c5e..201a2eb2a 100644 --- a/ansys/rep/client/jms/resource/int_parameter_definition.py +++ b/ansys/rep/client/jms/resource/int_parameter_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on IntParameterDefinitionSchema +# autogenerated code based on IntParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/job.py b/ansys/rep/client/jms/resource/job.py index e51ea1828..ce0e840cb 100644 --- a/ansys/rep/client/jms/resource/job.py +++ b/ansys/rep/client/jms/resource/job.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on JobSchema +# autogenerated code based on JobSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/job_definition.py b/ansys/rep/client/jms/resource/job_definition.py index 3794ab16e..07d58a26f 100644 --- a/ansys/rep/client/jms/resource/job_definition.py +++ b/ansys/rep/client/jms/resource/job_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on JobDefinitionSchema +# autogenerated code based on JobDefinitionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/license_context.py b/ansys/rep/client/jms/resource/license_context.py index 681d06e26..f1ca5ac9c 100644 --- a/ansys/rep/client/jms/resource/license_context.py +++ b/ansys/rep/client/jms/resource/license_context.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on LicenseContextSchema +# autogenerated code based on LicenseContextSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/licensing.py b/ansys/rep/client/jms/resource/licensing.py index f146d2659..a48ba2c77 100644 --- a/ansys/rep/client/jms/resource/licensing.py +++ b/ansys/rep/client/jms/resource/licensing.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on LicensingSchema +# autogenerated code based on LicensingSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/operation.py b/ansys/rep/client/jms/resource/operation.py index 0785c11b3..3d3f9efae 100644 --- a/ansys/rep/client/jms/resource/operation.py +++ b/ansys/rep/client/jms/resource/operation.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on OperationSchema +# autogenerated code based on OperationSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/parameter_definition.py b/ansys/rep/client/jms/resource/parameter_definition.py index ecbc48f29..6267f85c0 100644 --- a/ansys/rep/client/jms/resource/parameter_definition.py +++ b/ansys/rep/client/jms/resource/parameter_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on ParameterDefinitionSchema +# autogenerated code based on ParameterDefinitionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/parameter_mapping.py b/ansys/rep/client/jms/resource/parameter_mapping.py index 603849a27..7cd7352c5 100644 --- a/ansys/rep/client/jms/resource/parameter_mapping.py +++ b/ansys/rep/client/jms/resource/parameter_mapping.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on ParameterMappingSchema +# autogenerated code based on ParameterMappingSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/project.py b/ansys/rep/client/jms/resource/project.py index b4f4acc60..7671006af 100644 --- a/ansys/rep/client/jms/resource/project.py +++ b/ansys/rep/client/jms/resource/project.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on ProjectSchema +# autogenerated code based on ProjectSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/project_permission.py b/ansys/rep/client/jms/resource/project_permission.py index a42bc6c4b..f5e3aad6a 100644 --- a/ansys/rep/client/jms/resource/project_permission.py +++ b/ansys/rep/client/jms/resource/project_permission.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on ProjectPermissionSchema +# autogenerated code based on ProjectPermissionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/resource_requirements.py b/ansys/rep/client/jms/resource/resource_requirements.py index 42dd1a3ab..7583498d3 100644 --- a/ansys/rep/client/jms/resource/resource_requirements.py +++ b/ansys/rep/client/jms/resource/resource_requirements.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on ResourceRequirementsSchema +# autogenerated code based on ResourceRequirementsSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/selection.py b/ansys/rep/client/jms/resource/selection.py index 0d2320523..96cb58ca3 100644 --- a/ansys/rep/client/jms/resource/selection.py +++ b/ansys/rep/client/jms/resource/selection.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on JobSelectionSchema +# autogenerated code based on JobSelectionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/software.py b/ansys/rep/client/jms/resource/software.py index 0d7f6f961..96081248a 100644 --- a/ansys/rep/client/jms/resource/software.py +++ b/ansys/rep/client/jms/resource/software.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on SoftwareSchema +# autogenerated code based on SoftwareSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/string_parameter_definition.py b/ansys/rep/client/jms/resource/string_parameter_definition.py index 6a5b2acd3..e86a1827f 100644 --- a/ansys/rep/client/jms/resource/string_parameter_definition.py +++ b/ansys/rep/client/jms/resource/string_parameter_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on StringParameterDefinitionSchema +# autogenerated code based on StringParameterDefinitionSchema from marshmallow.utils import missing from .parameter_definition import ParameterDefinition diff --git a/ansys/rep/client/jms/resource/success_criteria.py b/ansys/rep/client/jms/resource/success_criteria.py index 21cb8d87e..b2a99f661 100644 --- a/ansys/rep/client/jms/resource/success_criteria.py +++ b/ansys/rep/client/jms/resource/success_criteria.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on SuccessCriteriaSchema +# autogenerated code based on SuccessCriteriaSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/task.py b/ansys/rep/client/jms/resource/task.py index 706bd58f0..59162250d 100644 --- a/ansys/rep/client/jms/resource/task.py +++ b/ansys/rep/client/jms/resource/task.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on TaskSchema +# autogenerated code based on TaskSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/task_definition.py b/ansys/rep/client/jms/resource/task_definition.py index 8d44dcdf7..31c816c0f 100644 --- a/ansys/rep/client/jms/resource/task_definition.py +++ b/ansys/rep/client/jms/resource/task_definition.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on TaskDefinitionSchema +# autogenerated code based on TaskDefinitionSchema from marshmallow.utils import missing from .base import Object diff --git a/ansys/rep/client/jms/resource/task_definition_template.py b/ansys/rep/client/jms/resource/task_definition_template.py index 2e761eacb..781cad1ed 100644 --- a/ansys/rep/client/jms/resource/task_definition_template.py +++ b/ansys/rep/client/jms/resource/task_definition_template.py @@ -1,4 +1,4 @@ -# autogenerated on 2022-09-01 17:37 based on TaskDefinitionTemplateSchema +# autogenerated code based on TaskDefinitionTemplateSchema from marshmallow.utils import missing from .base import Object diff --git a/generate_resources.py b/generate_resources.py index 4f4c44f54..46092f6a1 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -227,7 +227,6 @@ "schema_filename": "user", "rest_name": None, "additional_fields": [], - "base_class": "Object", "class": "User", "resource_filename": "user", }, From 12a940b507eedafdb34835bd53cf9b864910d36a Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Fri, 2 Sep 2022 08:52:11 +0200 Subject: [PATCH 11/13] Clean up doc generation --- doc/source/conf.py | 1 - prepare_documentation.py | 2 +- requirements/requirements_doc.txt | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 0ac3a99db..6f0c9d83c 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -35,7 +35,6 @@ "sphinx.ext.extlinks", # "sphinx.ext.viewcode", # to show pytho source code "sphinxcontrib.httpdomain", - "sphinxcontrib.jsonschema", "sphinxcontrib.globalsubs", "sphinx.ext.intersphinx", "sphinx_copybutton", diff --git a/prepare_documentation.py b/prepare_documentation.py index 6fb6f71dc..e24d11f5a 100644 --- a/prepare_documentation.py +++ b/prepare_documentation.py @@ -145,5 +145,5 @@ def archive_examples(examples): if __name__ == "__main__": - generate_openapi_specs() + # generate_openapi_specs() archive_examples(["mapdl_motorbike_frame"]) diff --git a/requirements/requirements_doc.txt b/requirements/requirements_doc.txt index 3d71f9ecf..a581b4e0a 100644 --- a/requirements/requirements_doc.txt +++ b/requirements/requirements_doc.txt @@ -4,6 +4,5 @@ ansys-sphinx-theme==0.5.2 sphinx-copybutton==0.5 apispec==5.2.2 sphinxcontrib-httpdomain==1.8.0 -sphinxcontrib-jsonschema==0.9.3 sphinxcontrib-globalsubs==0.1.0 sphinxnotes-strike==1.2 \ No newline at end of file From 3492d6298d550b8553cf6de4ccacdd702aaa2def Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Fri, 2 Sep 2022 11:12:14 +0200 Subject: [PATCH 12/13] Use numpydoc style for generated code --- ansys/rep/client/auth/resource/user.py | 29 ++++++---- ansys/rep/client/jms/resource/algorithm.py | 24 +++++--- .../jms/resource/bool_parameter_definition.py | 26 ++++++--- ansys/rep/client/jms/resource/evaluator.py | 42 +++++++++----- .../resource/float_parameter_definition.py | 41 ++++++++----- .../jms/resource/int_parameter_definition.py | 38 ++++++++----- ansys/rep/client/jms/resource/job.py | 51 +++++++++++------ .../rep/client/jms/resource/job_definition.py | 30 ++++++---- .../client/jms/resource/license_context.py | 9 ++- ansys/rep/client/jms/resource/licensing.py | 6 +- ansys/rep/client/jms/resource/operation.py | 33 +++++++---- .../jms/resource/parameter_definition.py | 3 +- .../client/jms/resource/parameter_mapping.py | 51 +++++++++++------ ansys/rep/client/jms/resource/project.py | 27 ++++++--- .../client/jms/resource/project_permission.py | 15 +++-- .../jms/resource/resource_requirements.py | 18 ++++-- ansys/rep/client/jms/resource/selection.py | 21 ++++--- ansys/rep/client/jms/resource/software.py | 9 ++- .../resource/string_parameter_definition.py | 29 ++++++---- .../client/jms/resource/success_criteria.py | 21 ++++--- ansys/rep/client/jms/resource/task.py | 57 ++++++++++++------- .../client/jms/resource/task_definition.py | 54 ++++++++++++------ .../jms/resource/task_definition_template.py | 45 ++++++++++----- ansys/rep/client/jms/schema/algorithm.py | 2 +- ansys/rep/client/jms/schema/file.py | 6 +- .../client/jms/schema/fitness_definition.py | 4 +- ansys/rep/client/jms/schema/job.py | 18 +++--- ansys/rep/client/jms/schema/job_definition.py | 8 +-- ansys/rep/client/jms/schema/selection.py | 2 +- ansys/rep/client/jms/schema/task.py | 5 +- doc/source/api/auth.rst | 2 +- generate_resources.py | 17 +++--- 32 files changed, 481 insertions(+), 262 deletions(-) diff --git a/ansys/rep/client/auth/resource/user.py b/ansys/rep/client/auth/resource/user.py index e147a8f16..cf980a3b7 100644 --- a/ansys/rep/client/auth/resource/user.py +++ b/ansys/rep/client/auth/resource/user.py @@ -7,16 +7,25 @@ class User(Object): """User resource. - Parameters: - id (str): Unique user ID, generated internally by the server on creation. - username (str): Username. - password (str): Password. - first_name (str, optional): First name - last_name (str, optional): Last name - email (str, optional): E-mail address (optional). - groups (str): Groups the user belongs to - realm_roles (str): Realm roles assigned to the user - is_admin: Whether the user has admin rights or not. + Parameters + ---------- + id : str + Unique user ID, generated internally by the server on creation. + username : str + Username. + password : str + Password. + first_name : str, optional + First name + last_name : str, optional + Last name + email : str, optional + E-mail address (optional). + groups : str + Groups the user belongs to + realm_roles : str + Realm roles assigned to the user + is_admin Whether the user has admin rights or not. """ diff --git a/ansys/rep/client/jms/resource/algorithm.py b/ansys/rep/client/jms/resource/algorithm.py index 0d1c58acf..d7073491c 100644 --- a/ansys/rep/client/jms/resource/algorithm.py +++ b/ansys/rep/client/jms/resource/algorithm.py @@ -7,14 +7,22 @@ class Algorithm(Object): """Algorithm resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name of the algorithm. - description (str, optional): Description of the algorithm. - creation_time (datetime, optional): The date and time the algorithm was created. - modification_time (datetime, optional): The date and time the algorithm was last modified. - data (str, optional): Generic string field to hold arbitrary algorithm job_definition data, e.g. as JSON dictionary. - jobs (list[str]): List of design point IDs. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name of the algorithm. + description : str, optional + Description of the algorithm. + creation_time : datetime, optional + The date and time the algorithm was created. + modification_time : datetime, optional + The date and time the algorithm was last modified. + data : str, optional + Generic string field to hold arbitrary algorithm job_definition data, e.g. as JSON dictionary. + jobs : list[str] + List of job IDs. """ diff --git a/ansys/rep/client/jms/resource/bool_parameter_definition.py b/ansys/rep/client/jms/resource/bool_parameter_definition.py index 8b7896665..12aeeba58 100644 --- a/ansys/rep/client/jms/resource/bool_parameter_definition.py +++ b/ansys/rep/client/jms/resource/bool_parameter_definition.py @@ -7,15 +7,23 @@ class BoolParameterDefinition(ParameterDefinition): """BoolParameterDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name (ID) of the parameter. - quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. - units (str, optional): Units for the parameter. - display_text (str, optional): Text to display as the parameter name. - mode (str): Indicates whether it's an input or output parameter. Filled server side. - type - default (bool, optional): Default parameter value. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name (ID) of the parameter. + quantity_name : str, optional + Name of the quantity the parameter represents, e.g. Length. + units : str, optional + Units for the parameter. + display_text : str, optional + Text to display as the parameter name. + mode : str + Indicates whether it's an input or output parameter. Filled server side. + type + default : bool, optional + Default parameter value. """ diff --git a/ansys/rep/client/jms/resource/evaluator.py b/ansys/rep/client/jms/resource/evaluator.py index 8240e96da..ff704d8db 100644 --- a/ansys/rep/client/jms/resource/evaluator.py +++ b/ansys/rep/client/jms/resource/evaluator.py @@ -7,20 +7,34 @@ class Evaluator(Object): """Evaluator resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - host_id (str): Unique identifier built from hardware information and selected job_definition details of an evaluator. - name (str, optional): Name of the evaluator. - hostname (str, optional): Name of the host on which the evaluator is running. - platform (str, optional): Operating system on which the evaluator is running. - task_manager_type (str, optional): Type of the task manager used by the evaluator. - project_server_select (bool, optional): Whether the evaluator allows server-driven assignment of projects or uses it's own local settings. - alive_update_interval (int, optional): Minimal time (in seconds) between evaluator registration updates. - update_time (datetime, optional): Last time the evaluator updated it's registration details. Used to check which evaluators are alive. - external_access_port (int, optional): Port number for external access to the evaluator. - project_assignment_mode (str, optional): Which strategy to use for selecting projects to work on. - project_list (list): List of projects on which this evaluator should be working. - configuration (dict, optional): Details of the evaluator configuration, including hardware info and available applications. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + host_id : str + Unique identifier built from hardware information and selected job_definition details of an evaluator. + name : str, optional + Name of the evaluator. + hostname : str, optional + Name of the host on which the evaluator is running. + platform : str, optional + Operating system on which the evaluator is running. + task_manager_type : str, optional + Type of the task manager used by the evaluator. + project_server_select : bool, optional + Whether the evaluator allows server-driven assignment of projects or uses it's own local settings. + alive_update_interval : int, optional + Minimal time (in seconds) between evaluator registration updates. + update_time : datetime, optional + Last time the evaluator updated it's registration details. Used to check which evaluators are alive. + external_access_port : int, optional + Port number for external access to the evaluator. + project_assignment_mode : str, optional + Which strategy to use for selecting projects to work on. + project_list : list + List of projects on which this evaluator should be working. + configuration : dict, optional + Details of the evaluator configuration, including hardware info and available applications. """ diff --git a/ansys/rep/client/jms/resource/float_parameter_definition.py b/ansys/rep/client/jms/resource/float_parameter_definition.py index 457e68c35..b84a57def 100644 --- a/ansys/rep/client/jms/resource/float_parameter_definition.py +++ b/ansys/rep/client/jms/resource/float_parameter_definition.py @@ -7,20 +7,33 @@ class FloatParameterDefinition(ParameterDefinition): """FloatParameterDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name (ID) of the parameter. - quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. - units (str, optional): Units for the parameter. - display_text (str, optional): Text to display as the parameter name. - mode (str): Indicates whether it's an input or output parameter. Filled server side. - type - default (float, optional): Default parameter value. - lower_limit (float, optional): Lower bound for the parameter value. - upper_limit (float, optional): Upper bound for the parameter value. - step (float, optional): If provided, allowable values are given by: AllowableValue = lower_limit + n * step, where n is an integer and AllowableValue <= upper_limit. - cyclic (bool, optional): Indicates if the parameter is cyclic. - value_list (list, optional): A list of allowed values, alternative to providing upper and lower limits. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name (ID) of the parameter. + quantity_name : str, optional + Name of the quantity the parameter represents, e.g. Length. + units : str, optional + Units for the parameter. + display_text : str, optional + Text to display as the parameter name. + mode : str + Indicates whether it's an input or output parameter. Filled server side. + type + default : float, optional + Default parameter value. + lower_limit : float, optional + Lower bound for the parameter value. + upper_limit : float, optional + Upper bound for the parameter value. + step : float, optional + If provided, allowable values are given by: AllowableValue = lower_limit + n * step, where n is an integer and AllowableValue <= upper_limit. + cyclic : bool, optional + Indicates if the parameter is cyclic. + value_list : list, optional + A list of allowed values, alternative to providing upper and lower limits. """ diff --git a/ansys/rep/client/jms/resource/int_parameter_definition.py b/ansys/rep/client/jms/resource/int_parameter_definition.py index 201a2eb2a..4b8213cb4 100644 --- a/ansys/rep/client/jms/resource/int_parameter_definition.py +++ b/ansys/rep/client/jms/resource/int_parameter_definition.py @@ -7,19 +7,31 @@ class IntParameterDefinition(ParameterDefinition): """IntParameterDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name (ID) of the parameter. - quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. - units (str, optional): Units for the parameter. - display_text (str, optional): Text to display as the parameter name. - mode (str): Indicates whether it's an input or output parameter. Filled server side. - type - default (int, optional): Default parameter value. - lower_limit (int, optional): Lower bound for the parameter value. - upper_limit (int, optional): Upper bound for the parameter value. - step (int, optional): Equal to 1 by default. - cyclic (bool, optional): Indicates if the parameter is cyclic. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name (ID) of the parameter. + quantity_name : str, optional + Name of the quantity the parameter represents, e.g. Length. + units : str, optional + Units for the parameter. + display_text : str, optional + Text to display as the parameter name. + mode : str + Indicates whether it's an input or output parameter. Filled server side. + type + default : int, optional + Default parameter value. + lower_limit : int, optional + Lower bound for the parameter value. + upper_limit : int, optional + Upper bound for the parameter value. + step : int, optional + Equal to 1 by default. + cyclic : bool, optional + Indicates if the parameter is cyclic. """ diff --git a/ansys/rep/client/jms/resource/job.py b/ansys/rep/client/jms/resource/job.py index ce0e840cb..5f04bcd58 100644 --- a/ansys/rep/client/jms/resource/job.py +++ b/ansys/rep/client/jms/resource/job.py @@ -7,23 +7,40 @@ class Job(Object): """Job resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name of the design point. - eval_status (str): Evaluation status. - job_definition_id (str): ID of the linked job_definition, see :class:`ansys.rep.client.jms.JobDefinition`. - priority (int, optional): Priority with which design points are evaluated. The default is 0, which is the highest priority. Assigning a higher value to a design point makes it a lower priority. - values (dict, optional): Dictionary with (name,value) pairs for all parameters defined in the linked job_definition. - fitness (float, optional): Fitness value computed. - fitness_term_values (dict, optional): Dictionary with (name,value) pairs for all fitness terms computed. - note (str, optional): Optional note for this design point. - creator (str, optional): Optional name/ID of the creator of this design point. - executed_task_definition_level (int, optional): Execution level of the last executed process step (-1 if none has been executed yet). - creation_time (datetime, optional): The date and time the design point was created. - modification_time (datetime, optional): The date and time the design point was last modified. - elapsed_time (float): Number of seconds it took the evaluator(s) to update the design point. - evaluators (list, optional): List of UUID strings of the evaluators that updated the design point. - file_ids (list[str]): List of IDs of all files of this design point. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name of the job. + eval_status : str + Evaluation status. + job_definition_id : str + ID of the linked job_definition, see :class:`ansys.rep.client.jms.JobDefinition`. + priority : int, optional + Priority with which jobs are evaluated. The default is 0, which is the highest priority. Assigning a higher value to a design point makes it a lower priority. + values : dict, optional + Dictionary with (name,value) pairs for all parameters defined in the linked job_definition. + fitness : float, optional + Fitness value computed. + fitness_term_values : dict, optional + Dictionary with (name,value) pairs for all fitness terms computed. + note : str, optional + Optional note for this job. + creator : str, optional + Optional name/ID of the creator of this job. + executed_task_definition_level : int, optional + Execution level of the last executed process step (-1 if none has been executed yet). + creation_time : datetime, optional + The date and time the job was created. + modification_time : datetime, optional + The date and time the job was last modified. + elapsed_time : float + Number of seconds it took the evaluator(s) to update the job. + evaluators : list, optional + List of IDs of the evaluators that updated the job. + file_ids : list[str] + List of IDs of all files of this job. """ diff --git a/ansys/rep/client/jms/resource/job_definition.py b/ansys/rep/client/jms/resource/job_definition.py index 07d58a26f..6ffb6a88b 100644 --- a/ansys/rep/client/jms/resource/job_definition.py +++ b/ansys/rep/client/jms/resource/job_definition.py @@ -7,16 +7,26 @@ class JobDefinition(Object): """JobDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name of the job_definition - active (bool): Defines whether this is the active job_definition in the project where evaluators will evaluate pending design points - creation_time (datetime, optional): The date and time the job_definition was created. - modification_time (datetime, optional): The date and time the job_definition was last modified. - parameter_definition_ids (list[str]) - parameter_mapping_ids (list[str]) - task_definition_ids (list[str]) - fitness_definition (optional): An :class:`ansys.rep.client.jms.FitnessDefinition` object. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name of the job_definition + active : bool + Defines whether this is the active job definition in the project where evaluators will evaluate pending jobs + creation_time : datetime, optional + The date and time the job definition was created. + modification_time : datetime, optional + The date and time the job definition was last modified. + parameter_definition_ids : list[str] + + parameter_mapping_ids : list[str] + + task_definition_ids : list[str] + + fitness_definition : any, optional + An :class:`ansys.rep.client.jms.FitnessDefinition` object. """ diff --git a/ansys/rep/client/jms/resource/license_context.py b/ansys/rep/client/jms/resource/license_context.py index f1ca5ac9c..996c32b9d 100644 --- a/ansys/rep/client/jms/resource/license_context.py +++ b/ansys/rep/client/jms/resource/license_context.py @@ -7,9 +7,12 @@ class LicenseContext(Object): """LicenseContext resource. - Parameters: - context_id (str, optional): License context ID - environment (dict, optional): License context environment dict + Parameters + ---------- + context_id : str, optional + License context ID + environment : dict, optional + License context environment dict """ diff --git a/ansys/rep/client/jms/resource/licensing.py b/ansys/rep/client/jms/resource/licensing.py index a48ba2c77..3ff604b08 100644 --- a/ansys/rep/client/jms/resource/licensing.py +++ b/ansys/rep/client/jms/resource/licensing.py @@ -7,8 +7,10 @@ class Licensing(Object): """Licensing resource. - Parameters: - enable_shared_licensing (bool, optional): Whether to enable shared licensing contexts for Ansys simulations + Parameters + ---------- + enable_shared_licensing : bool, optional + Whether to enable shared licensing contexts for Ansys simulations """ diff --git a/ansys/rep/client/jms/resource/operation.py b/ansys/rep/client/jms/resource/operation.py index 3d3f9efae..f094594d8 100644 --- a/ansys/rep/client/jms/resource/operation.py +++ b/ansys/rep/client/jms/resource/operation.py @@ -7,17 +7,28 @@ class Operation(Object): """Operation resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional) - finished (bool, optional) - succeeded (bool, optional) - progress (float, optional) - status (str, optional) - result (dict, optional) - messages (list, optional) - start_time (datetime, optional) - end_time (datetime, optional) + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + + finished : bool, optional + + succeeded : bool, optional + + progress : float, optional + + status : str, optional + + result : dict, optional + + messages : list, optional + + start_time : datetime, optional + + end_time : datetime, optional + """ diff --git a/ansys/rep/client/jms/resource/parameter_definition.py b/ansys/rep/client/jms/resource/parameter_definition.py index 6267f85c0..8148a236f 100644 --- a/ansys/rep/client/jms/resource/parameter_definition.py +++ b/ansys/rep/client/jms/resource/parameter_definition.py @@ -7,7 +7,8 @@ class ParameterDefinition(Object): """ParameterDefinition resource. - Parameters: + Parameters + ---------- """ diff --git a/ansys/rep/client/jms/resource/parameter_mapping.py b/ansys/rep/client/jms/resource/parameter_mapping.py index 7cd7352c5..9bb6f61d0 100644 --- a/ansys/rep/client/jms/resource/parameter_mapping.py +++ b/ansys/rep/client/jms/resource/parameter_mapping.py @@ -7,23 +7,40 @@ class ParameterMapping(Object): """ParameterMapping resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - line (int, optional) - column (int, optional) - key_string (str, optional) - float_field (str, optional) - width (int, optional) - precision (int, optional) - tokenizer (str, optional) - decimal_symbol (str, optional) - digit_grouping_symbol (str, optional) - string_quote (str, optional) - true_string (str, optional) - false_string (str, optional) - parameter_definition_id (str, optional): ID of the linked parameter definition, see :class:`ansys.rep.client.jms.ParameterDefinition`. - task_definition_property (str, optional) - file_id (str, optional): ID of the file resource. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + line : int, optional + + column : int, optional + + key_string : str, optional + + float_field : str, optional + + width : int, optional + + precision : int, optional + + tokenizer : str, optional + + decimal_symbol : str, optional + + digit_grouping_symbol : str, optional + + string_quote : str, optional + + true_string : str, optional + + false_string : str, optional + + parameter_definition_id : str, optional + ID of the linked parameter definition, see :class:`ansys.rep.client.jms.ParameterDefinition`. + task_definition_property : str, optional + + file_id : str, optional + ID of the file resource. """ diff --git a/ansys/rep/client/jms/resource/project.py b/ansys/rep/client/jms/resource/project.py index 7671006af..6ea21bcca 100644 --- a/ansys/rep/client/jms/resource/project.py +++ b/ansys/rep/client/jms/resource/project.py @@ -7,15 +7,24 @@ class Project(Object): """Project resource. - Parameters: - id (str): Unique ID to access the project, specified on creation of the project. - name (str): Name of the project. - active (bool): Defines whether the project is active for evaluation. - priority (int): Priority to pick the project for evaluation. - creation_time (datetime, optional): The date and time the project was created. - modification_time (datetime, optional): The date and time the project was last modified. - file_storages (list): List of file storages defined for the project. - statistics (dict): Optional dictionary containing various project statistics. + Parameters + ---------- + id : str + Unique ID to access the project, specified on creation of the project. + name : str + Name of the project. + active : bool + Defines whether the project is active for evaluation. + priority : int + Priority to pick the project for evaluation. + creation_time : datetime, optional + The date and time the project was created. + modification_time : datetime, optional + The date and time the project was last modified. + file_storages : list + List of file storages defined for the project. + statistics : dict + Optional dictionary containing various project statistics. """ diff --git a/ansys/rep/client/jms/resource/project_permission.py b/ansys/rep/client/jms/resource/project_permission.py index f5e3aad6a..eabf3ef84 100644 --- a/ansys/rep/client/jms/resource/project_permission.py +++ b/ansys/rep/client/jms/resource/project_permission.py @@ -7,11 +7,16 @@ class ProjectPermission(Object): """ProjectPermission resource. - Parameters: - permission_type (str) - value_id (str) - value_name (str, optional) - role (str) + Parameters + ---------- + permission_type : str + + value_id : str + + value_name : str, optional + + role : str + """ diff --git a/ansys/rep/client/jms/resource/resource_requirements.py b/ansys/rep/client/jms/resource/resource_requirements.py index 7583498d3..c9433e68c 100644 --- a/ansys/rep/client/jms/resource/resource_requirements.py +++ b/ansys/rep/client/jms/resource/resource_requirements.py @@ -7,12 +7,18 @@ class ResourceRequirements(Object): """ResourceRequirements resource. - Parameters: - platform (str, optional) - memory (int, optional) - cpu_core_usage (float, optional) - disk_space (int, optional) - custom (dict, optional) + Parameters + ---------- + platform : str, optional + + memory : int, optional + + cpu_core_usage : float, optional + + disk_space : int, optional + + custom : dict, optional + """ diff --git a/ansys/rep/client/jms/resource/selection.py b/ansys/rep/client/jms/resource/selection.py index 96cb58ca3..19a236bef 100644 --- a/ansys/rep/client/jms/resource/selection.py +++ b/ansys/rep/client/jms/resource/selection.py @@ -7,13 +7,20 @@ class JobSelection(Object): """JobSelection resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str): Name of the selection. - creation_time (datetime, optional): The date and time the selection was created. - modification_time (datetime, optional): The date and time the selection was last modified. - algorithm_id (str, optional): ID of the :class:`ansys.rep.client.jms.Algorithm` the selection belongs to (optional). - jobs (list[str]): List of design point IDs. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str + Name of the selection. + creation_time : datetime, optional + The date and time the selection was created. + modification_time : datetime, optional + The date and time the selection was last modified. + algorithm_id : str, optional + ID of the :class:`ansys.rep.client.jms.Algorithm` the selection belongs to (optional). + jobs : list[str] + List of job IDs. """ diff --git a/ansys/rep/client/jms/resource/software.py b/ansys/rep/client/jms/resource/software.py index 96081248a..8965e33f9 100644 --- a/ansys/rep/client/jms/resource/software.py +++ b/ansys/rep/client/jms/resource/software.py @@ -7,9 +7,12 @@ class Software(Object): """Software resource. - Parameters: - name (str): Application's name. - version (str, optional): Application's version. + Parameters + ---------- + name : str + + version : str, optional + """ diff --git a/ansys/rep/client/jms/resource/string_parameter_definition.py b/ansys/rep/client/jms/resource/string_parameter_definition.py index e86a1827f..dc1eb87f7 100644 --- a/ansys/rep/client/jms/resource/string_parameter_definition.py +++ b/ansys/rep/client/jms/resource/string_parameter_definition.py @@ -7,16 +7,25 @@ class StringParameterDefinition(ParameterDefinition): """StringParameterDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name (ID) of the parameter. - quantity_name (str, optional): Name of the quantity the parameter represents, e.g. Length. - units (str, optional): Units for the parameter. - display_text (str, optional): Text to display as the parameter name. - mode (str): Indicates whether it's an input or output parameter. Filled server side. - type - default (str, optional): Default parameter value. - value_list (list, optional): A list of allowed values. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name (ID) of the parameter. + quantity_name : str, optional + Name of the quantity the parameter represents, e.g. Length. + units : str, optional + Units for the parameter. + display_text : str, optional + Text to display as the parameter name. + mode : str + Indicates whether it's an input or output parameter. Filled server side. + type + default : str, optional + Default parameter value. + value_list : list, optional + A list of allowed values. """ diff --git a/ansys/rep/client/jms/resource/success_criteria.py b/ansys/rep/client/jms/resource/success_criteria.py index b2a99f661..7b708f17a 100644 --- a/ansys/rep/client/jms/resource/success_criteria.py +++ b/ansys/rep/client/jms/resource/success_criteria.py @@ -7,13 +7,20 @@ class SuccessCriteria(Object): """SuccessCriteria resource. - Parameters: - return_code (int, optional): The process exit code that must be returned by the executed command. - expressions (list, optional): A list of expressions to be evaluated. - required_output_file_ids (list[str], optional): List of IDs of required output files. - require_all_output_files (bool, optional): Flag to require all output files. - required_output_parameter_ids (list[str], optional): List of names of required output parameters. - require_all_output_parameters (bool, optional): Flag to require all output parameters. + Parameters + ---------- + return_code : int, optional + The process exit code that must be returned by the executed command. + expressions : list, optional + A list of expressions to be evaluated. + required_output_file_ids : list[str], optional + List of IDs of required output files. + require_all_output_files : bool, optional + Flag to require all output files. + required_output_parameter_ids : list[str], optional + List of names of required output parameters. + require_all_output_parameters : bool, optional + Flag to require all output parameters. """ diff --git a/ansys/rep/client/jms/resource/task.py b/ansys/rep/client/jms/resource/task.py index 59162250d..718fdfeee 100644 --- a/ansys/rep/client/jms/resource/task.py +++ b/ansys/rep/client/jms/resource/task.py @@ -7,25 +7,44 @@ class Task(Object): """Task resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - modification_time (datetime, optional): The date and time the task was last modified. - creation_time (datetime, optional): The date and time the task was created. - pending_time (datetime, optional): The date and time the task was set to pending. - prolog_time (datetime, optional): The date and time the task was set to prolog. - running_time (datetime, optional): The date and time the task was set to running. - finished_time (datetime, optional): The date and time the task was completed. - eval_status (str, optional): Evaluation status. - trial_number (int, optional): Which attempt to execute the process step this task represent. - elapsed_time (float, optional): Number of seconds it took the evaluator to execute the task. - task_definition_id (str): ('ID of the :class:`ansys.rep.client.jms.TaskDefinition` the task is linked to.',) - task_definition_snapshot (optional): Snapshot of :class:`ansys.rep.client.jms.TaskDefinition` created when task status changes to prolog, before evaluation. - job_id (str): ID of the :class:`ansys.rep.client.jms.Job` the task is linked to. - evaluator_id (str, optional): UUID of the :class:`ansys.rep.client.jms.Evaluator` that updated the task. - input_file_ids (list[str]): List of IDs of input files of task. - output_file_ids (list[str]): List of IDs of output files of task. - inherited_file_ids (list[str]): List of IDs of inherited files of task. - owned_file_ids (list[str]): List of IDs of owned files of task. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + modification_time : datetime, optional + The date and time the task was last modified. + creation_time : datetime, optional + The date and time the task was created. + pending_time : datetime, optional + The date and time the task was set to pending. + prolog_time : datetime, optional + The date and time the task was set to prolog. + running_time : datetime, optional + The date and time the task was set to running. + finished_time : datetime, optional + The date and time the task was completed. + eval_status : str, optional + Evaluation status. + trial_number : int, optional + Which attempt to execute the process step this task represent. + elapsed_time : float, optional + Number of seconds it took the evaluator to execute the task. + task_definition_id : str + ID of the :class:`ansys.rep.client.jms.TaskDefinition` the task is linked to. + task_definition_snapshot : any, optional + Snapshot of :class:`ansys.rep.client.jms.TaskDefinition` created when task status changes to prolog, before evaluation. + job_id : str + ID of the :class:`ansys.rep.client.jms.Job` the task is linked to. + evaluator_id : str, optional + UUID of the :class:`ansys.rep.client.jms.Evaluator` that updated the task. + input_file_ids : list[str] + List of IDs of input files of task. + output_file_ids : list[str] + List of IDs of output files of task. + inherited_file_ids : list[str] + List of IDs of inherited files of task. + owned_file_ids : list[str] + List of IDs of owned files of task. """ diff --git a/ansys/rep/client/jms/resource/task_definition.py b/ansys/rep/client/jms/resource/task_definition.py index 31c816c0f..626519601 100644 --- a/ansys/rep/client/jms/resource/task_definition.py +++ b/ansys/rep/client/jms/resource/task_definition.py @@ -7,24 +7,42 @@ class TaskDefinition(Object): """TaskDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name. - execution_command (str, optional): Command to execute (command or execution script is required). - use_execution_script (bool, optional): Whether to run task with the execution command or the execution script. - execution_script_id (str, optional): Script to execute (command or execution script is required). - execution_level (int): Define execution level for this task. - execution_context (dict, optional): Additional arguments to pass to the executing command - environment (dict, optional): Environment variables to set for the executed process - max_execution_time (float, optional): Maximum time in seconds for executing the task. - num_trials (int, optional): Maximum number of attempts to execute the task. - store_output (bool, optional): Specify whether to store the standard output of the task. - input_file_ids (list[str]): List of IDs of input files. - output_file_ids (list[str]): List of IDs of output files. - success_criteria (optional): A :class:`ansys.rep.client.jms.SuccessCriteria` object. - licensing (optional): A :class:`ansys.rep.client.jms.Licensing` object. - software_requirements (optional): A list of :class:`ansys.rep.client.jms.Software` objects. - resource_requirements (optional): A :class:`ansys.rep.client.jms.ResourceRequirements` object. + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name. + execution_command : str, optional + Command to execute (command or execution script is required). + use_execution_script : bool, optional + Whether to run task with the execution command or the execution script. + execution_script_id : str, optional + Script to execute (command or execution script is required). + execution_level : int + Define execution level for this task. + execution_context : dict, optional + Additional arguments to pass to the executing command + environment : dict, optional + Environment variables to set for the executed process + max_execution_time : float, optional + Maximum time in seconds for executing the task. + num_trials : int, optional + Maximum number of attempts to execute the task. + store_output : bool, optional + Specify whether to store the standard output of the task. + input_file_ids : list[str] + List of IDs of input files. + output_file_ids : list[str] + List of IDs of output files. + success_criteria : any, optional + A :class:`ansys.rep.client.jms.SuccessCriteria` object. + licensing : any, optional + A :class:`ansys.rep.client.jms.Licensing` object. + software_requirements : any, optional + + resource_requirements : any, optional + """ diff --git a/ansys/rep/client/jms/resource/task_definition_template.py b/ansys/rep/client/jms/resource/task_definition_template.py index 781cad1ed..d9ab07547 100644 --- a/ansys/rep/client/jms/resource/task_definition_template.py +++ b/ansys/rep/client/jms/resource/task_definition_template.py @@ -7,21 +7,36 @@ class TaskDefinitionTemplate(Object): """TaskDefinitionTemplate resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - modification_time (datetime, optional): Last time the object was modified, in UTC - creation_time (datetime, optional): Time when the object was created, in UTC - name (str): Name of the template - version (str, optional): version of the template - software_requirements (optional) - resource_requirements (optional) - execution_context (dict, optional): Additional arguments to pass to the executing command - environment (dict, optional): Environment variables to set for the executed process - execution_command (str, optional): Command to execute (command or execution script is required). - use_execution_script (bool, optional): Whether to run task with the execution command or the execution script. - execution_script_storage_id (str, optional): Storage ID of the script to execute (command or execution script is required). - input_files (optional) - output_files (optional) + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + modification_time : datetime, optional + Last time the object was modified, in UTC + creation_time : datetime, optional + Time when the object was created, in UTC + name : str + Name of the template + version : str, optional + version of the template + software_requirements : any, optional + + resource_requirements : any, optional + + execution_context : dict, optional + Additional arguments to pass to the executing command + environment : dict, optional + Environment variables to set for the executed process + execution_command : str, optional + Command to execute (command or execution script is required). + use_execution_script : bool, optional + Whether to run task with the execution command or the execution script. + execution_script_storage_id : str, optional + Storage ID of the script to execute (command or execution script is required). + input_files : any, optional + + output_files : any, optional + """ diff --git a/ansys/rep/client/jms/schema/algorithm.py b/ansys/rep/client/jms/schema/algorithm.py index 3567ca505..c78b29680 100644 --- a/ansys/rep/client/jms/schema/algorithm.py +++ b/ansys/rep/client/jms/schema/algorithm.py @@ -33,4 +33,4 @@ class Meta(ObjectSchema.Meta): description="Generic string field to hold arbitrary algorithm job_definition data," " e.g. as JSON dictionary.", ) - job_ids = IdReferenceList("Job", attribute="jobs", description="List of design point IDs.") + job_ids = IdReferenceList("Job", attribute="jobs", description="List of job IDs.") diff --git a/ansys/rep/client/jms/schema/file.py b/ansys/rep/client/jms/schema/file.py index 594db1a97..47624e7cf 100644 --- a/ansys/rep/client/jms/schema/file.py +++ b/ansys/rep/client/jms/schema/file.py @@ -44,15 +44,13 @@ class Meta(ObjectSchema.Meta): evaluation_path = fields.String( allow_none=True, description="Relative path under which the file instance for a " - "design point evaluation will be stored.", + "job evaluation will be stored.", ) monitor = fields.Bool( allow_none=True, description="Whether to live monitor the file's content." ) - collect = fields.Bool( - allow_none=True, description="Whether file should be collected per design point" - ) + collect = fields.Bool(allow_none=True, description="Whether file should be collected per job") collect_interval = fields.Int( allow_none=True, description="Collect frequency for a file with collect=True." diff --git a/ansys/rep/client/jms/schema/fitness_definition.py b/ansys/rep/client/jms/schema/fitness_definition.py index df6f56a3f..b91471d67 100644 --- a/ansys/rep/client/jms/schema/fitness_definition.py +++ b/ansys/rep/client/jms/schema/fitness_definition.py @@ -40,6 +40,4 @@ class Meta(ObjectSchema.Meta): many=True, description="List of :class:`ansys.rep.client.jms.FitnessTermDefinition`.", ) - error_fitness = fields.Float( - description="The default fitness value assigned to failed design points." - ) + error_fitness = fields.Float(description="The default fitness value assigned to failed jobs.") diff --git a/ansys/rep/client/jms/schema/job.py b/ansys/rep/client/jms/schema/job.py index 9abc248a0..27366b793 100644 --- a/ansys/rep/client/jms/schema/job.py +++ b/ansys/rep/client/jms/schema/job.py @@ -28,7 +28,7 @@ class JobSchema(ObjectSchema): class Meta(ObjectSchema.Meta): pass - name = fields.String(allow_none=True, description="Name of the design point.") + name = fields.String(allow_none=True, description="Name of the job.") eval_status = fields.String(validate=OneOf(valid_eval_status), description="Evaluation status.") job_definition_id = IdReference( allow_none=False, @@ -41,7 +41,7 @@ class Meta(ObjectSchema.Meta): priority = fields.Integer( allow_none=True, default=0, - description="Priority with which design points are evaluated. The default is 0, " + description="Priority with which jobs are evaluated. The default is 0, " "which is the highest priority. Assigning a higher value to a design " "point makes it a lower priority.", ) @@ -58,9 +58,9 @@ class Meta(ObjectSchema.Meta): allow_none=True, description="Dictionary with (name,value) pairs for all fitness terms computed.", ) - note = fields.String(allow_none=True, description="Optional note for this design point.") + note = fields.String(allow_none=True, description="Optional note for this job.") creator = fields.String( - allow_none=True, description="Optional name/ID of the creator of this design point." + allow_none=True, description="Optional name/ID of the creator of this job." ) executed_task_definition_level = fields.Integer( allow_none=True, @@ -71,26 +71,26 @@ class Meta(ObjectSchema.Meta): creation_time = fields.DateTime( allow_none=True, load_only=True, - description="The date and time the design point was created.", + description="The date and time the job was created.", ) modification_time = fields.DateTime( allow_none=True, load_only=True, - description="The date and time the design point was last modified.", + description="The date and time the job was last modified.", ) elapsed_time = fields.Float( load_only=True, - description="Number of seconds it took the evaluator(s) to update the design point.", + description="Number of seconds it took the evaluator(s) to update the job.", ) evaluators = fields.List( fields.String(allow_none=True), allow_none=True, - description="List of UUID strings of the evaluators that updated the design point.", + description="List of IDs of the evaluators that updated the job.", ) file_ids = IdReferenceList( referenced_class="File", attribute="file_ids", load_only=True, - description="List of IDs of all files of this design point.", + description="List of IDs of all files of this job.", ) diff --git a/ansys/rep/client/jms/schema/job_definition.py b/ansys/rep/client/jms/schema/job_definition.py index 6dc397ff1..76b1f15ab 100644 --- a/ansys/rep/client/jms/schema/job_definition.py +++ b/ansys/rep/client/jms/schema/job_definition.py @@ -22,18 +22,18 @@ class Meta(ObjectSchema.Meta): name = fields.String(allow_none=True, description="Name of the job_definition") active = fields.Boolean( - description="Defines whether this is the active job_definition in the " - "project where evaluators will evaluate pending design points" + description="Defines whether this is the active job definition in the " + "project where evaluators will evaluate pending jobs" ) creation_time = fields.DateTime( allow_none=True, load_only=True, - description="The date and time the job_definition was created.", + description="The date and time the job definition was created.", ) modification_time = fields.DateTime( allow_none=True, load_only=True, - description="The date and time the job_definition was last modified.", + description="The date and time the job definition was last modified.", ) parameter_definition_ids = IdReferenceList( diff --git a/ansys/rep/client/jms/schema/selection.py b/ansys/rep/client/jms/schema/selection.py index 23be68cb4..fb488d373 100644 --- a/ansys/rep/client/jms/schema/selection.py +++ b/ansys/rep/client/jms/schema/selection.py @@ -34,4 +34,4 @@ class Meta(ObjectSchema.Meta): description="ID of the :class:`ansys.rep.client.jms.Algorithm` " "the selection belongs to (optional).", ) - object_ids = IdReferenceList("Job", attribute="jobs", description="List of design point IDs.") + object_ids = IdReferenceList("Job", attribute="jobs", description="List of job IDs.") diff --git a/ansys/rep/client/jms/schema/task.py b/ansys/rep/client/jms/schema/task.py index 4c9cf63a3..e8d9cda3d 100644 --- a/ansys/rep/client/jms/schema/task.py +++ b/ansys/rep/client/jms/schema/task.py @@ -56,9 +56,8 @@ class Meta(ObjectSchema.Meta): allow_none=False, attribute="task_definition_id", referenced_class="TaskDefinition", - description=( - "ID of the :class:`ansys.rep.client.jms.TaskDefinition` the task is linked to.", - ), + description="ID of the :class:`ansys.rep.client.jms.TaskDefinition` " + "the task is linked to.", ) task_definition_snapshot = fields.Nested( TaskDefinitionSchema, diff --git a/doc/source/api/auth.rst b/doc/source/api/auth.rst index 24de808ea..ac06ee3d8 100644 --- a/doc/source/api/auth.rst +++ b/doc/source/api/auth.rst @@ -6,7 +6,7 @@ Authentication Service The REP Authentication Service processes all REP sign ins following OAuth 2.0 resource owner password credentials flow. When you enter your REP credentials, you get an access token (expiring after 24 hours) and a refresh token for authenticating all services. -The ```ansys.rep.client.auth``` subpackage wraps around the Authentication Service REST API available at ``https://hostname:port/rep/auth/api``. +The ``ansys.rep.client.auth`` subpackage wraps around the Authentication Service REST API available at ``https://hostname:port/rep/auth/api``. Authentication function ------------------------------------------ diff --git a/generate_resources.py b/generate_resources.py index 46092f6a1..239fe49e0 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -1,7 +1,7 @@ """ Script to auto generate (most of the) JMS Resources. -Main aim is to auto-generate the class docstrings and -allows code completion (intellisense). +The main goal is to auto-generate the class docstrings and +allow code completion. """ import importlib @@ -263,15 +263,15 @@ def declared_fields(schema): field_doc = f"{field}" type = FIELD_MAPPING.get(v.__class__, None) if type: - field_doc += f" ({type}" + field_doc += f" : {type}" if v.allow_none: field_doc += ", optional" - field_doc += ")" + field_doc += "\n" elif v.allow_none: - field_doc += " (optional)" + field_doc += " : any, optional\n" desc = v.metadata.get("description", None) if desc: - field_doc += f": {desc}" + field_doc += f" {desc}" fields_doc.append(field_doc) return fields, fields_doc @@ -291,7 +291,8 @@ def get_generated_code(resource, base_class, fields, field_docs): class {resource['class']}({base_class["name"]}): """{resource['class']} resource. - Parameters: + Parameters + ---------- {field_docs} """ @@ -329,7 +330,7 @@ def process_resources(subpackage, resources, base_class_path=""): field_docs_str = "" for k in field_docs: - field_docs_str += f" {k}\n" + field_docs_str += f" {k}\n" print(f"Class init parameters:\n{field_docs_str}") From d1ef847a931fbd55edc7adf401592da8f19a75f7 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Fri, 2 Sep 2022 13:40:12 +0200 Subject: [PATCH 13/13] Improve doc --- ansys/rep/client/jms/api/project_api.py | 6 +- ansys/rep/client/jms/resource/algorithm.py | 2 +- .../jms/resource/bool_parameter_definition.py | 2 +- ansys/rep/client/jms/resource/evaluator.py | 2 +- ansys/rep/client/jms/resource/file.py | 53 ++++---- .../client/jms/resource/fitness_definition.py | 114 ++++++++++-------- .../resource/float_parameter_definition.py | 2 +- .../jms/resource/int_parameter_definition.py | 2 +- ansys/rep/client/jms/resource/job.py | 4 +- .../rep/client/jms/resource/job_definition.py | 9 +- ansys/rep/client/jms/resource/operation.py | 9 -- .../client/jms/resource/parameter_mapping.py | 15 +-- .../client/jms/resource/project_permission.py | 4 - .../jms/resource/resource_requirements.py | 5 - ansys/rep/client/jms/resource/selection.py | 2 +- ansys/rep/client/jms/resource/software.py | 2 - .../resource/string_parameter_definition.py | 2 +- ansys/rep/client/jms/resource/task.py | 10 +- .../client/jms/resource/task_definition.py | 13 +- .../jms/resource/task_definition_template.py | 12 +- ansys/rep/client/jms/schema/algorithm.py | 2 +- ansys/rep/client/jms/schema/evaluator.py | 2 +- .../client/jms/schema/fitness_definition.py | 2 +- ansys/rep/client/jms/schema/job.py | 5 +- ansys/rep/client/jms/schema/job_definition.py | 4 +- .../client/jms/schema/parameter_mapping.py | 3 +- ansys/rep/client/jms/schema/selection.py | 3 +- ansys/rep/client/jms/schema/task.py | 9 +- .../rep/client/jms/schema/task_definition.py | 7 +- generate_resources.py | 15 ++- 30 files changed, 153 insertions(+), 169 deletions(-) diff --git a/ansys/rep/client/jms/api/project_api.py b/ansys/rep/client/jms/api/project_api.py index b958c45b1..ac6147cab 100644 --- a/ansys/rep/client/jms/api/project_api.py +++ b/ansys/rep/client/jms/api/project_api.py @@ -192,10 +192,10 @@ def delete_job_definitions(self, job_definitions): ################################################################ # Jobs - def get_jobs(self, as_objects=True, **query_params): + def get_jobs(self, as_objects=True, **query_params) -> List[Job]: return self._get_objects(Job, as_objects=as_objects, **query_params) - def create_jobs(self, jobs, as_objects=True): + def create_jobs(self, jobs, as_objects=True) -> List[Job]: """Create new jobs Args: @@ -218,7 +218,7 @@ def copy_jobs(self, jobs, as_objects=True, **query_params): """ return copy_jobs(self, jobs, as_objects=as_objects, **query_params) - def update_jobs(self, jobs, as_objects=True): + def update_jobs(self, jobs, as_objects=True) -> List[Job]: """Update existing jobs Args: diff --git a/ansys/rep/client/jms/resource/algorithm.py b/ansys/rep/client/jms/resource/algorithm.py index d7073491c..70405b9fd 100644 --- a/ansys/rep/client/jms/resource/algorithm.py +++ b/ansys/rep/client/jms/resource/algorithm.py @@ -20,7 +20,7 @@ class Algorithm(Object): modification_time : datetime, optional The date and time the algorithm was last modified. data : str, optional - Generic string field to hold arbitrary algorithm job_definition data, e.g. as JSON dictionary. + Generic string field to hold arbitrary algorithm configuration data, e.g. as JSON dictionary. jobs : list[str] List of job IDs. diff --git a/ansys/rep/client/jms/resource/bool_parameter_definition.py b/ansys/rep/client/jms/resource/bool_parameter_definition.py index 12aeeba58..8ecfcd173 100644 --- a/ansys/rep/client/jms/resource/bool_parameter_definition.py +++ b/ansys/rep/client/jms/resource/bool_parameter_definition.py @@ -21,7 +21,7 @@ class BoolParameterDefinition(ParameterDefinition): Text to display as the parameter name. mode : str Indicates whether it's an input or output parameter. Filled server side. - type + type : str default : bool, optional Default parameter value. diff --git a/ansys/rep/client/jms/resource/evaluator.py b/ansys/rep/client/jms/resource/evaluator.py index ff704d8db..e9abfee2d 100644 --- a/ansys/rep/client/jms/resource/evaluator.py +++ b/ansys/rep/client/jms/resource/evaluator.py @@ -12,7 +12,7 @@ class Evaluator(Object): id : str, optional Unique ID to access the resource, generated internally by the server on creation. host_id : str - Unique identifier built from hardware information and selected job_definition details of an evaluator. + Unique identifier built from hardware information and selected configuration details of an evaluator. name : str, optional Name of the evaluator. hostname : str, optional diff --git a/ansys/rep/client/jms/resource/file.py b/ansys/rep/client/jms/resource/file.py index 4e58fd147..a46b79ab4 100644 --- a/ansys/rep/client/jms/resource/file.py +++ b/ansys/rep/client/jms/resource/file.py @@ -7,28 +7,36 @@ class File(Object): """File resource. - Parameters: - id (str, optional): Unique ID to access the resource, - generated internally by the server on creation. - name (str): Name of the file resource. - type (str, optional): Type of the file. - This can be any string but using a correct media type for the - given resource is advisable. - storage_id (str, optional): File's identifier in the (orthogonal) file storage system - size (int, optional) - hash (str, optional) - creation_time (datetime, optional): The date and time the file resource was created. - modification_time (datetime, optional): The date and time the file resource - was last modified. - format (str, optional) - evaluation_path (str, optional): Relative path under which the file instance - for a design point evaluation will be stored. - monitor (bool, optional): Whether to live monitor the file's content. - collect (bool, optional): Whether file should be collected per design point - collect_interval (int, optional): Collect frequency for a file with collect=True. - Min value limited by the evaluator's settings. 0/None - let the evaluator decide, - other value - interval in seconds - reference_id (str, optional): Reference file from which this one was created + Parameters + ---------- + src : str, optional + Client-only field to specify the path of an input file. + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str + Name of the file resource. + type : str, optional + Type of the file. This can be any string but using a correct media type for the given resource is advisable. + storage_id : str, optional + File's identifier in the (orthogonal) file storage system + size : int, optional + hash : str, optional + creation_time : datetime, optional + The date and time the file resource was created. + modification_time : datetime, optional + The date and time the file resource was last modified. + format : str, optional + evaluation_path : str, optional + Relative path under which the file instance for a job evaluation will be stored. + monitor : bool, optional + Whether to live monitor the file's content. + collect : bool, optional + Whether file should be collected per job + collect_interval : int, optional + Collect frequency for a file with collect=True. Min value limited by the evaluator's settings. 0/None - let the evaluator decide, other value - interval in seconds + reference_id : str, optional + Reference file from which this one was created + """ class Meta: @@ -56,5 +64,4 @@ def __init__(self, src=None, **kwargs): super().__init__(**kwargs) - FileSchema.Meta.object_class = File diff --git a/ansys/rep/client/jms/resource/fitness_definition.py b/ansys/rep/client/jms/resource/fitness_definition.py index 406111178..cacea45d6 100644 --- a/ansys/rep/client/jms/resource/fitness_definition.py +++ b/ansys/rep/client/jms/resource/fitness_definition.py @@ -18,35 +18,50 @@ class FitnessTermDefinition(Object): """FitnessTermDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - name (str, optional): Name of the fitness term. - expression (str, optional): The Python expression that defines the fitness term. - type (str, optional): Fitness term type. - weighting_factor (float, optional): Relative importance of the fitness term in comparison to other fitness terms. - - Example: - - >>> # A fitness term of type objective - >>> ft1 = FitnessTermDefinition(name="weight", - type="design_objective", - weighting_factor=1.0, - expression="map_design_objective(values['weight'],7.5,5.5)" - ) - >>> # A fitness term of type target constraint - >>> ft2 = FitnessTermDefinition(name="torsional_stiffness", - type="target_constraint", - weighting_factor=0.8, - expression="map_target_constraint( - values['torsion_stiffness'], 1313.0, 5.0, 30.0)" - ) - >>> # A fitness term of type limit constraint - >>> ft3 = FitnessTermDefinition(name="max_stress", - type="limit_constraint", - weighting_factor=0.6, - expression="map_limit_constraint( - values['max_stress'], 451.0, 50.0 )" - ) + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + name : str, optional + Name of the fitness term. + expression : str, optional + The Python expression that defines the fitness term. + type : str, optional + Fitness term type. + weighting_factor : float, optional + Relative importance of the fitness term in comparison to other fitness terms. + + Examples + -------- + + A fitness term of type objective + + >>> ft1 = FitnessTermDefinition( + ... name="weight", + ... type="design_objective", + ... weighting_factor=1.0, + ... expression="map_design_objective(values['weight'],7.5,5.5)" + ... ) + + A fitness term of type target constraint + + >>> ft2 = FitnessTermDefinition( + ... name="torsional_stiffness", + ... type="target_constraint", + ... weighting_factor=0.8, + ... expression="map_target_constraint( + ... values['torsion_stiffness'], 1313.0, 5.0, 30.0)" + ... ) + + A fitness term of type limit constraint + + >>> ft3 = FitnessTermDefinition( + ... name="max_stress", + ... type="limit_constraint", + ... weighting_factor=0.6, + ... expression="map_limit_constraint( + ... values['max_stress'], 451.0, 50.0 )" + ... ) """ class Meta: @@ -69,24 +84,29 @@ def __init__(self, **kwargs): class FitnessDefinition(Object): """FitnessDefinition resource. - Parameters: - id (str, optional): Unique ID to access the resource, generated internally by the server on creation. - fitness_term_definitions: List of :class:`ansys.rep.client.jms.FitnessTermDefinition`. - error_fitness (float): The default fitness value assigned to failed design points. - - Example: - - >>> fd = FitnessDefinition(error_fitness=10.0) - >>> fd.add_fitness_term(name="weight", type="design_objective", weighting_factor=1.0, - expression="map_design_objective( values['weight'], 7.5, 5.5)") - >>> fd.add_fitness_term(name="torsional_stiffness", - type="target_constraint", - weighting_factor=1.0, - expression="map_target_constraint( - values['torsion_stiffness'], - 1313.0, - 5.0, - 30.0 )" ) + Parameters + ---------- + id : str, optional + Unique ID to access the resource, generated internally by the server on creation. + fitness_term_definitions + List of :class:`ansys.rep.client.jms.FitnessTermDefinition`. + error_fitness : float + The default fitness value assigned to failed design points. + + Examples + -------- + >>> fd = FitnessDefinition(error_fitness=10.0) + >>> fd.add_fitness_term(name="weight", type="design_objective", weighting_factor=1.0, + ... expression="map_design_objective( values['weight'], 7.5, 5.5)") + >>> fd.add_fitness_term(name="torsional_stiffness", + ... type="target_constraint", + ... weighting_factor=1.0, + ... expression="map_target_constraint( + ... values['torsion_stiffness'], + ... 1313.0, + ... 5.0, + ... 30.0 )" + ... ) """ class Meta: diff --git a/ansys/rep/client/jms/resource/float_parameter_definition.py b/ansys/rep/client/jms/resource/float_parameter_definition.py index b84a57def..0a21365c2 100644 --- a/ansys/rep/client/jms/resource/float_parameter_definition.py +++ b/ansys/rep/client/jms/resource/float_parameter_definition.py @@ -21,7 +21,7 @@ class FloatParameterDefinition(ParameterDefinition): Text to display as the parameter name. mode : str Indicates whether it's an input or output parameter. Filled server side. - type + type : str default : float, optional Default parameter value. lower_limit : float, optional diff --git a/ansys/rep/client/jms/resource/int_parameter_definition.py b/ansys/rep/client/jms/resource/int_parameter_definition.py index 4b8213cb4..acc33ae6f 100644 --- a/ansys/rep/client/jms/resource/int_parameter_definition.py +++ b/ansys/rep/client/jms/resource/int_parameter_definition.py @@ -21,7 +21,7 @@ class IntParameterDefinition(ParameterDefinition): Text to display as the parameter name. mode : str Indicates whether it's an input or output parameter. Filled server side. - type + type : str default : int, optional Default parameter value. lower_limit : int, optional diff --git a/ansys/rep/client/jms/resource/job.py b/ansys/rep/client/jms/resource/job.py index 5f04bcd58..1d16c40d0 100644 --- a/ansys/rep/client/jms/resource/job.py +++ b/ansys/rep/client/jms/resource/job.py @@ -16,11 +16,11 @@ class Job(Object): eval_status : str Evaluation status. job_definition_id : str - ID of the linked job_definition, see :class:`ansys.rep.client.jms.JobDefinition`. + ID of the linked job definition, see :class:`JobDefinition`. priority : int, optional Priority with which jobs are evaluated. The default is 0, which is the highest priority. Assigning a higher value to a design point makes it a lower priority. values : dict, optional - Dictionary with (name,value) pairs for all parameters defined in the linked job_definition. + Dictionary with (name,value) pairs for all parameters defined in the linked job definition. fitness : float, optional Fitness value computed. fitness_term_values : dict, optional diff --git a/ansys/rep/client/jms/resource/job_definition.py b/ansys/rep/client/jms/resource/job_definition.py index 6ffb6a88b..124eaaf32 100644 --- a/ansys/rep/client/jms/resource/job_definition.py +++ b/ansys/rep/client/jms/resource/job_definition.py @@ -12,7 +12,7 @@ class JobDefinition(Object): id : str, optional Unique ID to access the resource, generated internally by the server on creation. name : str, optional - Name of the job_definition + Name of the job definition active : bool Defines whether this is the active job definition in the project where evaluators will evaluate pending jobs creation_time : datetime, optional @@ -20,13 +20,10 @@ class JobDefinition(Object): modification_time : datetime, optional The date and time the job definition was last modified. parameter_definition_ids : list[str] - parameter_mapping_ids : list[str] - task_definition_ids : list[str] - - fitness_definition : any, optional - An :class:`ansys.rep.client.jms.FitnessDefinition` object. + fitness_definition : object, optional + A :class:`FitnessDefinition` object. """ diff --git a/ansys/rep/client/jms/resource/operation.py b/ansys/rep/client/jms/resource/operation.py index f094594d8..1c9de760d 100644 --- a/ansys/rep/client/jms/resource/operation.py +++ b/ansys/rep/client/jms/resource/operation.py @@ -12,24 +12,15 @@ class Operation(Object): id : str, optional Unique ID to access the resource, generated internally by the server on creation. name : str, optional - finished : bool, optional - succeeded : bool, optional - progress : float, optional - status : str, optional - result : dict, optional - messages : list, optional - start_time : datetime, optional - end_time : datetime, optional - """ class Meta: diff --git a/ansys/rep/client/jms/resource/parameter_mapping.py b/ansys/rep/client/jms/resource/parameter_mapping.py index 9bb6f61d0..5b1d4f3f6 100644 --- a/ansys/rep/client/jms/resource/parameter_mapping.py +++ b/ansys/rep/client/jms/resource/parameter_mapping.py @@ -12,33 +12,20 @@ class ParameterMapping(Object): id : str, optional Unique ID to access the resource, generated internally by the server on creation. line : int, optional - column : int, optional - key_string : str, optional - float_field : str, optional - width : int, optional - precision : int, optional - tokenizer : str, optional - decimal_symbol : str, optional - digit_grouping_symbol : str, optional - string_quote : str, optional - true_string : str, optional - false_string : str, optional - parameter_definition_id : str, optional - ID of the linked parameter definition, see :class:`ansys.rep.client.jms.ParameterDefinition`. + ID of the linked parameter definition, see :class:`ParameterDefinition`. task_definition_property : str, optional - file_id : str, optional ID of the file resource. diff --git a/ansys/rep/client/jms/resource/project_permission.py b/ansys/rep/client/jms/resource/project_permission.py index eabf3ef84..c225d0d26 100644 --- a/ansys/rep/client/jms/resource/project_permission.py +++ b/ansys/rep/client/jms/resource/project_permission.py @@ -10,14 +10,10 @@ class ProjectPermission(Object): Parameters ---------- permission_type : str - value_id : str - value_name : str, optional - role : str - """ class Meta: diff --git a/ansys/rep/client/jms/resource/resource_requirements.py b/ansys/rep/client/jms/resource/resource_requirements.py index c9433e68c..70ade1e53 100644 --- a/ansys/rep/client/jms/resource/resource_requirements.py +++ b/ansys/rep/client/jms/resource/resource_requirements.py @@ -10,16 +10,11 @@ class ResourceRequirements(Object): Parameters ---------- platform : str, optional - memory : int, optional - cpu_core_usage : float, optional - disk_space : int, optional - custom : dict, optional - """ class Meta: diff --git a/ansys/rep/client/jms/resource/selection.py b/ansys/rep/client/jms/resource/selection.py index 19a236bef..e9dac1e71 100644 --- a/ansys/rep/client/jms/resource/selection.py +++ b/ansys/rep/client/jms/resource/selection.py @@ -18,7 +18,7 @@ class JobSelection(Object): modification_time : datetime, optional The date and time the selection was last modified. algorithm_id : str, optional - ID of the :class:`ansys.rep.client.jms.Algorithm` the selection belongs to (optional). + ID of the :class:`Algorithm` the selection belongs to (optional). jobs : list[str] List of job IDs. diff --git a/ansys/rep/client/jms/resource/software.py b/ansys/rep/client/jms/resource/software.py index 8965e33f9..9bda1e11f 100644 --- a/ansys/rep/client/jms/resource/software.py +++ b/ansys/rep/client/jms/resource/software.py @@ -10,10 +10,8 @@ class Software(Object): Parameters ---------- name : str - version : str, optional - """ class Meta: diff --git a/ansys/rep/client/jms/resource/string_parameter_definition.py b/ansys/rep/client/jms/resource/string_parameter_definition.py index dc1eb87f7..500b3c285 100644 --- a/ansys/rep/client/jms/resource/string_parameter_definition.py +++ b/ansys/rep/client/jms/resource/string_parameter_definition.py @@ -21,7 +21,7 @@ class StringParameterDefinition(ParameterDefinition): Text to display as the parameter name. mode : str Indicates whether it's an input or output parameter. Filled server side. - type + type : str default : str, optional Default parameter value. value_list : list, optional diff --git a/ansys/rep/client/jms/resource/task.py b/ansys/rep/client/jms/resource/task.py index 718fdfeee..61ed340a2 100644 --- a/ansys/rep/client/jms/resource/task.py +++ b/ansys/rep/client/jms/resource/task.py @@ -30,13 +30,13 @@ class Task(Object): elapsed_time : float, optional Number of seconds it took the evaluator to execute the task. task_definition_id : str - ID of the :class:`ansys.rep.client.jms.TaskDefinition` the task is linked to. - task_definition_snapshot : any, optional - Snapshot of :class:`ansys.rep.client.jms.TaskDefinition` created when task status changes to prolog, before evaluation. + ID of the :class:`TaskDefinition` the task is linked to. + task_definition_snapshot : object, optional + Snapshot of :class:`TaskDefinition` created when task status changes to prolog, before evaluation. job_id : str - ID of the :class:`ansys.rep.client.jms.Job` the task is linked to. + ID of the :class:`Job` the task is linked to. evaluator_id : str, optional - UUID of the :class:`ansys.rep.client.jms.Evaluator` that updated the task. + UUID of the :class:`Evaluator` that updated the task. input_file_ids : list[str] List of IDs of input files of task. output_file_ids : list[str] diff --git a/ansys/rep/client/jms/resource/task_definition.py b/ansys/rep/client/jms/resource/task_definition.py index 626519601..de1f7d4a6 100644 --- a/ansys/rep/client/jms/resource/task_definition.py +++ b/ansys/rep/client/jms/resource/task_definition.py @@ -35,14 +35,11 @@ class TaskDefinition(Object): List of IDs of input files. output_file_ids : list[str] List of IDs of output files. - success_criteria : any, optional - A :class:`ansys.rep.client.jms.SuccessCriteria` object. - licensing : any, optional - A :class:`ansys.rep.client.jms.Licensing` object. - software_requirements : any, optional - - resource_requirements : any, optional - + success_criteria : object, optional + licensing : object, optional + A :class:`Licensing` object. + software_requirements : object, optional + resource_requirements : object, optional """ diff --git a/ansys/rep/client/jms/resource/task_definition_template.py b/ansys/rep/client/jms/resource/task_definition_template.py index d9ab07547..5f637c63b 100644 --- a/ansys/rep/client/jms/resource/task_definition_template.py +++ b/ansys/rep/client/jms/resource/task_definition_template.py @@ -19,10 +19,8 @@ class TaskDefinitionTemplate(Object): Name of the template version : str, optional version of the template - software_requirements : any, optional - - resource_requirements : any, optional - + software_requirements : object, optional + resource_requirements : object, optional execution_context : dict, optional Additional arguments to pass to the executing command environment : dict, optional @@ -33,10 +31,8 @@ class TaskDefinitionTemplate(Object): Whether to run task with the execution command or the execution script. execution_script_storage_id : str, optional Storage ID of the script to execute (command or execution script is required). - input_files : any, optional - - output_files : any, optional - + input_files : object, optional + output_files : object, optional """ diff --git a/ansys/rep/client/jms/schema/algorithm.py b/ansys/rep/client/jms/schema/algorithm.py index c78b29680..a21d4b0e3 100644 --- a/ansys/rep/client/jms/schema/algorithm.py +++ b/ansys/rep/client/jms/schema/algorithm.py @@ -30,7 +30,7 @@ class Meta(ObjectSchema.Meta): data = fields.String( allow_none=True, - description="Generic string field to hold arbitrary algorithm job_definition data," + description="Generic string field to hold arbitrary algorithm configuration data," " e.g. as JSON dictionary.", ) job_ids = IdReferenceList("Job", attribute="jobs", description="List of job IDs.") diff --git a/ansys/rep/client/jms/schema/evaluator.py b/ansys/rep/client/jms/schema/evaluator.py index d1b4c5a51..b55a207c6 100644 --- a/ansys/rep/client/jms/schema/evaluator.py +++ b/ansys/rep/client/jms/schema/evaluator.py @@ -20,7 +20,7 @@ class Meta: host_id = fields.String( description="Unique identifier built from hardware information and " - "selected job_definition details of an evaluator." + "selected configuration details of an evaluator." ) name = fields.String(allow_none=True, description="Name of the evaluator.") hostname = fields.String( diff --git a/ansys/rep/client/jms/schema/fitness_definition.py b/ansys/rep/client/jms/schema/fitness_definition.py index b91471d67..b6f80b2be 100644 --- a/ansys/rep/client/jms/schema/fitness_definition.py +++ b/ansys/rep/client/jms/schema/fitness_definition.py @@ -38,6 +38,6 @@ class Meta(ObjectSchema.Meta): fitness_term_definitions = fields.Nested( FitnessTermDefinitionSchema, many=True, - description="List of :class:`ansys.rep.client.jms.FitnessTermDefinition`.", + description="List of :class:`FitnessTermDefinition`.", ) error_fitness = fields.Float(description="The default fitness value assigned to failed jobs.") diff --git a/ansys/rep/client/jms/schema/job.py b/ansys/rep/client/jms/schema/job.py index 27366b793..3bca41389 100644 --- a/ansys/rep/client/jms/schema/job.py +++ b/ansys/rep/client/jms/schema/job.py @@ -34,8 +34,7 @@ class Meta(ObjectSchema.Meta): allow_none=False, attribute="job_definition_id", referenced_class="JobDefinition", - description="ID of the linked job_definition, " - "see :class:`ansys.rep.client.jms.JobDefinition`.", + description="ID of the linked job definition, " "see :class:`JobDefinition`.", ) priority = fields.Integer( @@ -49,7 +48,7 @@ class Meta(ObjectSchema.Meta): keys=fields.String(), allow_none=True, description="Dictionary with (name,value) pairs for all parameters defined in the " - "linked job_definition.", + "linked job definition.", ) fitness = fields.Float(allow_none=True, description="Fitness value computed.") fitness_term_values = fields.Dict( diff --git a/ansys/rep/client/jms/schema/job_definition.py b/ansys/rep/client/jms/schema/job_definition.py index 76b1f15ab..4ff8d0ab4 100644 --- a/ansys/rep/client/jms/schema/job_definition.py +++ b/ansys/rep/client/jms/schema/job_definition.py @@ -20,7 +20,7 @@ class JobDefinitionSchema(ObjectSchema): class Meta(ObjectSchema.Meta): pass - name = fields.String(allow_none=True, description="Name of the job_definition") + name = fields.String(allow_none=True, description="Name of the job definition") active = fields.Boolean( description="Defines whether this is the active job definition in the " "project where evaluators will evaluate pending jobs" @@ -49,5 +49,5 @@ class Meta(ObjectSchema.Meta): fitness_definition = fields.Nested( FitnessDefinitionSchema, allow_none=True, - description="An :class:`ansys.rep.client.jms.FitnessDefinition` object.", + description="A :class:`FitnessDefinition` object.", ) diff --git a/ansys/rep/client/jms/schema/parameter_mapping.py b/ansys/rep/client/jms/schema/parameter_mapping.py index a8f4d5fdb..01e89c989 100644 --- a/ansys/rep/client/jms/schema/parameter_mapping.py +++ b/ansys/rep/client/jms/schema/parameter_mapping.py @@ -35,8 +35,7 @@ class Meta(ObjectSchema.Meta): allow_none=True, attribute="parameter_definition_id", referenced_class="ParameterDefinition", - description="ID of the linked parameter definition, " - "see :class:`ansys.rep.client.jms.ParameterDefinition`.", + description="ID of the linked parameter definition, " "see :class:`ParameterDefinition`.", ) task_definition_property = fields.String(allow_none=True) file_id = IdReference( diff --git a/ansys/rep/client/jms/schema/selection.py b/ansys/rep/client/jms/schema/selection.py index fb488d373..21a78dc40 100644 --- a/ansys/rep/client/jms/schema/selection.py +++ b/ansys/rep/client/jms/schema/selection.py @@ -31,7 +31,6 @@ class Meta(ObjectSchema.Meta): allow_none=True, attribute="algorithm_id", referenced_class="DesignExplorationAlgorithm", - description="ID of the :class:`ansys.rep.client.jms.Algorithm` " - "the selection belongs to (optional).", + description="ID of the :class:`Algorithm` " "the selection belongs to (optional).", ) object_ids = IdReferenceList("Job", attribute="jobs", description="List of job IDs.") diff --git a/ansys/rep/client/jms/schema/task.py b/ansys/rep/client/jms/schema/task.py index e8d9cda3d..98045a7b4 100644 --- a/ansys/rep/client/jms/schema/task.py +++ b/ansys/rep/client/jms/schema/task.py @@ -56,13 +56,12 @@ class Meta(ObjectSchema.Meta): allow_none=False, attribute="task_definition_id", referenced_class="TaskDefinition", - description="ID of the :class:`ansys.rep.client.jms.TaskDefinition` " - "the task is linked to.", + description="ID of the :class:`TaskDefinition` " "the task is linked to.", ) task_definition_snapshot = fields.Nested( TaskDefinitionSchema, allow_none=True, - description="Snapshot of :class:`ansys.rep.client.jms.TaskDefinition` " + description="Snapshot of :class:`TaskDefinition` " "created when task status changes to prolog, before evaluation.", ) @@ -70,12 +69,12 @@ class Meta(ObjectSchema.Meta): allow_none=False, attribute="job_id", referenced_class="Job", - description="ID of the :class:`ansys.rep.client.jms.Job` the task is linked to.", + description="ID of the :class:`Job` the task is linked to.", ) evaluator_id = fields.String( allow_none=True, - description="UUID of the :class:`ansys.rep.client.jms.Evaluator` that updated the task.", + description="UUID of the :class:`Evaluator` that updated the task.", ) input_file_ids = IdReferenceList( diff --git a/ansys/rep/client/jms/schema/task_definition.py b/ansys/rep/client/jms/schema/task_definition.py index 480ace38e..9dc2d172c 100644 --- a/ansys/rep/client/jms/schema/task_definition.py +++ b/ansys/rep/client/jms/schema/task_definition.py @@ -126,22 +126,21 @@ class Meta(ObjectSchema.Meta): success_criteria = fields.Nested( SuccessCriteriaSchema, allow_none=True, - description="A :class:`ansys.rep.client.jms.SuccessCriteria` object.", ) licensing = fields.Nested( LicensingSchema, allow_none=True, - description="A :class:`ansys.rep.client.jms.Licensing` object.", + description="A :class:`Licensing` object.", ) software_requirements = fields.Nested( SoftwareSchema, many=True, allow_none=True, - metadata={"description": "A list of :class:`ansys.rep.client.jms.Software` objects."}, + metadata={"description": "A list of :class:`Software` objects."}, ) resource_requirements = fields.Nested( ResourceRequirementsSchema, allow_none=True, - metadata={"description": "A :class:`ansys.rep.client.jms.ResourceRequirements` object."}, + metadata={"description": "A :class:`ResourceRequirements` object."}, ) diff --git a/generate_resources.py b/generate_resources.py index 239fe49e0..5211b1f69 100644 --- a/generate_resources.py +++ b/generate_resources.py @@ -241,6 +241,8 @@ marshmallow.fields.DateTime: "datetime", marshmallow.fields.Dict: "dict", marshmallow.fields.List: "list", + marshmallow.fields.Constant: "Constant", + marshmallow.fields.Nested: "object", IdReferenceList: "list[str]", IdReference: "str", } @@ -261,9 +263,12 @@ def declared_fields(schema): # build attribute doc field_doc = f"{field}" - type = FIELD_MAPPING.get(v.__class__, None) - if type: - field_doc += f" : {type}" + if v.__class__ == marshmallow.fields.Constant: + field_type = type(v.constant).__name__ + else: + field_type = FIELD_MAPPING.get(v.__class__, None) + if field_type: + field_doc += f" : {field_type}" if v.allow_none: field_doc += ", optional" field_doc += "\n" @@ -271,7 +276,7 @@ def declared_fields(schema): field_doc += " : any, optional\n" desc = v.metadata.get("description", None) if desc: - field_doc += f" {desc}" + field_doc += f" {desc}\n" fields_doc.append(field_doc) return fields, fields_doc @@ -330,7 +335,7 @@ def process_resources(subpackage, resources, base_class_path=""): field_docs_str = "" for k in field_docs: - field_docs_str += f" {k}\n" + field_docs_str += f" {k}" print(f"Class init parameters:\n{field_docs_str}")