Downloadable examples

This Jupyter Notebook show how to easily retrieve advanced examples online.

  1. Datasets

  2. Samples

import warnings
warnings.filterwarnings("ignore", message=".*IProgress not found.*")

Section 1: Datasets

Retrieving advanded datasets examples is as easy as:

from plaid.examples import AVAILABLE_EXAMPLES

print(AVAILABLE_EXAMPLES)
['vki_ls59', 'elastoplastodynamics', 'multiscale_hyperelasticity', 'tensile2d', 'rotor37', 'profile2d', 'airfrans_clipped', 'airfrans_original', 'airfrans_remeshed']
from plaid.examples import datasets
import time

start = time.perf_counter()
print(datasets.tensile2d)
end = time.perf_counter()
print(f"First dataset retrieval duration: {end - start:.6f} seconds")
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
File ~/checkouts/readthedocs.org/user_builds/plaid-lib/conda/0.1.8/lib/python3.11/site-packages/plaid/examples/dataset.py:43, in _LazyDatasets._load_dataset(self, ex_name, hf_repo)
     42 try:
---> 43     dataset, _ = streamed_huggingface_dataset_to_plaid(hf_repo, 2)
     44     self._cache[ex_name] = dataset

File ~/checkouts/readthedocs.org/user_builds/plaid-lib/conda/0.1.8/lib/python3.11/site-packages/plaid/bridges/huggingface_bridge.py:440, in streamed_huggingface_dataset_to_plaid(hf_repo, number_of_samples)
    439     hf_sample = next(iter(ds_stream))
--> 440     samples.append(to_plaid_sample(hf_sample))
    442 dataset = Dataset.from_list_of_samples(samples)

File ~/checkouts/readthedocs.org/user_builds/plaid-lib/conda/0.1.8/lib/python3.11/site-packages/plaid/bridges/huggingface_bridge.py:301, in to_plaid_sample(hf_sample)
    293 """Convert a Hugging Face sample dictionary to a PLAID Sample instance.
    294 
    295 Args:
   (...)    299     Sample: The deserialized PLAID Sample object.
    300 """
--> 301 return Sample.model_validate(pickle.loads(hf_sample["sample"]))

File ~/checkouts/readthedocs.org/user_builds/plaid-lib/conda/0.1.8/lib/python3.11/site-packages/pydantic/main.py:705, in BaseModel.model_validate(cls, obj, strict, from_attributes, context, by_alias, by_name)
    700     raise PydanticUserError(
    701         'At least one of `by_alias` or `by_name` must be set to True.',
    702         code='validate-by-alias-and-name-false',
    703     )
--> 705 return cls.__pydantic_validator__.validate_python(
    706     obj, strict=strict, from_attributes=from_attributes, context=context, by_alias=by_alias, by_name=by_name
    707 )

ValidationError: 2 validation errors for Sample
meshes
  Input should be an instance of SampleMeshes [type=is_instance_of, input_value={0.0: ['CGNSTree', None, ...ase_t']], 'CGNSTree_t']}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
scalars
  Input should be an instance of SampleScalars [type=is_instance_of, input_value={'P': -43.83, 'max_U2_top...: 1845.0, 'p5': 73150.0}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[3], line 5
      2 import time
      4 start = time.perf_counter()
----> 5 print(datasets.tensile2d)
      6 end = time.perf_counter()
      7 print(f"First dataset retrieval duration: {end - start:.6f} seconds")

File ~/checkouts/readthedocs.org/user_builds/plaid-lib/conda/0.1.8/lib/python3.11/site-packages/plaid/examples/dataset.py:52, in _make_example.<locals>.prop(self)
     51 def prop(self):
---> 52     return self._load_dataset(ex_name, hf_repo)

File ~/checkouts/readthedocs.org/user_builds/plaid-lib/conda/0.1.8/lib/python3.11/site-packages/plaid/examples/dataset.py:47, in _LazyDatasets._load_dataset(self, ex_name, hf_repo)
     45     return dataset
     46 except Exception as e: # pragma: no cover
---> 47     raise RuntimeError(f"Failed to download or convert dataset '{hf_repo}'.") from e

RuntimeError: Failed to download or convert dataset 'PLAID-datasets/Tensile2d'.
start = time.perf_counter()
print(datasets.tensile2d)
end = time.perf_counter()
print(f"Second dataset retrieval duration: {end - start:.6f} seconds")

Section 2: Samples

from plaid.examples import samples

start = time.perf_counter()
print(samples.vki_ls59)

end = time.perf_counter()
print(f"First sample retrieval duration: {end - start:.6f} seconds")
from plaid.examples import samples

start = time.perf_counter()
print(samples.tensile2d)

end = time.perf_counter()
print(f"The tensile2d dataset being already loaded: sample retrieval duration: {end - start:.6f} seconds")