Source code for api.simulation.studies.studies_setup
""" Handling of studies """importtypingfromabcimportabstractmethod,ABCfrommore.api.simulation.studies.job_setupimportJobCreationContext
[docs]classStudiesSetup(ABC):""" Entry point for the studies API You should create this object using the :class:`~api.simulation.simulation_setup.SimulationSetup` object. """def__init__(self,item):self._study=itemdef_get_wrapped_object(self):returnself._study
[docs]@abstractmethoddefset_study(self,study)->'StudiesSetup':""" Sets the study being edited in this setup object. .. admonition:: Deprecated :class: warning `set_study` will be removed in a future MORe release, it is replaced by the :class:`~more.api.simulation.simulation_setup.SimulationSetup` .. admonition:: Example :class: note This method is invoked internally when using the :class:`~api.simulation.simulation_setup.SimulationSetup` .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() .. >>> created_study_setup = simulation_setup.create_study_setup().set_name(name='study_name') >>> study_setup = simulation_setup.get_study_setup(name='study_name') # invoked internally here, the study must already exist .. >>> created_study_setup._study == study_setup._study True >>> study_setup.set_study(study=None) Traceback (most recent call last): ... ValueError: ... Parameters ---------- study : StudyTable A study instance Returns ------- self: StudiesSetup Raises ------ ValueError Raised if the given study is not an instance of a study """pass
[docs]@abstractmethoddefadd_tags(self,tags:typing.List[str])->'StudiesSetup':""" Adds tags to the available tags .. admonition:: Example :class: note To add tags to the list available in the program: .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup().set_name(name='study_name') >>> study_setup.add_tags(['first_tag', 'second_tag']) <more...> .. >>> from more.design_parameters.registered_list_injector_singleton import LazyRegisteredListInjectorSingleton >>> list(LazyRegisteredListInjectorSingleton.get()['tags'].names_id_dict.keys()) ['first_tag', 'second_tag'] >>> study_setup.add_tags([None]) Traceback (most recent call last): ... TypeError: A tag can only be a string Parameters ---------- tags: list of strings A list of tag names to add to the available tags Returns ------- self: StudiesSetup Raises ------ TypeError Raised if a non-string value is given as one of the tags """pass
[docs]@abstractmethoddefremove_tags(self,tags:list)->'StudiesSetup':""" Remove tags from the available tags .. admonition:: Example :class: note To remove tags to the list available in the program (first tags are added): .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup().set_name(name='study_name') >>> study_setup.add_tags(['first_tag', 'second_tag', 'third_tag']) <more...> >>> study_setup.remove_tags(tags=['first_tag', 'third_tag']) <more...> .. >>> from more.design_parameters.registered_list_injector_singleton import LazyRegisteredListInjectorSingleton >>> list(LazyRegisteredListInjectorSingleton.get()['tags'].names_id_dict.keys()) ['second_tag'] Trying to remove a non-existent tag >>> study_setup.remove_tags(['non-existent-tag']) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- tags: list of strings A list of tag names to remove from the available tags Returns ------- self: StudiesSetup Raises ------ NameNotFoundError Raised if a tag with the given name does not exist """pass
[docs]@abstractmethoddefset_study_name(self,name:str)->'StudiesSetup':""" Changes the name of the study Parameters ---------- name: str The new name of the study Returns ------- self: StudiesSetup """pass
[docs]@abstractmethoddefget_name(self)->str:""" Returns the name of the object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup().set_name(name='study_name') >>> study_setup.set_name(name='new_name') <more...> >>> study_setup.get_name() 'new_name' Returns ------- name: str The name of the object """pass
[docs]@abstractmethoddefset_name(self,name:str,resolve_duplicate_name:bool=False)->'StudiesSetup':""" Changes the name of the study .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup().set_name(name='study_name') >>> study_setup.set_name(name='new_name') <more...> >>> second_study_setup = simulation_setup.create_study_setup() \\ ... .set_name(name='new_name', resolve_duplicate_name=True) >>> second_study_setup.get_name() 'new_name 1' .. >>> study_setup._study.name 'new_name' Trying to set the name to a non-string value >>> study_setup.set_name(name=None) Traceback (most recent call last): ... TypeError: A name of a study ... >>> study_setup.set_name('new_name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotUniqueError: ... Parameters ---------- resolve_duplicate_name: bool Whether to automatically assign a new name when the chosen one is already taken name: str The new name of the study Returns ------- self: StudiesSetup Raises ------ TypeError Raised if the given name is not a string NameNotUniqueError Raised if the given name is not unique """pass
[docs]@abstractmethoddefadd_job(self,parameters_dict:dict)->'StudiesSetup':""" Adds a job from a parameters dict .. admonition:: Deprecated :class: warning `add_job` will be removed in a future MORe release, it is replaced by :meth:`.create_job_setup` which streamlines the job creation process Parameters ---------- parameters_dict: dict The parameters dict consisting of parameter uuid's and parameters to add as a new job to the study Returns ------- self: StudiesSetup """pass
[docs]@abstractmethoddefremove_job(self,job_label:typing.Optional[str]=None)->'StudiesSetup':""" Removes a job from the study .. admonition:: Example :class: note To remove a job by label: .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup() >>> job_setup = study_setup.create_job_setup(job_name='Static Job') >>> job_setup = job_setup.set_general_job_settings_parameter(parameter_name='label', value='first_job') \\ ... .create() \\ ... .set_general_job_settings_parameter(parameter_name='label', value='second_job') \\ ... .create() \\ ... .set_general_job_settings_parameter(parameter_name='label', value='third_job') \\ ... .create() .. >>> isinstance(job_setup, JobCreationContext) True >>> study_setup.remove_job(job_label='second_job') # Remove the second job <more...> .. >>> setup_collections = study_setup._study.get_study_table().study_parameters_setup.setup_collections >>> len(setup_collections) 2 >>> list(setup_collections[0].values())[0].value 'first_job' >>> list(setup_collections[1].values())[0].value 'third_job' Trying to remove a job that does not exist: >>> study_setup.remove_job(job_label='job_that_does_not_exist') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- job_label: str, optional The label of the job to remove, if none is specified then the last job will be removed Returns ------- self: StudiesSetup Raises ------ NameNotFoundError Raised if no job with the given label exists """pass
[docs]@abstractmethoddefcreate_job_setup(self,job_name:str)->JobCreationContext:""" Creates a :class:`~api.simulation.studies.job_setup.JobCreationContext` object for handling job creation for this study .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup() >>> print(study_setup.get_available_job_type_names()) # Check which job type names are available [...] >>> job_setup = study_setup.create_job_setup(job_name='Static Job') # Adds a static job and returns a job creation pipeline object .. >>> isinstance(job_setup, JobCreationContext) True Trying to add a non-existent job type >>> study_setup.create_job_setup(job_name='non-existent-job-type') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- job_name: str The name of the job type to add Returns ------- :class:`~api.simulation.studies.job_setup.JobCreationContext` An object for setting up the job Raises ------ NameNotFoundError Raised if no job type with the given name exists """pass
[docs]@abstractmethoddefget_available_job_type_names(self)->typing.List[str]:""" Get the available job type names .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> study_setup = simulation_setup.create_study_setup() >>> study_setup.get_available_job_type_names() [...] .. >>> list_of_job_type_names = study_setup.get_available_job_type_names() >>> standard_job_type_names = ['Modal Job', 'Static Job', 'Transient Thermal Job', 'Static Job Aggregation', 'Thermo Mechanical Job', 'Transient Mechanical Job', 'FRF Job', 'Thermal Steady State Job'] >>> all(job_name in list_of_job_type_names for job_name in standard_job_type_names) True Returns ------- list of strings The list of available job type names to use with the `create_job_setup` method """pass