Skip to content
28 changes: 20 additions & 8 deletions src/plaid/bridges/huggingface_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -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
Expand Down
74 changes: 1 addition & 73 deletions src/plaid/containers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 <plaid.containers.dataset.Dataset>`, overwriting existing information if there's a conflict.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand All @@ -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],
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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 <plaid.containers.utils.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.
Expand Down
38 changes: 38 additions & 0 deletions src/plaid/containers/feature_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"<feature_type>::<detail1>/<detail2>/.../<detailN>"

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)
10 changes: 0 additions & 10 deletions src/plaid/containers/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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.

Expand Down
68 changes: 0 additions & 68 deletions src/plaid/containers/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions src/plaid/pipelines/sklearn_block_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/plaid/post/bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
Loading
Loading