Source code for api.postprocessor.simresult_setup

""" Handling of results functionality """

import typing
from abc import abstractmethod, ABC

import more.api.postprocessor.evaluations


[docs] class SimresultSetup(ABC): def __init__(self, simresult): self._simresult = simresult def _get_wrapped_object(self): return self._simresult
[docs] @abstractmethod def get_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) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> simresult_setup.set_name('new_name') <more...> >>> simresult_setup.get_name() 'new_name' Returns ------- name: str The name of the object """ pass
[docs] @abstractmethod def set_name(self, name: str, resolve_duplicate_name: bool = False) -> 'SimresultSetup': """ Changes the name of the simresults .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> append_simresult_with_empty_result(proj, 'other_example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> simresult_setup.set_name('new_name') <more...> >>> second_simresult_setup = postprocessor_setup.get_simresult(name='other_example_simresult') \\ ... .set_name(name='new_name', resolve_duplicate_name=True) >>> second_simresult_setup.get_name() 'new_name 1' .. >>> simresult_setup._simresult.name 'new_name' Trying to set the name to a non-string value >>> simresult_setup.set_name(name=None) Traceback (most recent call last): ... TypeError: ... Setting a non-unique name >>> simresult_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 Returns ------- self: :class:`~api.postprocessor.simresult_setup.SimresultSetup` This object Raises ------ TypeError Raised if the given name is not a string NameNotUniqueError Raised if the given name is not unique """ pass
[docs] @abstractmethod def get_evaluation(self, name: str) -> 'more.api.postprocessor.evaluations.EvaluationSetup': """ Creates a :class:`~api.postprocessor.evaluations.EvaluationSetup` for an already existing evaluation .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist .. >>> _ = simresult_setup.create_evaluation(evaluation_type='Filter evaluation').set_name(name='example_evaluation') >>> evaluation_setup = simresult_setup.get_evaluation(name='example_evaluation') # The evaluation object must already exist .. >>> proj.post.simresults_container.elements[0].evaluation_container.elements[0].name 'example_evaluation' >>> from more.program_interfaces.evaluation_interfaces.evaluation_interface import EvaluationInterface >>> from more.post.simresults import Simresults >>> isinstance(proj.post.simresults_container.elements[0].evaluation_container.elements[0], EvaluationInterface) True >>> evaluation_setup._evaluation == proj.post.simresults_container.elements[0].evaluation_container.elements[0] True >>> simresult_setup.get_evaluation(name='non_existent_name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- name : str The name of the existing evaluation for which to return a :class:`~api.postprocessor.evaluations.EvaluationSetup` Returns ------- :class:`~api.postprocessor.evaluations.EvaluationSetup` A :class:`~api.postprocessor.evaluations.EvaluationSetup` object for the found evaluation object Raises ------ NameNotFoundError Raised if no evaluation with the given name was found """ pass
[docs] @abstractmethod def remove_evaluation(self, name: str) -> 'SimresultSetup': """ Removes an evaluation .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist .. >>> _ = simresult_setup.create_evaluation(evaluation_type='Filter evaluation').set_name(name='example_evaluation') >>> simresult_setup.remove_evaluation(name='example_evaluation') # The evaluation object must already exist <more...> .. >>> len(proj.post.simresults[0].evaluations) 0 >>> simresult_setup.remove_evaluation(name='non_existent_example_evaluation') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- name : str The name of the evaluation object to remove Returns ------- self : :class:`~api.postprocessor.simresult_setup.SimresultSetup` Raises ------ NameNotFoundError Raised if no evaluation with the given name exist """ pass
[docs] @abstractmethod def duplicate_evaluation(self, name: str) -> 'more.api.postprocessor.evaluations.EvaluationSetup': """ Duplicates an evaluation and return the :class:`~api.postprocessor.evaluations.EvaluationSetup` object for the newly created evaluation .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> original_evaluation = simresult_setup.create_evaluation(evaluation_type='Filter evaluation').set_name(name='example_evaluation') >>> duplicate_evaluation = simresult_setup.duplicate_evaluation(name='example_evaluation') >>> print("Automatically assigned name of the duplicate: {}".format(duplicate_evaluation.get_name())) Automatically assigned name of the duplicate: ... .. >>> len(proj.post.simresults_container.elements[0].evaluation_container.elements) 2 >>> simresult_setup.duplicate_evaluation(name='non_existent_example_evaluation') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- name : str The name of the evaluation to duplicate Returns ------- more.api.postprocessor.evaluations.EvaluationSetup The evaluation setup object for the new evaluation Raises ------ NameNotFoundError Raised if no evaluation with the given name exist """ pass
[docs] @abstractmethod def create_evaluation(self, evaluation_type: str) -> 'more.api.postprocessor.evaluations.EvaluationSetup': """ Creates a :class:`~api.postprocessor.evaluations.EvaluationSetup` object for handling evaluations .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> print("Available evaluation types: {}".format(simresult_setup.get_compatible_evaluation_types())) Available evaluation types: [...] >>> evaluation_setup = simresult_setup.create_evaluation(evaluation_type='Custom') .. >>> len(proj.post.simresults_container.elements[0].evaluation_container.elements) 1 >>> simresult_setup.create_evaluation(evaluation_type='non_existent_name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... >>> simresult_setup.create_evaluation(evaluation_type='Transient mechanical') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- evaluation_type: str The name of the evaluation type to add, to check which names are compatible run the :meth:`~get_compatible_evaluation_types` method Returns ------- :class:`~api.postprocessor.evaluations.EvaluationSetup` An object for managing evaluation setup Raises ------ NameNotFoundError Raised if no evaluation with the given type exists or the type is not compatible with the current evaluation """ pass
[docs] @abstractmethod def get_compatible_evaluation_types(self) -> typing.List[str]: """ Gets the names of evaluation types compatible with this simresults .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> print("Available evaluation types: {}".format(simresult_setup.get_compatible_evaluation_types())) Available evaluation types: [...] Returns ------- list of strings Names of compatible evaluation types """ pass
[docs] @abstractmethod def get_evaluation_names(self) -> typing.List[str]: """ Gets the names of existing evaluations .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> print("Available evaluations: {}".format(simresult_setup.get_evaluation_names())) Available evaluations: [...] Returns ------- list of strings Names of existing evaluations """ pass
[docs] @abstractmethod def get_result_names(self) -> typing.List[str]: """ Gets the names of the results, typically those are the job labels assigned in the study .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'example_simresult') >>> simresult_setup = postprocessor_setup.get_simresult(name='example_simresult') # The simresult object must already exist >>> print("Available results: {}".format(simresult_setup.get_result_names())) Available results: [...] Returns ------- list of strings Names of available results """ pass
[docs] @abstractmethod def copy_evaluation_from(self, source_evaluation_setup: 'more.api.postprocessor.evaluations.EvaluationSetup', target_evaluation_name: typing.Optional[str] = None) -> 'more.api.postprocessor.evaluations.EvaluationSetup': """ Copies an evaluation from the given simresult to this one and renames it, returns the newly created evaluation setup .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> postprocessor_setup = api.create_postprocessor_setup() .. >>> from more.api_implementations._api_tools.postprocessor.mocking_utils import append_simresult_with_empty_result >>> append_simresult_with_empty_result(proj, 'source_simresult') >>> append_simresult_with_empty_result(proj, 'target_simresult') >>> # Prepare source simresult and source evaluation for copying, the source simresult must already exist >>> source_simresult = postprocessor_setup.get_simresult(name='source_simresult') >>> source_evaluation = source_simresult.create_evaluation(evaluation_type='Filter evaluation').set_name('source_evaluation') >>> # Prepare target simresult setup, the simresult must already exist >>> target_simresult = postprocessor_setup.get_simresult(name='target_simresult') >>> # Copy source evaluation from source simresult to target simresult >>> target_evaluation = target_simresult.copy_evaluation_from(source_evaluation_setup=source_evaluation, ... target_evaluation_name='target_evaluation') .. >>> len(target_simresult.get_evaluation_names()) 1 >>> # Name not-unique >>> new_target_eval = target_simresult.create_evaluation(evaluation_type='Filter evaluation').set_name(name='non_unique_name') >>> target_evaluation = target_simresult.copy_evaluation_from(source_evaluation_setup=source_evaluation, ... target_evaluation_name='non_unique_name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotUniqueError: ... Parameters ---------- source_evaluation_setup: EvaluationSetup The name of the evaluation in the source simresult to copy target_evaluation_name: Optional[str] Optional name to use for the new evaluation, if not given then the same name will be used as in the source Returns ------- :class:`~api.postprocessor.evaluations.EvaluationSetup` The newly created duplicate evaluation Raises ------ NameNotUniqueError Raised when the provided target name is a duplicate """ pass