diff --git a/src/plaid/bridges/huggingface_bridge.py b/src/plaid/bridges/huggingface_bridge.py index 06c83dcc..6e555fbe 100644 --- a/src/plaid/bridges/huggingface_bridge.py +++ b/src/plaid/bridges/huggingface_bridge.py @@ -42,13 +42,14 @@ from huggingface_hub import HfApi, hf_hub_download, snapshot_download from pydantic import ValidationError -from plaid import Dataset, ProblemDefinition, Sample +from plaid import Dataset, ProblemDefinition, Sample, problem_definition from plaid.containers.features import SampleFeatures from plaid.types import IndexType from plaid.utils.cgns_helper import ( flatten_cgns_tree, unflatten_cgns_tree, ) +from plaid.containers import FeatureIdentifier # ------------------------------------------------------------------------------ @@ -696,18 +697,29 @@ def huggingface_description_to_problem_definition( """ description = {} if description == "" else description problem_definition = ProblemDefinition() + #todo for func, key in [ (problem_definition.set_task, "task"), (problem_definition.set_split, "split"), - (problem_definition.add_input_scalars_names, "in_scalars_names"), - (problem_definition.add_output_scalars_names, "out_scalars_names"), - (problem_definition.add_input_fields_names, "in_fields_names"), - (problem_definition.add_output_fields_names, "out_fields_names"), - (problem_definition.add_input_meshes_names, "in_meshes_names"), - (problem_definition.add_output_meshes_names, "out_meshes_names"), ]: try: - func(description[key]) + func([ description[key] ]) + except KeyError: + logger.error(f"Could not retrieve key:'{key}' from description") + pass + + + for func, ftype, key in [ + (problem_definition.add_in_features_identifiers, "scalar","in_scalars_names"), + (problem_definition.add_out_feature_identifier, "scalar","out_scalars_names"), + (problem_definition.add_in_features_identifiers, "field","in_fields_names"), + (problem_definition.add_out_feature_identifier, "field","out_fields_names"), + (problem_definition.add_in_features_identifiers, "mesh","in_meshes_names"), + (problem_definition.add_out_feature_identifier, "mesh","out_meshes_names"), + + ]: + try: + func([ FeatureIdentifier({"type":ftype, "name":name }) for name in description[key] ]) except KeyError: logger.error(f"Could not retrieve key:'{key}' from description") pass diff --git a/src/plaid/containers/dataset.py b/src/plaid/containers/dataset.py index d4833b2e..dbf0c87f 100644 --- a/src/plaid/containers/dataset.py +++ b/src/plaid/containers/dataset.py @@ -37,7 +37,7 @@ from plaid.containers.utils import check_features_size_homogeneity from plaid.types import Array, Feature from plaid.utils.base import DeprecatedError, ShapeError, generate_random_ASCII -from plaid.utils.deprecation import deprecated, deprecated_argument +from plaid.utils.deprecation import deprecated logger = logging.getLogger(__name__) @@ -65,7 +65,6 @@ def _process_sample(path: Union[str, Path]) -> tuple: # pragma: no cover class Dataset(object): """A set of samples, and optionnaly some other informations about the Dataset.""" - @deprecated_argument("directory_path", "path", version="0.1.8", removal="0.2.0") def __init__( self, path: Optional[Union[str, Path]] = None, @@ -705,19 +704,6 @@ def extract_dataset_from_identifier( dataset.add_sample(sample=extracted_sample, id=id) return dataset - @deprecated( - "`Dataset.from_features_identifier(...)` is deprecated, use instead `Dataset.extract_dataset_from_identifier(...)`", - version="0.1.8", - removal="0.2", - ) - def from_features_identifier( - self, - feature_identifiers: Union[FeatureIdentifier, list[FeatureIdentifier]], - ) -> Self: - """DEPRECATED: Use :meth:`Dataset.extract_dataset_from_identifier` instead.""" - return self.extract_dataset_from_identifier( - feature_identifiers - ) # pragma: no cover def get_tabular_from_homogeneous_identifiers( self, @@ -829,22 +815,6 @@ def add_features_from_tabular( return dataset - @deprecated( - "`Dataset.from_tabular(...)` is deprecated, use instead `Dataset.add_features_from_tabular(...)`", - version="0.1.8", - removal="0.2", - ) - def from_tabular( - self, - tabular: Array, - feature_identifiers: Union[FeatureIdentifier, list[FeatureIdentifier]], - restrict_to_features: bool = True, - ) -> Self: - """DEPRECATED: Use :meth:`Dataset.add_features_from_tabular` instead.""" - return self.add_features_from_tabular( - tabular, feature_identifiers, restrict_to_features - ) # pragma: no cover - # -------------------------------------------------------------------------# def add_info(self, cat_key: str, info_key: str, info: str) -> None: """Add information to the :class:`Dataset `, overwriting existing information if there's a conflict. @@ -1085,16 +1055,6 @@ def merge_dataset_by_features(cls, datasets_list: list[Self]) -> Self: merged_dataset = merged_dataset.merge_features(dataset, in_place=False) return merged_dataset - @deprecated_argument("directory_path", "path", version="0.1.8", removal="0.2.0") - @deprecated( - "`Dataset.save(...)` is deprecated, use instead `Dataset.save_to_file(...)`", - version="0.1.10", - removal="0.2.0", - ) - def save(self, path: Union[str, Path]) -> None: - """DEPRECATED: use :meth:`Dataset.save_to_file` instead.""" - self.save_to_file(path) - def save_to_file(self, path: Union[str, Path]) -> None: """Saves the data set to a TAR (Tape Archive) file. @@ -1372,19 +1332,6 @@ def check_feature_completeness(self) -> str: return report @classmethod - @deprecated( - "`Dataset.from_list_of_samples(samples)` is deprecated, use instead `Dataset(samples=samples)`", - version="0.1.8", - removal="0.2.0", - ) - def from_list_of_samples( - cls, list_of_samples: list[Sample], ids: Optional[list[int]] = None - ) -> Self: - """DEPRECATED: use `Dataset(samples=..., sample_ids=...)` instead.""" - return cls(samples=list_of_samples, sample_ids=ids) - - @classmethod - @deprecated_argument("fname", "path", version="0.1.8", removal="0.2.0") def load_from_file( cls, path: Union[str, Path], verbose: bool = False, processes_number: int = 0 ) -> Self: @@ -1404,7 +1351,6 @@ def load_from_file( return instance @classmethod - @deprecated_argument("fname", "path", version="0.1.8", removal="0.2.0") def load_from_dir( cls, path: Union[str, Path], @@ -1430,7 +1376,6 @@ def load_from_dir( ) return instance - @deprecated_argument("fname", "path", version="0.1.8", removal="0.2.0") def load( self, path: Union[str, Path], verbose: bool = False, processes_number: int = 0 ) -> None: @@ -1479,7 +1424,6 @@ def load( ) # -------------------------------------------------------------------------# - @deprecated_argument("save_dir", "path", version="0.1.8", removal="0.2.0") def add_to_dir( self, sample: Sample, @@ -1538,15 +1482,6 @@ def add_to_dir( sample_dname = samples_dir / f"sample_{i_sample:09d}" sample.save_to_dir(sample_dname) - @deprecated( - "`Dataset._save_to_dir_(path)` is deprecated, use instead `Dataset.save_to_dir(path)`", - version="0.1.10", - removal="0.2.0", - ) - def _save_to_dir_(self, path: Union[str, Path], verbose: bool = False) -> None: - """DEPRECATED: use :meth:`Dataset.save_to_dir` instead.""" - self.save_to_dir(path, verbose=verbose) - def _load_from_dir_( self, path: Union[str, Path], @@ -1651,13 +1586,6 @@ def update(self, *a): if len(self) == 0: # pragma: no cover print("Warning: dataset contains no sample") - @staticmethod - def _load_number_of_samples_(_path: Union[str, Path]) -> int: - """DEPRECATED: use :meth:`plaid.get_number_of_samples ` instead.""" - raise DeprecatedError( - 'use instead: plaid.get_number_of_samples("path-to-my-dataset")' - ) - # -------------------------------------------------------------------------# def set_samples(self, samples: dict[int, Sample]) -> None: """Set the samples of the data set, overwriting the existing ones. diff --git a/src/plaid/containers/feature_identifier.py b/src/plaid/containers/feature_identifier.py index f76820f9..68e0d208 100644 --- a/src/plaid/containers/feature_identifier.py +++ b/src/plaid/containers/feature_identifier.py @@ -35,3 +35,41 @@ def __lt__(self, other: "FeatureIdentifier") -> bool: bool: True if this feature identifier is less than the other, False otherwise. """ return sorted(self.items()) < sorted(other.items()) + + @classmethod + def from_string(cls, string_identifier: str) -> "FeatureIdentifier": + """Create a FeatureIdentifier from a string representation. + + Args: + string_identifier (str): The string representation of the feature identifier. + + The `string_identifier` must follow the format: + ":://.../" + + Supported feature types: + - "scalar": expects 1 detail → ["name"], + - "field": up to 5 details → ["name", "location", "zone_name", "base_name", "time"], + - "nodes": up to 3 details → ["zone_name", "base_name", "time"], + + Returns: + FeatureIdentifier + + + Warnings: + - If "time" is present in a field/nodes identifier, it is cast to float. + - `name` is required for scalar and field features. + """ + splitted_identifier = string_identifier.split("::") + + feature_type = splitted_identifier[0] + feature_details = [detail for detail in splitted_identifier[1].split("/")] + + from plaid.constants import AUTHORIZED_FEATURE_TYPES, AUTHORIZED_FEATURE_INFOS + + assert feature_type in AUTHORIZED_FEATURE_TYPES, "feature_type not known" + + arg_names = AUTHORIZED_FEATURE_INFOS[feature_type] + assert len(arg_names) >= len(feature_details), "Too much details provided" + data = {"type": feature_type} + data.update({ arg_name : feature_detail for arg_name, feature_detail in zip(arg_names, feature_details)}) + return FeatureIdentifier(data) diff --git a/src/plaid/containers/features.py b/src/plaid/containers/features.py index 86fd54ac..58d72ada 100644 --- a/src/plaid/containers/features.py +++ b/src/plaid/containers/features.py @@ -22,7 +22,6 @@ ) from plaid.types import Array, CGNSNode, CGNSTree, Field from plaid.utils import cgns_helper as CGH -from plaid.utils.deprecation import deprecated logger = logging.getLogger(__name__) @@ -129,15 +128,6 @@ def get_all_time_values(self) -> list[float]: """ return list(self.data.keys()) - @deprecated( - "`get_all_mesh_times()` is deprecated, use instead `get_all_time_values()`", - version="0.1.11", - removal="0.2.0", - ) - def get_all_mesh_times(self) -> list[float]: - """DEPRECATED: Use :meth:`get_all_time_values` instead.""" - return self.get_all_time_values() # pragma: no cover - def init_tree(self, time: Optional[float] = None) -> CGNSTree: """Initialize a CGNS tree structure at a specified time step or create a new one if it doesn't exist. diff --git a/src/plaid/containers/sample.py b/src/plaid/containers/sample.py index c3913ce3..8fc4dac4 100644 --- a/src/plaid/containers/sample.py +++ b/src/plaid/containers/sample.py @@ -45,7 +45,6 @@ ) from plaid.utils import cgns_helper as CGH from plaid.utils.base import delegate_methods, safe_len -from plaid.utils.deprecation import deprecated logger = logging.getLogger(__name__) @@ -581,20 +580,6 @@ def extract_sample_from_identifier( return sample - @deprecated( - "`Dataset.from_features_identifier(...)` is deprecated, use instead `Dataset.extract_sample_from_identifier(...)`", - version="0.1.8", - removal="0.2", - ) - def from_features_identifier( - self, - feature_identifiers: Union[FeatureIdentifier, list[FeatureIdentifier]], - ) -> Self: - """DEPRECATED: Use :meth:`Dataset.extract_sample_from_identifier` instead.""" - return self.extract_sample_from_identifier( - feature_identifiers - ) # pragma: no cover - def merge_features(self, sample: Self, in_place: bool = False) -> Self: """Merge features from another sample into the current sample. @@ -639,18 +624,6 @@ def merge_features(self, sample: Self, in_place: bool = False) -> Self: in_place=in_place, ) - # -------------------------------------------------------------------------# - @deprecated( - "`Sample.save(...)` is deprecated, use instead `Sample.save_to_dir(...)`", - version="0.1.8", - removal="0.2", - ) - def save( - self, path: Union[str, Path], overwrite: bool = False, memory_safe: bool = False - ) -> None: - """DEPRECATED: use :meth:`Sample.save_to_dir` instead.""" - self.save_to_dir(path, overwrite=overwrite, memory_safe=memory_safe) - # -------------------------------------------------------------------------# def save_to_dir( self, path: Union[str, Path], overwrite: bool = False, memory_safe: bool = False @@ -760,47 +733,6 @@ def load(self, path: Union[str, Path]) -> None: (self.features.data[time],) = (tree,) - old_scalars_file = path / "scalars.csv" - if old_scalars_file.is_file(): - self._load_old_scalars(old_scalars_file) - - old_time_series_files = list(path.glob("time_series_*.csv")) - if len(old_time_series_files) > 0: - self._load_old_time_series(old_time_series_files) - - @deprecated( - reason="This Sample was written with plaid<=0.1.9, save it with plaid>=0.1.10 to have all features embedded in the CGNS tree", - version="0.1.10", - removal="0.2.0", - ) - def _load_old_scalars(self, scalars_file: Path): - names = np.loadtxt(scalars_file, dtype=str, max_rows=1, delimiter=",").reshape( - (-1,) - ) - scalars = np.loadtxt( - scalars_file, dtype=float, skiprows=1, delimiter="," - ).reshape((-1,)) - for name, value in zip(names, scalars): - self.add_scalar(name, value) - - @deprecated( - reason="This Sample was written with plaid<=0.1.9, save it with plaid>=0.1.10 to have all features embedded in the CGNS tree", - version="0.1.10", - removal="0.2.0", - ) - def _load_old_time_series(self, time_series_files: list[Path]): - for ts_fname in time_series_files: - names = np.loadtxt(ts_fname, dtype=str, max_rows=1, delimiter=",").reshape( - (-1,) - ) - assert names[0] == "t" - times_and_val = np.loadtxt(ts_fname, dtype=float, skiprows=1, delimiter=",") - for i in range(times_and_val.shape[0]): - self.add_global( - name=names[1], - global_array=times_and_val[i, 1], - time=times_and_val[i, 0], - ) # # -------------------------------------------------------------------------# def __str__(self) -> str: diff --git a/src/plaid/pipelines/sklearn_block_wrappers.py b/src/plaid/pipelines/sklearn_block_wrappers.py index 3b5920a9..7866e391 100644 --- a/src/plaid/pipelines/sklearn_block_wrappers.py +++ b/src/plaid/pipelines/sklearn_block_wrappers.py @@ -249,7 +249,7 @@ def predict(self, dataset: Dataset) -> Dataset: dataset_predicted = Dataset.merge_dataset_by_features( [ - dataset.from_tabular( + dataset.add_features_from_tabular( y[ :, None, @@ -262,9 +262,7 @@ def predict(self, dataset: Dataset) -> Dataset: for i_feat, feat_ids in enumerate(self.out_features_identifiers_) ] ) - # dataset_predicted = dataset.add_features_from_tabular( - # y, self.out_features_identifiers_, restrict_to_features=False - # ) + dataset_predicted = dataset.merge_features(dataset_predicted) return dataset_predicted diff --git a/src/plaid/post/bisect.py b/src/plaid/post/bisect.py index 0832514d..347b5d46 100644 --- a/src/plaid/post/bisect.py +++ b/src/plaid/post/bisect.py @@ -37,7 +37,7 @@ def prepare_datasets( assert ref_problem == pred_problem, "Reference and predicted dataset scalars differ" n_samples = len(ref_dataset) - out_scalars_names = problem_definition.get_output_scalars_names() + out_scalars_names = [f["name"] for f in problem_definition.get_out_features_identifiers()] ref_out_scalars = {} pred_out_scalars = {} diff --git a/src/plaid/problem_definition.py b/src/plaid/problem_definition.py index 78d3c713..f4bc5f35 100644 --- a/src/plaid/problem_definition.py +++ b/src/plaid/problem_definition.py @@ -48,7 +48,6 @@ class ProblemDefinition(object): def __init__( self, path: Optional[Union[str, Path]] = None, - directory_path: Optional[Union[str, Path]] = None, ) -> None: """Initialize an empty :class:`ProblemDefinition `. @@ -56,7 +55,6 @@ def __init__( Args: path (Union[str,Path], optional): The path from which to load PLAID problem definition files. - directory_path (Union[str,Path], optional): Deprecated, use `path` instead. Example: .. code-block:: python @@ -80,29 +78,18 @@ def __init__( self.in_features_identifiers: Sequence[Union[str, FeatureIdentifier]] = [] self.out_features_identifiers: Sequence[Union[str, FeatureIdentifier]] = [] self.constant_features_identifiers: list[str] = [] - self.in_scalars_names: list[str] = [] - self.out_scalars_names: list[str] = [] - self.in_timeseries_names: list[str] = [] - self.out_timeseries_names: list[str] = [] - self.in_fields_names: list[str] = [] - self.out_fields_names: list[str] = [] - self.in_meshes_names: list[str] = [] - self.out_meshes_names: list[str] = [] + #self.in_scalars_names: list[str] = [] + #self.out_scalars_names: list[str] = [] + #self.in_timeseries_names: list[str] = [] + #self.out_timeseries_names: list[str] = [] + #self.in_fields_names: list[str] = [] + #self.out_fields_names: list[str] = [] + #self.in_meshes_names: list[str] = [] + #self.out_meshes_names: list[str] = [] self._split: Optional[dict[str, IndexType]] = None self._train_split: Optional[dict[str, dict[str, IndexType]]] = None self._test_split: Optional[dict[str, dict[str, IndexType]]] = None - if directory_path is not None: - if path is not None: - raise ValueError( - "Arguments `path` and `directory_path` cannot be both set. Use only `path` as `directory_path` is deprecated." - ) - else: - path = directory_path - logger.warning( - "DeprecationWarning: 'directory_path' is deprecated, use 'path' instead." - ) - if path is not None: path = Path(path) self._load_from_dir_(path) @@ -652,187 +639,187 @@ def filter_constant_features_identifiers(self, identifiers: list[str]) -> list[s ) # -------------------------------------------------------------------------# - @deprecated( - "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_input_scalars_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. - - Get the input scalars names of the problem. - - Returns: - list[str]: A list of input feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - input_scalars_names = problem.get_input_scalars_names() - print(input_scalars_names) - >>> ['omega', 'pressure'] - """ - return self.in_scalars_names - - @deprecated( - "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_scalars_names(self, inputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. - - Add input scalars names to the problem. - - Args: - inputs (list[str]): A list of input feature names to add. - - Raises: - ValueError: If some :code:`inputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_scalars_names = ['omega', 'pressure'] - problem.add_input_scalars_names(input_scalars_names) - """ - if not (len(set(inputs)) == len(inputs)): - raise ValueError("Some inputs have same names") - for input in inputs: - self.add_input_scalar_name(input) - - @deprecated( - "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_scalar_name(self, input: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. - - Add an input scalar name to the problem. - - Args: - input (str): The name of the input feature to add. - - Raises: - ValueError: If the specified input feature is already in the list of inputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_name = 'pressure' - problem.add_input_scalar_name(input_name) - """ - if input in self.in_scalars_names: - raise ValueError(f"{input} is already in self.in_scalars_names") - self.in_scalars_names.append(input) - self.in_scalars_names.sort() - - @deprecated( - "use `filter_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def filter_input_scalars_names(self, names: list[str]) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.filter_in_features_identifiers` instead. - - Filter and get input scalars features corresponding to a list of names. - - Args: - names (list[str]): A list of names for which to retrieve corresponding input features. - - Returns: - list[str]: A sorted list of input feature names or categories corresponding to the provided names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - scalars_names = ['omega', 'pressure', 'temperature'] - input_features = problem.filter_input_scalars_names(scalars_names) - print(input_features) - >>> ['omega', 'pressure'] - """ - return sorted(set(names).intersection(self.get_input_scalars_names())) + # @deprecated( + # "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_input_scalars_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. + + # Get the input scalars names of the problem. + + # Returns: + # list[str]: A list of input feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # input_scalars_names = problem.get_input_scalars_names() + # print(input_scalars_names) + # >>> ['omega', 'pressure'] + # """ + # return self.in_scalars_names + + # @deprecated( + # "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_scalars_names(self, inputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. + + # Add input scalars names to the problem. + + # Args: + # inputs (list[str]): A list of input feature names to add. + + # Raises: + # ValueError: If some :code:`inputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_scalars_names = ['omega', 'pressure'] + # problem.add_input_scalars_names(input_scalars_names) + # """ + # if not (len(set(inputs)) == len(inputs)): + # raise ValueError("Some inputs have same names") + # for input in inputs: + # self.add_input_scalar_name(input) + + # @deprecated( + # "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_scalar_name(self, input: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. + + # Add an input scalar name to the problem. + + # Args: + # input (str): The name of the input feature to add. + + # Raises: + # ValueError: If the specified input feature is already in the list of inputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_name = 'pressure' + # problem.add_input_scalar_name(input_name) + # """ + # if input in self.in_scalars_names: + # raise ValueError(f"{input} is already in self.in_scalars_names") + # self.in_scalars_names.append(input) + # self.in_scalars_names.sort() + + # @deprecated( + # "use `filter_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def filter_input_scalars_names(self, names: list[str]) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.filter_in_features_identifiers` instead. + + # Filter and get input scalars features corresponding to a list of names. + + # Args: + # names (list[str]): A list of names for which to retrieve corresponding input features. + + # Returns: + # list[str]: A sorted list of input feature names or categories corresponding to the provided names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # scalars_names = ['omega', 'pressure', 'temperature'] + # input_features = problem.filter_input_scalars_names(scalars_names) + # print(input_features) + # >>> ['omega', 'pressure'] + # """ + # return sorted(set(names).intersection(self.get_input_scalars_names())) # -------------------------------------------------------------------------# - @deprecated( - "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_output_scalars_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. - - Get the output scalars names of the problem. - - Returns: - list[str]: A list of output feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - outputs_names = problem.get_output_scalars_names() - print(outputs_names) - >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - """ - return self.out_scalars_names - - @deprecated( - "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_scalars_names(self, outputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. - - Add output scalars names to the problem. - - Args: - outputs (list[str]): A list of output feature names to add. - - Raises: - ValueError: if some :code:`outputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_scalars_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - problem.add_output_scalars_names(output_scalars_names) - """ - if not (len(set(outputs)) == len(outputs)): - raise ValueError("Some outputs have same names") - for output in outputs: - self.add_output_scalar_name(output) - - @deprecated( - "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_scalar_name(self, output: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. - - Add an output scalar name to the problem. - - Args: - output (str): The name of the output feature to add. - - Raises: - ValueError: If the specified output feature is already in the list of outputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_scalars_names = 'pressure' - problem.add_output_scalar_name(output_scalars_names) - """ - if output in self.out_scalars_names: - raise ValueError(f"{output} is already in self.out_scalars_names") - self.out_scalars_names.append(output) - self.in_scalars_names.sort() + # @deprecated( + # "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_output_scalars_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. + + # Get the output scalars names of the problem. + + # Returns: + # list[str]: A list of output feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # outputs_names = problem.get_output_scalars_names() + # print(outputs_names) + # >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # """ + # return self.out_scalars_names + + # @deprecated( + # "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_scalars_names(self, outputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. + + # Add output scalars names to the problem. + + # Args: + # outputs (list[str]): A list of output feature names to add. + + # Raises: + # ValueError: if some :code:`outputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_scalars_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # problem.add_output_scalars_names(output_scalars_names) + # """ + # if not (len(set(outputs)) == len(outputs)): + # raise ValueError("Some outputs have same names") + # for output in outputs: + # self.add_output_scalar_name(output) + + # @deprecated( + # "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_scalar_name(self, output: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. + + # Add an output scalar name to the problem. + + # Args: + # output (str): The name of the output feature to add. + + # Raises: + # ValueError: If the specified output feature is already in the list of outputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_scalars_names = 'pressure' + # problem.add_output_scalar_name(output_scalars_names) + # """ + # if output in self.out_scalars_names: + # raise ValueError(f"{output} is already in self.out_scalars_names") + # self.out_scalars_names.append(output) + # self.in_scalars_names.sort() def filter_output_scalars_names(self, names: list[str]) -> list[str]: """Filter and get output features corresponding to a list of names. @@ -854,185 +841,185 @@ def filter_output_scalars_names(self, names: list[str]) -> list[str]: print(output_features) >>> ['in_massflow'] """ - return sorted(set(names).intersection(self.get_output_scalars_names())) + return sorted(set(names).intersection([f["name"] for f in self.get_out_features_identifiers()])) # -------------------------------------------------------------------------# - @deprecated( - "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_input_fields_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. - - Get the input fields names of the problem. - - Returns: - list[str]: A list of input feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - input_fields_names = problem.get_input_fields_names() - print(input_fields_names) - >>> ['omega', 'pressure'] - """ - return self.in_fields_names - - @deprecated( - "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_fields_names(self, inputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. - - Add input fields names to the problem. - - Args: - inputs (list[str]): A list of input feature names to add. - - Raises: - ValueError: If some :code:`inputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_fields_names = ['omega', 'pressure'] - problem.add_input_fields_names(input_fields_names) - """ - if not (len(set(inputs)) == len(inputs)): - raise ValueError("Some inputs have same names") - for input in inputs: - self.add_input_field_name(input) - - @deprecated( - "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_field_name(self, input: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. - - Add an input field name to the problem. - - Args: - input (str): The name of the input feature to add. - - Raises: - ValueError: If the specified input feature is already in the list of inputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_name = 'pressure' - problem.add_input_field_name(input_name) - """ - if input in self.in_fields_names: - raise ValueError(f"{input} is already in self.in_fields_names") - self.in_fields_names.append(input) - self.in_fields_names.sort() - - def filter_input_fields_names(self, names: list[str]) -> list[str]: - """Filter and get input fields features corresponding to a list of names. - - Args: - names (list[str]): A list of names for which to retrieve corresponding input features. - - Returns: - list[str]: A sorted list of input feature names or categories corresponding to the provided names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - input_fields_names = ['omega', 'pressure', 'temperature'] - input_features = problem.filter_input_fields_names(input_fields_names) - print(input_features) - >>> ['omega', 'pressure'] - """ - return sorted(set(names).intersection(self.get_input_fields_names())) + # @deprecated( + # "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_input_fields_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. + + # Get the input fields names of the problem. + + # Returns: + # list[str]: A list of input feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # input_fields_names = problem.get_input_fields_names() + # print(input_fields_names) + # >>> ['omega', 'pressure'] + # """ + # return self.in_fields_names + + # @deprecated( + # "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_fields_names(self, inputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. + + # Add input fields names to the problem. + + # Args: + # inputs (list[str]): A list of input feature names to add. + + # Raises: + # ValueError: If some :code:`inputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_fields_names = ['omega', 'pressure'] + # problem.add_input_fields_names(input_fields_names) + # """ + # if not (len(set(inputs)) == len(inputs)): + # raise ValueError("Some inputs have same names") + # for input in inputs: + # self.add_input_field_name(input) + + # @deprecated( + # "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_field_name(self, input: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. + + # Add an input field name to the problem. + + # Args: + # input (str): The name of the input feature to add. + + # Raises: + # ValueError: If the specified input feature is already in the list of inputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_name = 'pressure' + # problem.add_input_field_name(input_name) + # """ + # if input in self.in_fields_names: + # raise ValueError(f"{input} is already in self.in_fields_names") + # self.in_fields_names.append(input) + # self.in_fields_names.sort() + + # def filter_input_fields_names(self, names: list[str]) -> list[str]: + # """Filter and get input fields features corresponding to a list of names. + + # Args: + # names (list[str]): A list of names for which to retrieve corresponding input features. + + # Returns: + # list[str]: A sorted list of input feature names or categories corresponding to the provided names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # input_fields_names = ['omega', 'pressure', 'temperature'] + # input_features = problem.filter_input_fields_names(input_fields_names) + # print(input_features) + # >>> ['omega', 'pressure'] + # """ + # return sorted(set(names).intersection(self.get_input_fields_names())) # -------------------------------------------------------------------------# - @deprecated( - "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_output_fields_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. - - Get the output fields names of the problem. - - Returns: - list[str]: A list of output feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - outputs_names = problem.get_output_fields_names() - print(outputs_names) - >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - """ - return self.out_fields_names - - @deprecated( - "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_fields_names(self, outputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. - - Add output fields names to the problem. - - Args: - outputs (list[str]): A list of output feature names to add. - - Raises: - ValueError: if some :code:`outputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_fields_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - problem.add_output_fields_names(output_fields_names) - """ - if not (len(set(outputs)) == len(outputs)): - raise ValueError("Some outputs have same names") - for output in outputs: - self.add_output_field_name(output) - - @deprecated( - "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_field_name(self, output: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. - - Add an output field name to the problem. - - Args: - output (str): The name of the output feature to add. - - Raises: - ValueError: If the specified output feature is already in the list of outputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_fields_names = 'pressure' - problem.add_output_field_name(output_fields_names) - """ - if output in self.out_fields_names: - raise ValueError(f"{output} is already in self.out_fields_names") - self.out_fields_names.append(output) - self.out_fields_names.sort() + # @deprecated( + # "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_output_fields_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. + + # Get the output fields names of the problem. + + # Returns: + # list[str]: A list of output feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # outputs_names = problem.get_output_fields_names() + # print(outputs_names) + # >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # """ + # return self.out_fields_names + + # @deprecated( + # "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_fields_names(self, outputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. + + # Add output fields names to the problem. + + # Args: + # outputs (list[str]): A list of output feature names to add. + + # Raises: + # ValueError: if some :code:`outputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_fields_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # problem.add_output_fields_names(output_fields_names) + # """ + # if not (len(set(outputs)) == len(outputs)): + # raise ValueError("Some outputs have same names") + # for output in outputs: + # self.add_output_field_name(output) + + # @deprecated( + # "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_field_name(self, output: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. + + # Add an output field name to the problem. + + # Args: + # output (str): The name of the output feature to add. + + # Raises: + # ValueError: If the specified output feature is already in the list of outputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_fields_names = 'pressure' + # problem.add_output_field_name(output_fields_names) + # """ + # if output in self.out_fields_names: + # raise ValueError(f"{output} is already in self.out_fields_names") + # self.out_fields_names.append(output) + # self.out_fields_names.sort() def filter_output_fields_names(self, names: list[str]) -> list[str]: """Filter and get output features corresponding to a list of names. @@ -1057,182 +1044,182 @@ def filter_output_fields_names(self, names: list[str]) -> list[str]: return sorted(set(names).intersection(self.get_output_fields_names())) # -------------------------------------------------------------------------# - @deprecated( - "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_input_timeseries_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. - - Get the input timeseries names of the problem. - - Returns: - list[str]: A list of input feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - input_timeseries_names = problem.get_input_timeseries_names() - print(input_timeseries_names) - >>> ['omega', 'pressure'] - """ - return self.in_timeseries_names - - @deprecated( - "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_timeseries_names(self, inputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. - - Add input timeseries names to the problem. - - Args: - inputs (list[str]): A list of input feature names to add. - - Raises: - ValueError: If some :code:`inputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_timeseries_names = ['omega', 'pressure'] - problem.add_input_timeseries_names(input_timeseries_names) - """ - if not (len(set(inputs)) == len(inputs)): - raise ValueError("Some inputs have same names") - for input in inputs: - self.add_input_timeseries_name(input) - - @deprecated( - "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_timeseries_name(self, input: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. - - Add an input timeseries name to the problem. - - Args: - input (str): The name of the input feature to add. - - Raises: - ValueError: If the specified input feature is already in the list of inputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_name = 'pressure' - problem.add_input_timeseries_name(input_name) - """ - if input in self.in_timeseries_names: - raise ValueError(f"{input} is already in self.in_timeseries_names") - self.in_timeseries_names.append(input) - self.in_timeseries_names.sort() - - def filter_input_timeseries_names(self, names: list[str]) -> list[str]: - """Filter and get input timeseries features corresponding to a list of names. - - Args: - names (list[str]): A list of names for which to retrieve corresponding input features. - - Returns: - list[str]: A sorted list of input feature names or categories corresponding to the provided names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - input_timeseries_names = ['omega', 'pressure', 'temperature'] - input_features = problem.filter_input_timeseries_names(input_timeseries_names) - print(input_features) - >>> ['omega', 'pressure'] - """ - return sorted(set(names).intersection(self.get_input_timeseries_names())) + # @deprecated( + # "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_input_timeseries_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. + + # Get the input timeseries names of the problem. + + # Returns: + # list[str]: A list of input feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # input_timeseries_names = problem.get_input_timeseries_names() + # print(input_timeseries_names) + # >>> ['omega', 'pressure'] + # """ + # return self.in_timeseries_names + + # @deprecated( + # "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_timeseries_names(self, inputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. + + # Add input timeseries names to the problem. + + # Args: + # inputs (list[str]): A list of input feature names to add. + + # Raises: + # ValueError: If some :code:`inputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_timeseries_names = ['omega', 'pressure'] + # problem.add_input_timeseries_names(input_timeseries_names) + # """ + # if not (len(set(inputs)) == len(inputs)): + # raise ValueError("Some inputs have same names") + # for input in inputs: + # self.add_input_timeseries_name(input) + + # @deprecated( + # "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_timeseries_name(self, input: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. + + # Add an input timeseries name to the problem. + + # Args: + # input (str): The name of the input feature to add. + + # Raises: + # ValueError: If the specified input feature is already in the list of inputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_name = 'pressure' + # problem.add_input_timeseries_name(input_name) + # """ + # if input in self.in_timeseries_names: + # raise ValueError(f"{input} is already in self.in_timeseries_names") + # self.in_timeseries_names.append(input) + # self.in_timeseries_names.sort() + + # def filter_input_timeseries_names(self, names: list[str]) -> list[str]: + # """Filter and get input timeseries features corresponding to a list of names. + + # Args: + # names (list[str]): A list of names for which to retrieve corresponding input features. + + # Returns: + # list[str]: A sorted list of input feature names or categories corresponding to the provided names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # input_timeseries_names = ['omega', 'pressure', 'temperature'] + # input_features = problem.filter_input_timeseries_names(input_timeseries_names) + # print(input_features) + # >>> ['omega', 'pressure'] + # """ + # return sorted(set(names).intersection(self.get_input_timeseries_names())) # -------------------------------------------------------------------------# - @deprecated( - "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_output_timeseries_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. - - Get the output timeseries names of the problem. - - Returns: - list[str]: A list of output feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - outputs_names = problem.get_output_timeseries_names() - print(outputs_names) - >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - """ - return self.out_timeseries_names - - @deprecated( - "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_timeseries_names(self, outputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. - - Add output timeseries names to the problem. - - Args: - outputs (list[str]): A list of output feature names to add. - - Raises: - ValueError: if some :code:`outputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_timeseries_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - problem.add_output_timeseries_names(output_timeseries_names) - """ - if not (len(set(outputs)) == len(outputs)): - raise ValueError("Some outputs have same names") - for output in outputs: - self.add_output_timeseries_name(output) - - @deprecated( - "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_timeseries_name(self, output: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. - - Add an output timeseries name to the problem. - - Args: - output (str): The name of the output feature to add. - - Raises: - ValueError: If the specified output feature is already in the list of outputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_timeseries_names = 'pressure' - problem.add_output_timeseries_name(output_timeseries_names) - """ - if output in self.out_timeseries_names: - raise ValueError(f"{output} is already in self.out_timeseries_names") - self.out_timeseries_names.append(output) - self.in_timeseries_names.sort() + # @deprecated( + # "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_output_timeseries_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. + + # Get the output timeseries names of the problem. + + # Returns: + # list[str]: A list of output feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # outputs_names = problem.get_output_timeseries_names() + # print(outputs_names) + # >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # """ + # return self.out_timeseries_names + + # @deprecated( + # "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_timeseries_names(self, outputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. + + # Add output timeseries names to the problem. + + # Args: + # outputs (list[str]): A list of output feature names to add. + + # Raises: + # ValueError: if some :code:`outputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_timeseries_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # problem.add_output_timeseries_names(output_timeseries_names) + # """ + # if not (len(set(outputs)) == len(outputs)): + # raise ValueError("Some outputs have same names") + # for output in outputs: + # self.add_output_timeseries_name(output) + + # @deprecated( + # "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_timeseries_name(self, output: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. + + # Add an output timeseries name to the problem. + + # Args: + # output (str): The name of the output feature to add. + + # Raises: + # ValueError: If the specified output feature is already in the list of outputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_timeseries_names = 'pressure' + # problem.add_output_timeseries_name(output_timeseries_names) + # """ + # if output in self.out_timeseries_names: + # raise ValueError(f"{output} is already in self.out_timeseries_names") + # self.out_timeseries_names.append(output) + # self.in_timeseries_names.sort() def filter_output_timeseries_names(self, names: list[str]) -> list[str]: """Filter and get output features corresponding to a list of names. @@ -1257,82 +1244,82 @@ def filter_output_timeseries_names(self, names: list[str]) -> list[str]: return sorted(set(names).intersection(self.get_output_timeseries_names())) # -------------------------------------------------------------------------# - @deprecated( - "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_input_meshes_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. - - Get the input meshes names of the problem. - - Returns: - list[str]: A list of input feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - input_meshes_names = problem.get_input_meshes_names() - print(input_meshes_names) - >>> ['omega', 'pressure'] - """ - return self.in_meshes_names - - @deprecated( - "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_meshes_names(self, inputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. - - Add input meshes names to the problem. - - Args: - inputs (list[str]): A list of input feature names to add. - - Raises: - ValueError: If some :code:`inputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_meshes_names = ['omega', 'pressure'] - problem.add_input_meshes_names(input_meshes_names) - """ - if not (len(set(inputs)) == len(inputs)): - raise ValueError("Some inputs have same names") - for input in inputs: - self.add_input_mesh_name(input) - - @deprecated( - "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_input_mesh_name(self, input: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. - - Add an input mesh name to the problem. - - Args: - input (str): The name of the input feature to add. - - Raises: - ValueError: If the specified input feature is already in the list of inputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - input_name = 'pressure' - problem.add_input_mesh_name(input_name) - """ - if input in self.in_meshes_names: - raise ValueError(f"{input} is already in self.in_meshes_names") - self.in_meshes_names.append(input) - self.in_meshes_names.sort() + # @deprecated( + # "use `get_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_input_meshes_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_in_features_identifiers` instead. + + # Get the input meshes names of the problem. + + # Returns: + # list[str]: A list of input feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # input_meshes_names = problem.get_input_meshes_names() + # print(input_meshes_names) + # >>> ['omega', 'pressure'] + # """ + # return self.in_meshes_names + + # @deprecated( + # "use `add_in_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_meshes_names(self, inputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_features_identifiers` instead. + + # Add input meshes names to the problem. + + # Args: + # inputs (list[str]): A list of input feature names to add. + + # Raises: + # ValueError: If some :code:`inputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_meshes_names = ['omega', 'pressure'] + # problem.add_input_meshes_names(input_meshes_names) + # """ + # if not (len(set(inputs)) == len(inputs)): + # raise ValueError("Some inputs have same names") + # for input in inputs: + # self.add_input_mesh_name(input) + + # @deprecated( + # "use `add_in_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_input_mesh_name(self, input: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_in_feature_identifier` instead. + + # Add an input mesh name to the problem. + + # Args: + # input (str): The name of the input feature to add. + + # Raises: + # ValueError: If the specified input feature is already in the list of inputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # input_name = 'pressure' + # problem.add_input_mesh_name(input_name) + # """ + # if input in self.in_meshes_names: + # raise ValueError(f"{input} is already in self.in_meshes_names") + # self.in_meshes_names.append(input) + # self.in_meshes_names.sort() def filter_input_meshes_names(self, names: list[str]) -> list[str]: """Filter and get input meshes features corresponding to a list of names. @@ -1357,82 +1344,82 @@ def filter_input_meshes_names(self, names: list[str]) -> list[str]: return sorted(set(names).intersection(self.get_input_meshes_names())) # -------------------------------------------------------------------------# - @deprecated( - "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def get_output_meshes_names(self) -> list[str]: - """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. - - Get the output meshes names of the problem. - - Returns: - list[str]: A list of output feature names. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - # [...] - outputs_names = problem.get_output_meshes_names() - print(outputs_names) - >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - """ - return self.out_meshes_names - - @deprecated( - "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_meshes_names(self, outputs: list[str]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. - - Add output meshes names to the problem. - - Args: - outputs (list[str]): A list of output feature names to add. - - Raises: - ValueError: if some :code:`outputs` are redondant. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_meshes_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] - problem.add_output_meshes_names(output_meshes_names) - """ - if not (len(set(outputs)) == len(outputs)): - raise ValueError("Some outputs have same names") - for output in outputs: - self.add_output_mesh_name(output) - - @deprecated( - "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" - ) - def add_output_mesh_name(self, output: str) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. - - Add an output mesh name to the problem. - - Args: - output (str): The name of the output feature to add. - - Raises: - ValueError: If the specified output feature is already in the list of outputs. - - Example: - .. code-block:: python - - from plaid import ProblemDefinition - problem = ProblemDefinition() - output_meshes_names = 'pressure' - problem.add_output_mesh_name(output_meshes_names) - """ - if output in self.out_meshes_names: - raise ValueError(f"{output} is already in self.out_meshes_names") - self.out_meshes_names.append(output) - self.in_meshes_names.sort() + # @deprecated( + # "use `get_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def get_output_meshes_names(self) -> list[str]: + # """DEPRECATED: use :meth:`ProblemDefinition.get_out_features_identifiers` instead. + + # Get the output meshes names of the problem. + + # Returns: + # list[str]: A list of output feature names. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # # [...] + # outputs_names = problem.get_output_meshes_names() + # print(outputs_names) + # >>> ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # """ + # return self.out_meshes_names + + # @deprecated( + # "use `add_out_features_identifiers` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_meshes_names(self, outputs: list[str]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_features_identifiers` instead. + + # Add output meshes names to the problem. + + # Args: + # outputs (list[str]): A list of output feature names to add. + + # Raises: + # ValueError: if some :code:`outputs` are redondant. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_meshes_names = ['compression_rate', 'in_massflow', 'isentropic_efficiency'] + # problem.add_output_meshes_names(output_meshes_names) + # """ + # if not (len(set(outputs)) == len(outputs)): + # raise ValueError("Some outputs have same names") + # for output in outputs: + # self.add_output_mesh_name(output) + + # @deprecated( + # "use `add_out_feature_identifier` instead", version="0.1.8", removal="0.2.0" + # ) + # def add_output_mesh_name(self, output: str) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.add_out_feature_identifier` instead. + + # Add an output mesh name to the problem. + + # Args: + # output (str): The name of the output feature to add. + + # Raises: + # ValueError: If the specified output feature is already in the list of outputs. + + # Example: + # .. code-block:: python + + # from plaid import ProblemDefinition + # problem = ProblemDefinition() + # output_meshes_names = 'pressure' + # problem.add_output_mesh_name(output_meshes_names) + # """ + # if output in self.out_meshes_names: + # raise ValueError(f"{output} is already in self.out_meshes_names") + # self.out_meshes_names.append(output) + # self.in_meshes_names.sort() def filter_output_meshes_names(self, names: list[str]) -> list[str]: """Filter and get output features corresponding to a list of names. @@ -1500,23 +1487,23 @@ def _generate_problem_infos_dict(self) -> dict[str, Union[str, list]]: data["test_split"] = self._test_split if self._name is not None: data["name"] = self._name - if Version(plaid.__version__) < Version("0.2.0"): - data.update( - { - k: v - for k, v in { - "input_scalars": self.in_scalars_names, - "output_scalars": self.out_scalars_names, - "input_fields": self.in_fields_names, - "output_fields": self.out_fields_names, - "input_timeseries": self.in_timeseries_names, - "output_timeseries": self.out_timeseries_names, - "input_meshes": self.in_meshes_names, - "output_meshes": self.out_meshes_names, - }.items() - if v # keeps only truthy (non-empty, non-None) lists - } - ) + # if Version(plaid.__version__) < Version("0.2.0"): + # data.update( + # { + # k: v + # for k, v in { + # "input_scalars": self.in_scalars_names, + # "output_scalars": self.out_scalars_names, + # "input_fields": self.in_fields_names, + # "output_fields": self.out_fields_names, + # "input_timeseries": self.in_timeseries_names, + # "output_timeseries": self.out_timeseries_names, + # "input_meshes": self.in_meshes_names, + # "output_meshes": self.out_meshes_names, + # }.items() + # if v # keeps only truthy (non-empty, non-None) lists + # } + # ) # Handle version plaid_version = Version(plaid.__version__) @@ -1530,16 +1517,6 @@ def _generate_problem_infos_dict(self) -> dict[str, Union[str, list]]: return data - # Handle version - plaid_version = Version(plaid.__version__) - if self._version != plaid_version: # pragma: no cover - logger.warning( - f"Version mismatch: ProblemDefinition was loaded from version {self._version if self._version is not None else 'anterior to 0.1.10'}, and will be saved with version: {plaid_version}" - ) - data["version"] = str(plaid_version) - else: - data["version"] = str(self._version) - # Save infos def save_to_file(self, path: Union[str, Path]) -> None: @@ -1569,14 +1546,14 @@ def save_to_file(self, path: Union[str, Path]) -> None: problem_infos_dict, file, default_flow_style=False, sort_keys=True ) - @deprecated( - "`ProblemDefinition._save_to_dir_(...)` is deprecated. Use `ProblemDefinition.save_to_dir(...)` instead.", - version="0.1.10", - removal="0.2.0", - ) - def _save_to_dir_(self, path: Union[str, Path]) -> None: - """DEPRECATED: use :meth:`ProblemDefinition.save_to_dir` instead.""" - self.save_to_dir(path) + # @deprecated( + # "`ProblemDefinition._save_to_dir_(...)` is deprecated. Use `ProblemDefinition.save_to_dir(...)` instead.", + # version="0.1.10", + # removal="0.2.0", + # ) + # def _save_to_dir_(self, path: Union[str, Path]) -> None: + # """DEPRECATED: use :meth:`ProblemDefinition.save_to_dir` instead.""" + # self.save_to_dir(path) def save_to_dir(self, path: Union[str, Path]) -> None: """Save problem information, inputs, outputs, and split to the specified directory in YAML and CSV formats. diff --git a/tests/bridges/test_huggingface_bridge.py b/tests/bridges/test_huggingface_bridge.py index b4d0c131..6eeb8d45 100644 --- a/tests/bridges/test_huggingface_bridge.py +++ b/tests/bridges/test_huggingface_bridge.py @@ -15,7 +15,7 @@ from plaid.bridges import huggingface_bridge from plaid.containers.dataset import Dataset from plaid.containers.sample import Sample -from plaid.problem_definition import ProblemDefinition +from plaid.problem_definition import ProblemDefinition, FeatureIdentifier from plaid.utils import cgns_helper @@ -37,7 +37,10 @@ def dataset(samples, infos) -> Dataset: def problem_definition() -> ProblemDefinition: problem_definition = ProblemDefinition() problem_definition.set_task("regression") - problem_definition.add_input_scalars_names(["feature_name_1", "feature_name_2"]) + scalar_1_feat_id = FeatureIdentifier({"type":"scalar", "name":"feature_name_1"}) + scalar_2_feat_id = FeatureIdentifier({"type":"scalar", "name":"feature_name_2"}) + + problem_definition.add_in_features_identifiers([scalar_1_feat_id, scalar_2_feat_id]) problem_definition.set_split({"train": [0, 2], "test": [1, 3]}) return problem_definition diff --git a/tests/containers/test_dataset.py b/tests/containers/test_dataset.py index 067a39f8..6689569f 100644 --- a/tests/containers/test_dataset.py +++ b/tests/containers/test_dataset.py @@ -86,15 +86,6 @@ def test__init__path(self, current_directory): dataset_path = current_directory / "dataset" Dataset(path=dataset_path) - def test__init__directory_path(self, current_directory): - dataset_path = current_directory / "dataset" - Dataset(directory_path=dataset_path) - - def test__init__both_path_and_directory_path(self, current_directory): - dataset_path = current_directory / "dataset" - with pytest.raises(ValueError): - Dataset(path=dataset_path, directory_path=dataset_path) - # -------------------------------------------------------------------------# def test_get_samples(self, dataset_with_samples, nb_samples): dataset_with_samples.get_samples() @@ -986,11 +977,6 @@ def test_check_feature_completeness( # -------------------------------------------------------------------------# - def test_from_list_of_samples_deprecated(self, samples): - with pytest.warns(DeprecationWarning): - loaded_dataset = Dataset.from_list_of_samples(samples) - assert len(loaded_dataset) == len(samples) - def test___init___samples(self, samples): loaded_dataset = Dataset(samples=samples) assert len(loaded_dataset) == len(samples) @@ -1011,7 +997,7 @@ def test___init___samples_and_path(self, samples, tmp_path): def test_save(self, dataset_with_samples, tmp_path): fname = tmp_path / "test.plaid" - dataset_with_samples.save(fname) + dataset_with_samples.save_to_file(fname) assert fname.is_file() def test_load_file(self, dataset_with_samples, tmp_path): @@ -1044,7 +1030,7 @@ def test_load_dir(self, dataset_with_samples, tmp_path): def test_load_multiprocessing(self, dataset_with_samples, tmp_path): fname = tmp_path / "test.plaid" - dataset_with_samples.save(fname) + dataset_with_samples.save_to_file(fname) new_dataset = Dataset() new_dataset.load(fname) @@ -1070,19 +1056,19 @@ def test_load_multiprocessing(self, dataset_with_samples, tmp_path): def test_load_process_eror(self, dataset_with_samples, tmp_path): fname = tmp_path / "test.plaid" - dataset_with_samples.save(fname) + dataset_with_samples.save_to_file(fname) with pytest.raises(ValueError): Dataset(str(fname), processes_number=-3) def test_load_from_file(self, dataset_with_samples, tmp_path): fname = tmp_path / "test_fname.plaid" - dataset_with_samples.save(fname) + dataset_with_samples.save_to_file(fname) loaded_dataset = Dataset.load_from_file(fname) assert len(loaded_dataset) == len(dataset_with_samples) def test_load_from_dir(self, dataset_with_samples, tmp_path): dname = tmp_path / "test_dname" - dataset_with_samples._save_to_dir_(dname) + dataset_with_samples.save_to_dir(dname) loaded_dataset = Dataset.load_from_dir(dname) assert len(loaded_dataset) == len(dataset_with_samples) @@ -1128,26 +1114,17 @@ def test__add_to_dir__path(self, empty_dataset, sample, tmp_path): save_dir = tmp_path / "my_dataset_dir" empty_dataset.add_to_dir(sample, path=save_dir) - def test__add_to_dir__save_dir(self, empty_dataset, sample, tmp_path): - save_dir = tmp_path / "my_dataset_dir" - empty_dataset.add_to_dir(sample, save_dir=save_dir) - - def test__add_to_dir__both_path_and_save_dir(self, empty_dataset, sample, tmp_path): - save_dir = tmp_path / "my_dataset_dir" - with pytest.raises(ValueError): - empty_dataset.add_to_dir(sample, path=save_dir, save_dir=save_dir) - # -------------------------------------------------------------------------# def test__save_to_dir_(self, dataset_with_samples, tmp_path): savedir = tmp_path / "testdir" - dataset_with_samples._save_to_dir_(savedir) + dataset_with_samples.save_to_dir(savedir) assert plaid.get_number_of_samples(savedir) == len(dataset_with_samples) assert savedir.is_dir() assert (savedir / "infos.yaml").is_file() def test__load_from_dir_(self, dataset_with_samples, infos, tmp_path): savedir = tmp_path / "testdir" - dataset_with_samples._save_to_dir_(savedir) + dataset_with_samples.save_to_dir(savedir) new_dataset = Dataset() new_dataset._load_from_dir_(savedir) assert len(new_dataset) == len(dataset_with_samples) @@ -1161,11 +1138,6 @@ def test__load_from_dir_(self, dataset_with_samples, infos, tmp_path): new_dataset._load_from_dir_(savedir, [1, 2]) assert len(new_dataset) == 2 - # -------------------------------------------------------------------------# - def test__load_number_of_samples_(self, tmp_path): - with pytest.raises(DeprecatedError): - Dataset._load_number_of_samples_(tmp_path) - # -------------------------------------------------------------------------# def test_set_samples(self, dataset, samples): dataset.set_samples({i: samp for i, samp in enumerate(samples)}) @@ -1247,131 +1219,3 @@ def test___repr__(self, dataset, dataset_with_samples): print(dataset) print(dataset_with_samples) - # #-------------------------------------------------------------------------# - # #-------------------------------------------------------------------------# - # #-------------------------------------------------------------------------# - # def test__init__(self, dataset): - # pass - - # #---# - # def test_get_samples(self, dataset_with_samples, nb_samples): - # samples = dataset_with_samples.get_samples() - # assert(isinstance(samples,dict)) - # for samp in samples.values(): - # assert(isinstance(samp,Sample)) - # assert(len(samples)==nb_samples) - # def test_get_samples_with_ids(self, dataset_with_samples, nb_samples): - # ids = [np.random.randint(0,nb_samples)] - # samples = dataset_with_samples.get_samples(ids) - # assert(isinstance(samples,dict)) - # for samp in samples.values(): - # assert(isinstance(samp,Sample)) - # assert(len(samples)==len(ids)) - - # def test_set_samples(self, dataset, samples): - # dataset.set_samples({id:sample for id,sample in enumerate(samples)}) - # def test_set_samples_fail_type(self, dataset): - # with pytest.raises(TypeError): - # dataset.set_samples(1) - # def test_set_samples_fail_type_input(self, dataset): - # with pytest.raises(TypeError): - # dataset.set_samples(1) - # def test_set_samples_fail_type_key(self, dataset): - # with pytest.raises(TypeError): - # dataset.set_samples({'test':'test'}) - # def test_set_samples_fail_negative_key(self, dataset): - # with pytest.raises(ValueError): - # dataset.set_samples({-1:'test'}) - # def test_set_samples_fail_type_value(self, dataset): - # with pytest.raises(TypeError): - # dataset.set_samples({0:'test'}) - - # def test_set_sample(self, dataset, sample): - # dataset.set_sample(id=0,sample=sample) - # def test_set_sample_already_present(self, dataset_with_samples, sample): - # dataset_with_samples.set_sample(id=0,sample=sample) - # def test_set_sample_fail_id_type(self, dataset, sample): - # with pytest.raises(TypeError): - # dataset.set_sample(id='0',sample=sample) - # def test_set_sample_fail_negative_id(self, dataset, sample): - # with pytest.raises(ValueError): - # dataset.set_sample(id=-1,sample=sample) - # def test_set_sample_fail_sample_type(self, dataset): - # with pytest.raises(TypeError): - # dataset.set_sample(id=1,sample='sample') - - # def test_add_sample(self, dataset, sample): - # dataset.add_sample(sample) - # def test_add_sample_fail_type(self, dataset): - # with pytest.raises(TypeError): - # dataset.add_sample(1) - - # def test_add_samples(self, dataset,samples): - # dataset.add_samples(samples) - # def test_add_samples_fail_type(self, dataset): - # with pytest.raises(TypeError): - # dataset.add_samples(1) - # def test_add_samples_fail_sample_type(self, dataset): - # with pytest.raises(TypeError): - # dataset.add_samples([1]) - - # #---# - # def test_get_sample_ids(self, dataset): - # dataset.get_sample_ids() - # def test_get_sample_ids_type(self, dataset): - # dataset.get_sample_ids(feature_type='scalar') - # def test_get_sample_ids_name(self, dataset): - # dataset.get_sample_ids(feature_name='test_scalar2') - - # #---# - # def test_get_feature_types(self, dataset): - # assert(dataset.get_feature_types()==set()) - # assert(dataset.get_feature_types(feature_name='missing_name')==set()) - # def test_get_feature_names(self, dataset): - # assert(dataset.get_feature_names()==set()) - # assert(dataset.get_feature_names(feature_type='missing_type')==set()) - - # #---# - # def test_get_scalars_to_tabular(self, dataset_with_samples): - # dataset_with_samples.get_scalars_to_tabular(feature_names=['test_scalar']) - # def test_get_scalars_to_tabular_all(self, dataset_with_samples): - # dataset_with_samples.get_scalars_to_tabular() - # def test_get_scalars_to_tabular_dict(self, dataset_with_samples): - # dataset_with_samples.get_scalars_to_tabular(feature_names=['test_scalar']) - # def test_get_scalars_to_tabular_all_dict(self, dataset_with_samples): - # dataset_with_samples.get_scalars_to_tabular() - # def test_get_scalars_to_tabular_missing_name(self, dataset_with_samples): - # with pytest.raises(ValueError): - # dataset_with_samples.get_scalars_to_tabular(feature_names=['missing_scalar_name']) - - # def test_merge_dataset(self, dataset_with_samples, other_dataset_with_samples): - # dataset_with_samples.merge_dataset(other_dataset_with_samples) - - # # def test_save(self, dataset): - # # dataset.save() - - # # def test_load(self, dataset): - # # dataset.load() - - # # def test__save_to_dir_(self, dataset): - # # dataset._save_to_dir_() - - # # def test__load_from_dir_(self, dataset): - # # dataset._load_from_dir_() - - # def test___len__(self, dataset): - # assert(len(dataset)==0) - # def test___len__with_samples(self, dataset_with_samples, nb_samples): - # assert(len(dataset_with_samples)==nb_samples) - - # def test___getitem__(self, dataset_with_samples): - # dataset_with_samples[0] - # def test___getitem__no_id(self, dataset_with_samples, nb_samples): - # with pytest.raises(IndexError): - # dataset_with_samples[nb_samples + 1] - - # def test___call__(self, dataset_with_samples): - # dataset_with_samples(0) - - # def test___repr__(self, dataset_with_samples): - # print(dataset_with_samples) diff --git a/tests/containers/test_sample.py b/tests/containers/test_sample.py index 50808222..3b91cd52 100644 --- a/tests/containers/test_sample.py +++ b/tests/containers/test_sample.py @@ -190,15 +190,6 @@ def test__init__path(self, current_directory): sample_path = current_directory / "dataset" / "samples" / "sample_000000000" Sample(path=sample_path) - # def test__init__directory_path(self, current_directory): - # sample_path = current_directory / "dataset" / "samples" / "sample_000000000" - # Sample(directory_path=sample_path) - - # def test__init__both_path_and_directory_path(self, current_directory): - # sample_path = current_directory / "dataset" / "samples" / "sample_000000000" - # with pytest.raises(ValueError): - # Sample(path=sample_path, directory_path=sample_path) - def test_copy(self, sample_with_tree_and_scalar): sample_with_tree_and_scalar.copy() @@ -1596,16 +1587,16 @@ def test_merge_features2(self, sample_with_tree_and_scalar, sample_with_tree): # -------------------------------------------------------------------------# def test_save(self, sample_with_tree_and_scalar, tmp_path): save_dir = tmp_path / "test_dir" - sample_with_tree_and_scalar.save(save_dir) + sample_with_tree_and_scalar.save_to_dir(save_dir) assert save_dir.is_dir() with pytest.raises(ValueError): - sample_with_tree_and_scalar.save(save_dir, memory_safe=False) - sample_with_tree_and_scalar.save(save_dir, overwrite=True) - sample_with_tree_and_scalar.save(save_dir, overwrite=True, memory_safe=True) + sample_with_tree_and_scalar.save_to_dir(save_dir, memory_safe=False) + sample_with_tree_and_scalar.save_to_dir(save_dir, overwrite=True) + sample_with_tree_and_scalar.save_to_dir(save_dir, overwrite=True, memory_safe=True) def test_load_from_saved_file(self, sample_with_tree_and_scalar, tmp_path): save_dir = tmp_path / "test_dir" - sample_with_tree_and_scalar.save(save_dir) + sample_with_tree_and_scalar.save_to_dir(save_dir) new_sample = Sample() new_sample.load(save_dir) assert CGU.checkSameTree( @@ -1615,7 +1606,7 @@ def test_load_from_saved_file(self, sample_with_tree_and_scalar, tmp_path): def test_load_from_dir(self, sample_with_tree_and_scalar, tmp_path): save_dir = tmp_path / "test_dir" - sample_with_tree_and_scalar.save(save_dir) + sample_with_tree_and_scalar.save_to_dir(save_dir) new_sample = Sample.load_from_dir(save_dir) assert CGU.checkSameTree( sample_with_tree_and_scalar.get_tree(), diff --git a/tests/storage/test_storage.py b/tests/storage/test_storage.py index aa58932c..4ec7066d 100644 --- a/tests/storage/test_storage.py +++ b/tests/storage/test_storage.py @@ -13,6 +13,7 @@ from pathlib import Path import numpy as np +from plaid.containers.feature_identifier import FeatureIdentifier import pytest import yaml @@ -183,7 +184,7 @@ def main_splits() -> dict: def problem_definition(main_splits) -> ProblemDefinition: problem_definition = ProblemDefinition() problem_definition.set_task("regression") - problem_definition.add_input_scalars_names(["feature_name_1", "feature_name_2"]) + problem_definition.add_in_features_identifiers([FeatureIdentifier.from_string("scalar::feature_name_1"), FeatureIdentifier.from_string("scalar::feature_name_2")]) problem_definition.set_split(main_splits) return problem_definition diff --git a/tests/test_problem_definition.py b/tests/test_problem_definition.py index 3176d6c4..63cc6614 100644 --- a/tests/test_problem_definition.py +++ b/tests/test_problem_definition.py @@ -48,9 +48,9 @@ def problem_definition_full(problem_definition: ProblemDefinition) -> ProblemDef ) problem_definition.add_out_feature_identifier(feature_identifier) # ---- - feature_identifier = "Base_2_2/Zone/PointData/U1" - predict_feature_identifier = "Base_2_2/Zone/PointData/U2" - test_feature_identifier = "Base_2_2/Zone/PointData/sig12" + feature_identifier = FeatureIdentifier.from_string("field::U1/PointData/Zone/Base_2_2") + predict_feature_identifier = FeatureIdentifier.from_string("field::U2/PointData/Zone/Base_2_2") + test_feature_identifier = FeatureIdentifier.from_string("field::sig12/PointData/Zone/Base_2_2") problem_definition.add_in_features_identifiers( [predict_feature_identifier, test_feature_identifier] ) @@ -58,31 +58,31 @@ def problem_definition_full(problem_definition: ProblemDefinition) -> ProblemDef problem_definition.add_out_features_identifiers( [predict_feature_identifier, test_feature_identifier] ) - problem_definition.add_constant_feature_identifier(feature_identifier) + problem_definition.add_constant_feature_identifier(feature_identifier["name"]) problem_definition.add_constant_features_identifiers( - [predict_feature_identifier, test_feature_identifier] + [predict_feature_identifier["name"], test_feature_identifier["name"]] ) # ---- - problem_definition.add_input_scalars_names(["scalar", "test_scalar"]) - problem_definition.add_input_scalar_name("predict_scalar") - problem_definition.add_output_scalars_names(["scalar", "test_scalar"]) - problem_definition.add_output_scalar_name("predict_scalar") - - problem_definition.add_input_fields_names(["field", "test_field"]) - problem_definition.add_input_field_name("predict_field") - problem_definition.add_output_fields_names(["field", "test_field"]) - problem_definition.add_output_field_name("predict_field") - - problem_definition.add_input_timeseries_names(["timeseries", "test_timeseries"]) - problem_definition.add_input_timeseries_name("predict_timeseries") - problem_definition.add_output_timeseries_names(["timeseries", "test_timeseries"]) - problem_definition.add_output_timeseries_name("predict_timeseries") - - problem_definition.add_input_meshes_names(["mesh", "test_mesh"]) - problem_definition.add_input_mesh_name("predict_mesh") - problem_definition.add_output_meshes_names(["mesh", "test_mesh"]) - problem_definition.add_output_mesh_name("predict_mesh") + # problem_definition.add_input_scalars_names(["scalar", "test_scalar"]) + # problem_definition.add_input_scalar_name("predict_scalar") + # problem_definition.add_output_scalars_names(["scalar", "test_scalar"]) + # problem_definition.add_output_scalar_name("predict_scalar") + + # problem_definition.add_input_fields_names(["field", "test_field"]) + # problem_definition.add_input_field_name("predict_field") + # problem_definition.add_output_fields_names(["field", "test_field"]) + # problem_definition.add_output_field_name("predict_field") + + # problem_definition.add_input_timeseries_names(["timeseries", "test_timeseries"]) + # problem_definition.add_input_timeseries_name("predict_timeseries") + # problem_definition.add_output_timeseries_names(["timeseries", "test_timeseries"]) + # problem_definition.add_output_timeseries_name("predict_timeseries") + + # problem_definition.add_input_meshes_names(["mesh", "test_mesh"]) + # problem_definition.add_input_mesh_name("predict_mesh") + # problem_definition.add_output_meshes_names(["mesh", "test_mesh"]) + # problem_definition.add_output_mesh_name("predict_mesh") new_split = {"train": [0, 1, 2], "test": [3, 4]} problem_definition.set_split(new_split) @@ -127,15 +127,6 @@ def test__init__path(self, current_directory): d_path = current_directory / "problem_definition" ProblemDefinition(path=d_path) - def test__init__directory_path(self, current_directory): - d_path = current_directory / "problem_definition" - ProblemDefinition(directory_path=d_path) - - def test__init__both_path_and_directory_path(self, current_directory): - d_path = current_directory / "problem_definition" - with pytest.raises(ValueError): - ProblemDefinition(path=d_path, directory_path=d_path) - # -------------------------------------------------------------------------# def test_version(self, problem_definition): # Unauthorized version @@ -328,269 +319,249 @@ def test_filter_features_identifiers(self, current_directory): # -#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # -------------------------------------------------------------------------# - def test_get_input_scalars_names(self, problem_definition): - assert problem_definition.get_input_scalars_names() == [] - def test_add_input_scalars_names_fail_same_name(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_input_scalars_names(["feature_name", "feature_name"]) - problem_definition.add_input_scalar_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_input_scalar_name("feature_name") - - def test_add_input_scalars_names(self, problem_definition): - problem_definition.add_input_scalars_names(["scalar", "test_scalar"]) - problem_definition.add_input_scalar_name("predict_scalar") - inputs = problem_definition.get_input_scalars_names() - assert len(inputs) == 3 - assert set(inputs) == set(["predict_scalar", "scalar", "test_scalar"]) - print(problem_definition) + # def test_add_input_scalars_names_fail_same_name(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_input_scalars_names(["feature_name", "feature_name"]) + # problem_definition.add_input_scalar_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_input_scalar_name("feature_name") + + # def test_add_input_scalars_names(self, problem_definition): + # problem_definition.add_input_scalars_names(["scalar", "test_scalar"]) + # problem_definition.add_input_scalar_name("predict_scalar") + # inputs = problem_definition.get_in_features_identifiers() + # assert len(inputs) == 3 + # assert set(inputs) == set(["predict_scalar", "scalar", "test_scalar"]) + # print(problem_definition) # -------------------------------------------------------------------------# - def test_get_output_scalars_names(self, problem_definition): - assert problem_definition.get_output_scalars_names() == [] - - def test_add_output_scalars_names_fail(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_output_scalars_names( - ["feature_name", "feature_name"] - ) - problem_definition.add_output_scalar_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_output_scalar_name("feature_name") - - def test_add_output_scalars_names(self, problem_definition): - problem_definition.add_output_scalars_names(["scalar", "test_scalar"]) - problem_definition.add_output_scalar_name("predict_scalar") - outputs = problem_definition.get_output_scalars_names() - assert len(outputs) == 3 - assert set(outputs) == set(["predict_scalar", "scalar", "test_scalar"]) - print(problem_definition) + #def test_get_output_scalars_names(self, problem_definition): + # assert problem_definition.get_output_scalars_names() == [] # -------------------------------------------------------------------------# - def test_filter_scalars_names(self, current_directory): - d_path = current_directory / "problem_definition" - problem = ProblemDefinition(d_path) - filter_in = problem.filter_input_scalars_names( - ["predict_scalar", "test_scalar"] - ) - filter_out = problem.filter_output_scalars_names( - ["predict_scalar", "test_scalar"] - ) - assert len(filter_in) == 2 and filter_in == ["predict_scalar", "test_scalar"] - assert filter_in != ["test_scalar", "predict_scalar"], ( - "common inputs not sorted" - ) - - assert len(filter_out) == 2 and filter_out == ["predict_scalar", "test_scalar"] - assert filter_out != ["test_scalar", "predict_scalar"], ( - "common outputs not sorted" - ) - - fail_filter_in = problem.filter_input_scalars_names(["a_scalar"]) - fail_filter_out = problem.filter_output_scalars_names(["b_scalar"]) - - assert fail_filter_in == [] - assert fail_filter_out == [] + # def test_filter_scalars_names(self, current_directory): + # d_path = current_directory / "problem_definition" + # problem = ProblemDefinition(d_path) + # print(problem) + # filter_in = problem.filter_in_features_identifiers( + # ["predict_scalar", "test_scalar"] + # ) + # filter_out = problem.filter_output_scalars_names( + # ["predict_scalar", "test_scalar"] + # ) + # assert len(filter_in) == 2 and filter_in == ["predict_scalar", "test_scalar"] + # assert filter_in != ["test_scalar", "predict_scalar"], ( + # "common inputs not sorted" + # ) + + # assert len(filter_out) == 2 and filter_out == ["predict_scalar", "test_scalar"] + # assert filter_out != ["test_scalar", "predict_scalar"], ( + # "common outputs not sorted" + # ) + + # fail_filter_in = problem.filter_input_scalars_names(["a_scalar"]) + # fail_filter_out = problem.filter_output_scalars_names(["b_scalar"]) + + # assert fail_filter_in == [] + # assert fail_filter_out == [] # -#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # -------------------------------------------------------------------------# - def test_get_input_fields_names(self, problem_definition): - assert problem_definition.get_input_fields_names() == [] + # def test_get_input_fields_names(self, problem_definition): + # assert problem_definition.get_input_fields_names() == [] - def test_add_input_fields_names_fail_same_name(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_input_fields_names(["feature_name", "feature_name"]) - problem_definition.add_input_field_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_input_field_name("feature_name") + # def test_add_input_fields_names_fail_same_name(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_input_fields_names(["feature_name", "feature_name"]) + # problem_definition.add_input_field_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_input_field_name("feature_name") def test_add_input_fields_names(self, problem_definition): - problem_definition.add_input_fields_names(["field", "test_field"]) - problem_definition.add_input_field_name("predict_field") - inputs = problem_definition.get_input_fields_names() + problem_definition.add_in_features_identifiers( [ FeatureIdentifier({"type":"field", "name":n}) for n in ["field", "test_field"]]) + problem_definition.add_in_features_identifiers( [ FeatureIdentifier({"type":"field", "name":"predict_field"})] ) + inputs = [f["name"] for f in problem_definition.get_in_features_identifiers() if f["type"] =="field"] assert len(inputs) == 3 assert set(inputs) == set(["predict_field", "field", "test_field"]) print(problem_definition) # -------------------------------------------------------------------------# - def test_get_output_fields_names(self, problem_definition): - assert problem_definition.get_output_fields_names() == [] - - def test_add_output_fields_names_fail(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_output_fields_names(["feature_name", "feature_name"]) - problem_definition.add_output_field_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_output_field_name("feature_name") - def test_add_output_fields_names(self, problem_definition): - problem_definition.add_output_fields_names(["field", "test_field"]) - problem_definition.add_output_field_name("predict_field") - outputs = problem_definition.get_output_fields_names() - assert len(outputs) == 3 - assert set(outputs) == set(["predict_field", "field", "test_field"]) - print(problem_definition) + # def test_add_output_fields_names_fail(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_output_fields_names(["feature_name", "feature_name"]) + # problem_definition.add_output_field_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_output_field_name("feature_name") + + # def test_add_output_fields_names(self, problem_definition): + # problem_definition.add_output_fields_names(["field", "test_field"]) + # problem_definition.add_output_field_name("predict_field") + # outputs = problem_definition.get_output_fields_names() + # assert len(outputs) == 3 + # assert set(outputs) == set(["predict_field", "field", "test_field"]) + # print(problem_definition) # -------------------------------------------------------------------------# - def test_filter_fields_names(self, current_directory): - d_path = current_directory / "problem_definition" - problem = ProblemDefinition(d_path) - filter_in = problem.filter_input_fields_names(["predict_field", "test_field"]) - filter_out = problem.filter_output_fields_names(["predict_field", "test_field"]) - assert len(filter_in) == 2 and filter_in == ["predict_field", "test_field"] - assert filter_in != ["test_field", "predict_field"], "common inputs not sorted" + # def test_filter_fields_names(self, current_directory): + # d_path = current_directory / "problem_definition" + # problem = ProblemDefinition(d_path) + # filter_in = problem.filter_input_fields_names(["predict_field", "test_field"]) + # filter_out = problem.filter_output_fields_names(["predict_field", "test_field"]) + # assert len(filter_in) == 2 and filter_in == ["predict_field", "test_field"] + # assert filter_in != ["test_field", "predict_field"], "common inputs not sorted" - assert len(filter_out) == 2 and filter_out == ["predict_field", "test_field"] - assert filter_out != ["test_field", "predict_field"], ( - "common outputs not sorted" - ) + # assert len(filter_out) == 2 and filter_out == ["predict_field", "test_field"] + # assert filter_out != ["test_field", "predict_field"], ( + # "common outputs not sorted" + # ) - fail_filter_in = problem.filter_input_fields_names(["a_field"]) - fail_filter_out = problem.filter_output_fields_names(["b_field"]) + # fail_filter_in = problem.filter_input_fields_names(["a_field"]) + # fail_filter_out = problem.filter_output_fields_names(["b_field"]) - assert fail_filter_in == [] - assert fail_filter_out == [] + # assert fail_filter_in == [] + # assert fail_filter_out == [] # -#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # -------------------------------------------------------------------------# - def test_get_input_timeseries_names(self, problem_definition): - assert problem_definition.get_input_timeseries_names() == [] - - def test_add_input_timeseries_names_fail_same_name(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_input_timeseries_names( - ["feature_name", "feature_name"] - ) - problem_definition.add_input_timeseries_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_input_timeseries_name("feature_name") - - def test_add_input_timeseries_names(self, problem_definition): - problem_definition.add_input_timeseries_names(["timeseries", "test_timeseries"]) - problem_definition.add_input_timeseries_name("predict_timeseries") - inputs = problem_definition.get_input_timeseries_names() - assert len(inputs) == 3 - assert set(inputs) == set( - ["predict_timeseries", "timeseries", "test_timeseries"] - ) - print(problem_definition) + # def test_get_input_timeseries_names(self, problem_definition): + # assert problem_definition.get_input_timeseries_names() == [] + + # def test_add_input_timeseries_names_fail_same_name(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_input_timeseries_names( + # ["feature_name", "feature_name"] + # ) + # problem_definition.add_input_timeseries_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_input_timeseries_name("feature_name") + + # def test_add_input_timeseries_names(self, problem_definition): + # problem_definition.add_input_timeseries_names(["timeseries", "test_timeseries"]) + # problem_definition.add_input_timeseries_name("predict_timeseries") + # inputs = problem_definition.get_input_timeseries_names() + # assert len(inputs) == 3 + # assert set(inputs) == set( + # ["predict_timeseries", "timeseries", "test_timeseries"] + # ) + # print(problem_definition) # -------------------------------------------------------------------------# - def test_get_output_timeseries_names(self, problem_definition): - assert problem_definition.get_output_timeseries_names() == [] - - def test_add_output_timeseries_names_fail(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_output_timeseries_names( - ["feature_name", "feature_name"] - ) - problem_definition.add_output_timeseries_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_output_timeseries_name("feature_name") - - def test_add_output_timeseries_names(self, problem_definition): - problem_definition.add_output_timeseries_names( - ["timeseries", "test_timeseries"] - ) - problem_definition.add_output_timeseries_name("predict_timeseries") - outputs = problem_definition.get_output_timeseries_names() - assert len(outputs) == 3 - assert set(outputs) == set( - ["predict_timeseries", "timeseries", "test_timeseries"] - ) - print(problem_definition) + # def test_get_output_timeseries_names(self, problem_definition): + # assert problem_definition.get_output_timeseries_names() == [] + + # def test_add_output_timeseries_names_fail(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_output_timeseries_names( + # ["feature_name", "feature_name"] + # ) + # problem_definition.add_output_timeseries_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_output_timeseries_name("feature_name") + + # def test_add_output_timeseries_names(self, problem_definition): + # problem_definition.add_output_timeseries_names( + # ["timeseries", "test_timeseries"] + # ) + # problem_definition.add_output_timeseries_name("predict_timeseries") + # outputs = problem_definition.get_output_timeseries_names() + # assert len(outputs) == 3 + # assert set(outputs) == set( + # ["predict_timeseries", "timeseries", "test_timeseries"] + # ) + # print(problem_definition) # -------------------------------------------------------------------------# - def test_filter_timeseries_names(self, current_directory): - d_path = current_directory / "problem_definition" - problem = ProblemDefinition(d_path) - filter_in = problem.filter_input_timeseries_names( - ["predict_timeseries", "test_timeseries"] - ) - filter_out = problem.filter_output_timeseries_names( - ["predict_timeseries", "test_timeseries"] - ) - assert len(filter_in) == 2 and filter_in == [ - "predict_timeseries", - "test_timeseries", - ] - assert filter_in != ["test_timeseries", "predict_timeseries"], ( - "common inputs not sorted" - ) - - assert len(filter_out) == 2 and filter_out == [ - "predict_timeseries", - "test_timeseries", - ] - assert filter_out != ["test_timeseries", "predict_timeseries"], ( - "common outputs not sorted" - ) - - fail_filter_in = problem.filter_input_timeseries_names(["a_timeseries"]) - fail_filter_out = problem.filter_output_timeseries_names(["b_timeseries"]) - - assert fail_filter_in == [] - assert fail_filter_out == [] + # def test_filter_timeseries_names(self, current_directory): + # d_path = current_directory / "problem_definition" + # problem = ProblemDefinition(d_path) + # filter_in = problem.filter_input_timeseries_names( + # ["predict_timeseries", "test_timeseries"] + # ) + # filter_out = problem.filter_output_timeseries_names( + # ["predict_timeseries", "test_timeseries"] + # ) + # assert len(filter_in) == 2 and filter_in == [ + # "predict_timeseries", + # "test_timeseries", + # ] + # assert filter_in != ["test_timeseries", "predict_timeseries"], ( + # "common inputs not sorted" + # ) + + # assert len(filter_out) == 2 and filter_out == [ + # "predict_timeseries", + # "test_timeseries", + # ] + # assert filter_out != ["test_timeseries", "predict_timeseries"], ( + # "common outputs not sorted" + # ) + + # fail_filter_in = problem.filter_input_timeseries_names(["a_timeseries"]) + # fail_filter_out = problem.filter_output_timeseries_names(["b_timeseries"]) + + # assert fail_filter_in == [] + # assert fail_filter_out == [] # -#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # -------------------------------------------------------------------------# - def test_get_input_meshes_names(self, problem_definition): - assert problem_definition.get_input_meshes_names() == [] - - def test_add_input_meshes_names_fail_same_name(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_input_meshes_names(["feature_name", "feature_name"]) - problem_definition.add_input_mesh_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_input_mesh_name("feature_name") - - def test_add_input_meshes_names(self, problem_definition): - problem_definition.add_input_meshes_names(["mesh", "test_mesh"]) - problem_definition.add_input_mesh_name("predict_mesh") - inputs = problem_definition.get_input_meshes_names() - assert len(inputs) == 3 - assert set(inputs) == set(["predict_mesh", "mesh", "test_mesh"]) - print(problem_definition) + # def test_get_input_meshes_names(self, problem_definition): + # assert problem_definition.get_input_meshes_names() == [] + + # def test_add_input_meshes_names_fail_same_name(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_input_meshes_names(["feature_name", "feature_name"]) + # problem_definition.add_input_mesh_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_input_mesh_name("feature_name") + + # def test_add_input_meshes_names(self, problem_definition): + # problem_definition.add_input_meshes_names(["mesh", "test_mesh"]) + # problem_definition.add_input_mesh_name("predict_mesh") + # inputs = problem_definition.get_input_meshes_names() + # assert len(inputs) == 3 + # assert set(inputs) == set(["predict_mesh", "mesh", "test_mesh"]) + # print(problem_definition) # -------------------------------------------------------------------------# - def test_get_output_meshes_names(self, problem_definition): - assert problem_definition.get_output_meshes_names() == [] - - def test_add_output_meshes_names_fail(self, problem_definition): - with pytest.raises(ValueError): - problem_definition.add_output_meshes_names(["feature_name", "feature_name"]) - problem_definition.add_output_mesh_name("feature_name") - with pytest.raises(ValueError): - problem_definition.add_output_mesh_name("feature_name") - - def test_add_output_meshes_names(self, problem_definition): - problem_definition.add_output_meshes_names(["mesh", "test_mesh"]) - problem_definition.add_output_mesh_name("predict_mesh") - outputs = problem_definition.get_output_meshes_names() - assert len(outputs) == 3 - assert set(outputs) == set(["predict_mesh", "mesh", "test_mesh"]) - print(problem_definition) + # def test_get_output_meshes_names(self, problem_definition): + # assert problem_definition.get_output_meshes_names() == [] + + # def test_add_output_meshes_names_fail(self, problem_definition): + # with pytest.raises(ValueError): + # problem_definition.add_output_meshes_names(["feature_name", "feature_name"]) + # problem_definition.add_output_mesh_name("feature_name") + # with pytest.raises(ValueError): + # problem_definition.add_output_mesh_name("feature_name") + + # def test_add_output_meshes_names(self, problem_definition): + # problem_definition.add_output_meshes_names(["mesh", "test_mesh"]) + # problem_definition.add_output_mesh_name("predict_mesh") + # outputs = problem_definition.get_output_meshes_names() + # assert len(outputs) == 3 + # assert set(outputs) == set(["predict_mesh", "mesh", "test_mesh"]) + # print(problem_definition) # -------------------------------------------------------------------------# - def test_filter_meshes_names(self, current_directory): - d_path = current_directory / "problem_definition" - problem = ProblemDefinition(d_path) - print(f"{problem=}") - print(f"{problem.get_input_meshes_names()=}") - filter_in = problem.filter_input_meshes_names(["predict_mesh", "test_mesh"]) - filter_out = problem.filter_output_meshes_names(["predict_mesh", "test_mesh"]) - assert len(filter_in) == 2 and filter_in == ["predict_mesh", "test_mesh"] - assert filter_in != ["test_mesh", "predict_mesh"], "common inputs not sorted" + # def test_filter_meshes_names(self, current_directory): + # d_path = current_directory / "problem_definition" + # problem = ProblemDefinition(d_path) + # print(f"{problem=}") + # print(f"{problem.get_input_meshes_names()=}") + # filter_in = problem.filter_input_meshes_names(["predict_mesh", "test_mesh"]) + # filter_out = problem.filter_output_meshes_names(["predict_mesh", "test_mesh"]) + # assert len(filter_in) == 2 and filter_in == ["predict_mesh", "test_mesh"] + # assert filter_in != ["test_mesh", "predict_mesh"], "common inputs not sorted" - assert len(filter_out) == 2 and filter_out == ["predict_mesh", "test_mesh"] - assert filter_out != ["test_mesh", "predict_mesh"], "common outputs not sorted" + # assert len(filter_out) == 2 and filter_out == ["predict_mesh", "test_mesh"] + # assert filter_out != ["test_mesh", "predict_mesh"], "common outputs not sorted" - fail_filter_in = problem.filter_input_meshes_names(["a_mesh"]) - fail_filter_out = problem.filter_output_meshes_names(["b_mesh"]) + # fail_filter_in = problem.filter_input_meshes_names(["a_mesh"]) + # fail_filter_out = problem.filter_output_meshes_names(["b_mesh"]) - assert fail_filter_in == [] - assert fail_filter_out == [] + # assert fail_filter_in == [] + # assert fail_filter_out == [] # -------------------------------------------------------------------------# def test_split(self, problem_definition): @@ -618,10 +589,10 @@ def test_test_split(self, problem_definition): assert problem_definition.get_test_split("test2") == [3, 4] # -------------------------------------------------------------------------# - def test__save_to_dir_( - self, problem_definition_full: ProblemDefinition, tmp_path: Path - ): - problem_definition_full._save_to_dir_(tmp_path / "problem_definition") + # def test__save_to_dir_( + # self, problem_definition_full: ProblemDefinition, tmp_path: Path + # ): + # problem_definition_full._save_to_dir_(tmp_path / "problem_definition") def test_save_to_dir( self, problem_definition_full: ProblemDefinition, tmp_path: Path @@ -636,15 +607,15 @@ def test___init___path( self, problem_definition_full: ProblemDefinition, tmp_path: Path ): d_path = tmp_path / "problem_definition" - problem_definition_full._save_to_dir_(d_path) + problem_definition_full.save_to_dir(d_path) # problem = ProblemDefinition(d_path) assert problem.get_task() == "regression" - assert set(problem.get_input_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_in_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) - assert set(problem.get_output_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_out_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) all_split = problem.get_split() assert all_split["train"] == [0, 1, 2] and all_split["test"] == [3, 4] @@ -653,16 +624,16 @@ def test__load_from_dir_( self, problem_definition_full: ProblemDefinition, tmp_path: Path ): d_path = tmp_path / "problem_definition" - problem_definition_full._save_to_dir_(d_path) + problem_definition_full.save_to_dir(d_path) # problem = ProblemDefinition() problem._load_from_dir_(d_path) assert problem.get_task() == "regression" - assert set(problem.get_input_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_in_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) - assert set(problem.get_output_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_out_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) all_split = problem.get_split() assert all_split["train"] == [0, 1, 2] and all_split["test"] == [3, 4] @@ -676,25 +647,25 @@ def test__load_from_file_( problem = ProblemDefinition() problem._load_from_file_(path) assert problem.get_task() == "regression" - assert set(problem.get_input_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set( f["name"] for f in problem.get_in_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) - assert set(problem.get_output_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_out_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) def test_load(self, problem_definition_full: ProblemDefinition, tmp_path: Path): d_path = tmp_path / "problem_definition" - problem_definition_full._save_to_dir_(d_path) + problem_definition_full.save_to_dir(d_path) # problem = ProblemDefinition.load(d_path) assert problem.get_task() == "regression" assert problem.get_name() == "regression_1" - assert set(problem.get_input_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_in_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) - assert set(problem.get_output_scalars_names()) == set( - ["predict_scalar", "scalar", "test_scalar"] + assert set(f["name"] for f in problem.get_out_features_identifiers() if f["type"] == "scalar") == set( + ["predict_feature", "test_feature", "feature"] ) all_split = problem.get_split() assert all_split["train"] == [0, 1, 2] and all_split["test"] == [3, 4] @@ -703,7 +674,7 @@ def test__load_from_dir__old_version( self, problem_definition_full: ProblemDefinition, tmp_path: Path ): d_path = tmp_path / "problem_definition" - problem_definition_full._save_to_dir_(d_path) + problem_definition_full.save_to_dir(d_path) # Modify the plaid version in saved file infos_path = d_path / "problem_infos.yaml" with infos_path.open("r") as f: