Skip to content

🎉 feat(sample.py) add option to overwrite folder in save #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@
# -- Path setup --------------------------------------------------------------

import datetime
import os
import sys
import subprocess

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from pathlib import Path

sys.path.insert(0, ".")
sys.path.insert(0, "../")

basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
basedir = Path(__file__).absolute().parent.parent
sys.path.insert(0, basedir)
sys.path.insert(0, os.path.join(basedir, "src/plaid"))
# sys.path.insert(0, os.path.join(basedir, "tests"))
sys.path.insert(0, os.path.join(basedir, "examples"))
sys.path.insert(0, basedir / "src" / "plaid")
# sys.path.insert(0, basedir / "tests")
sys.path.insert(0, basedir / "examples")
print(sys.path)


Expand Down Expand Up @@ -278,4 +273,4 @@ def get_git_info():
return "unknown"

release = get_git_info()
version = release
version = release
40 changes: 21 additions & 19 deletions docs/source/notebooks/bisect.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"outputs": [],
"source": [
"# Importing Required Libraries\n",
"import os\n",
"from typing import Union\n",
"from pathlib import Path\n",
"\n",
"from plaid.containers.dataset import Dataset\n",
"from plaid.post.bisect import plot_bisect, prepare_datasets\n",
Expand All @@ -30,24 +31,25 @@
"metadata": {},
"outputs": [],
"source": [
"def get_project_root(path: str, index=3) -> str:\n",
"def get_project_root(path: Union[str, Path], index: int=3) -> Path:\n",
" \"\"\"Find the project root path\n",
"\n",
" Args:\n",
" path (str): Current path of the notebook\n",
" path (Union[str, Path]): Current path of the notebook\n",
" index (int, optional): The number of parents to go back. Defaults to 3.\n",
"\n",
" Returns:\n",
" str: The project root path\n",
" Path: The project root path\n",
" \"\"\"\n",
" path = Path(path)\n",
" if index == 0:\n",
" return path\n",
" return get_project_root(os.path.dirname(path), index - 1)\n",
" return get_project_root(path.parent, index - 1)\n",
"\n",
"\n",
"# Setting up Directories\n",
"current_directory = os.getcwd()\n",
"dataset_directory = os.path.join(get_project_root(current_directory), \"tests\", \"post\")"
"current_directory = Path.cwd()\n",
"dataset_directory = get_project_root(current_directory) / \"tests\" / \"post\""
]
},
{
Expand All @@ -66,9 +68,9 @@
"outputs": [],
"source": [
"# Load PLAID datasets and problem metadata objects\n",
"ref_ds = Dataset(os.path.join(dataset_directory, \"dataset_ref\"))\n",
"pred_ds = Dataset(os.path.join(dataset_directory, \"dataset_near_pred\"))\n",
"problem = ProblemDefinition(os.path.join(dataset_directory, \"problem_definition\"))\n",
"ref_ds = Dataset(dataset_directory / \"dataset_ref\")\n",
"pred_ds = Dataset(dataset_directory / \"dataset_near_pred\")\n",
"problem = ProblemDefinition(dataset_directory / \"problem_definition\")\n",
"\n",
"# Get output scalars from reference and prediction dataset\n",
"ref_out_scalars, pred_out_scalars, out_scalars_names = prepare_datasets(\n",
Expand Down Expand Up @@ -117,9 +119,9 @@
"print(\"=== Plot with file paths ===\")\n",
"\n",
"# Load PLAID datasets and problem metadata from files\n",
"ref_path = os.path.join(dataset_directory, \"dataset_ref\")\n",
"pred_path = os.path.join(dataset_directory, \"dataset_pred\")\n",
"problem_path = os.path.join(dataset_directory, \"problem_definition\")\n",
"ref_path = dataset_directory / \"dataset_ref\"\n",
"pred_path = dataset_directory / \"dataset_pred\"\n",
"problem_path = dataset_directory / \"problem_definition\"\n",
"\n",
"# Using file paths to generate bisect plot on scalar_2\n",
"plot_bisect(ref_path, pred_path, problem_path, \"scalar_2\", \"differ_bisect_plot\")"
Expand All @@ -143,9 +145,9 @@
"print(\"=== Plot with PLAID objects ===\")\n",
"\n",
"# Load PLAID datasets and problem metadata objects\n",
"ref_path = Dataset(os.path.join(dataset_directory, \"dataset_ref\"))\n",
"pred_path = Dataset(os.path.join(dataset_directory, \"dataset_ref\"))\n",
"problem_path = ProblemDefinition(os.path.join(dataset_directory, \"problem_definition\"))\n",
"ref_path = Dataset(dataset_directory / \"dataset_ref\")\n",
"pred_path = Dataset(dataset_directory / \"dataset_pred\")\n",
"problem_path = ProblemDefinition(dataset_directory / \"problem_definition\")\n",
"\n",
"# Using PLAID objects to generate bisect plot on scalar_2\n",
"plot_bisect(ref_path, pred_path, problem_path, \"scalar_2\", \"equal_bisect_plot\")"
Expand All @@ -169,9 +171,9 @@
"print(\"=== Mix with scalar index and verbose ===\")\n",
"\n",
"# Mix\n",
"ref_path = os.path.join(dataset_directory, \"dataset_ref\")\n",
"pred_path = os.path.join(dataset_directory, \"dataset_near_pred\")\n",
"problem_path = ProblemDefinition(os.path.join(dataset_directory, \"problem_definition\"))\n",
"ref_path = dataset_directory / \"dataset_ref\"\n",
"pred_path = dataset_directory / \"dataset_near_pred\"\n",
"problem_path = ProblemDefinition(dataset_directory / \"problem_definition\")\n",
"\n",
"# Using scalar index and verbose option to generate bisect plot\n",
"scalar_index = 0\n",
Expand Down
34 changes: 18 additions & 16 deletions docs/source/notebooks/metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"outputs": [],
"source": [
"# Importing Required Libraries\n",
"import os\n",
"from typing import Union\n",
"from pathlib import Path\n",
"\n",
"from plaid.containers.dataset import Dataset\n",
"from plaid.post.metrics import compute_metrics, prepare_datasets, pretty_metrics\n",
Expand All @@ -30,24 +31,25 @@
"metadata": {},
"outputs": [],
"source": [
"def get_project_root(path: str, index=3) -> str:\n",
"def get_project_root(path: Union[str, Path], index=3) -> Path:\n",
" \"\"\"Find the project root path\n",
"\n",
" Args:\n",
" path (str): Current path of the notebook\n",
" path (Union[str, Path]): Current path of the notebook\n",
" index (int, optional): The number of parents to go back. Defaults to 3.\n",
"\n",
" Returns:\n",
" str: The project root path\n",
" Path: The project root path\n",
" \"\"\"\n",
" path = Path(path)\n",
" if index == 0:\n",
" return path\n",
" return get_project_root(os.path.dirname(path), index - 1)\n",
" return get_project_root(path.parent, index - 1)\n",
"\n",
"\n",
"# Setting up Directories\n",
"current_directory = os.getcwd()\n",
"dataset_directory = os.path.join(get_project_root(current_directory), \"tests\", \"post\")"
"current_directory = Path.cwd()\n",
"dataset_directory = current_directory / \"tests\" / \"post\""
]
},
{
Expand All @@ -66,9 +68,9 @@
"outputs": [],
"source": [
"# Load PLAID datasets and problem metadata objects\n",
"ref_ds = Dataset(os.path.join(dataset_directory, \"dataset_ref\"))\n",
"pred_ds = Dataset(os.path.join(dataset_directory, \"dataset_near_pred\"))\n",
"problem = ProblemDefinition(os.path.join(dataset_directory, \"problem_definition\"))\n",
"ref_ds = Dataset(dataset_directory / \"dataset_ref\")\n",
"pred_ds = Dataset(dataset_directory / \"dataset_near_pred\")\n",
"problem = ProblemDefinition(dataset_directory / \"problem_definition\")\n",
"\n",
"# Get output scalars from reference and prediction dataset\n",
"ref_out_scalars, pred_out_scalars, out_scalars_names = prepare_datasets(\n",
Expand Down Expand Up @@ -117,9 +119,9 @@
"print(\"=== Metrics with file paths ===\")\n",
"\n",
"# Load PLAID datasets and problem metadata file paths\n",
"ref_ds = os.path.join(dataset_directory, \"dataset_ref\")\n",
"pred_ds = os.path.join(dataset_directory, \"dataset_near_pred\")\n",
"problem = os.path.join(dataset_directory, \"problem_definition\")\n",
"ref_ds = dataset_directory / \"dataset_ref\"\n",
"pred_ds = dataset_directory / \"dataset_near_pred\"\n",
"problem = dataset_directory / \"problem_definition\"\n",
"\n",
"# Using file paths to generate metrics\n",
"metrics = compute_metrics(ref_ds, pred_ds, problem, \"first_metrics\")\n",
Expand Down Expand Up @@ -148,9 +150,9 @@
"print(\"=== Metrics with PLAID objects and verbose ===\")\n",
"\n",
"# Load PLAID datasets and problem metadata objects\n",
"ref_ds = Dataset(os.path.join(dataset_directory, \"dataset_ref\"))\n",
"pred_ds = Dataset(os.path.join(dataset_directory, \"dataset_pred\"))\n",
"problem = ProblemDefinition(os.path.join(dataset_directory, \"problem_definition\"))\n",
"ref_ds = Dataset(dataset_directory / \"dataset_ref\")\n",
"pred_ds = Dataset(dataset_directory / \"dataset_pred\")\n",
"problem = ProblemDefinition(dataset_directory / \"problem_definition\")\n",
"\n",
"# Pretty print activated with verbose mode\n",
"metrics = compute_metrics(ref_ds, pred_ds, problem, \"second_metrics\", verbose=True)"
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/problem_definition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"outputs": [],
"source": [
"# Import required libraries\n",
"import os\n",
"from pathlib import Path\n",
"\n",
"import numpy as np"
]
Expand Down Expand Up @@ -229,9 +229,9 @@
"metadata": {},
"outputs": [],
"source": [
"test_pth = f\"/tmp/test_safe_to_delete_{np.random.randint(1e10, 1e12)}\"\n",
"pb_def_save_fname = os.path.join(test_pth, \"test\")\n",
"os.makedirs(test_pth)\n",
"test_pth = Path(f\"/tmp/test_safe_to_delete_{np.random.randint(1e10, 1e12)}\")\n",
"pb_def_save_fname = test_pth / \"test\"\n",
"test_pth.mkdir(parents=True, exist_ok=True)\n",
"print(f\"saving path: {pb_def_save_fname}\")\n",
"\n",
"problem._save_to_dir_(pb_def_save_fname)"
Expand Down
16 changes: 7 additions & 9 deletions docs/source/notebooks/sample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"outputs": [],
"source": [
"# Import required libraries\n",
"import os\n",
"from pathlib import Path\n",
"\n",
"import numpy as np"
]
Expand Down Expand Up @@ -255,9 +255,7 @@
"metadata": {},
"outputs": [],
"source": [
"path_linked_sample = os.path.join(\n",
" os.getcwd(), \"dataset/samples/sample_000000000/meshes/mesh_000000000.cgns\"\n",
")\n",
"path_linked_sample = Path.cwd() / \"dataset/samples/sample_000000000/meshes/mesh_000000000.cgns\"\n",
"new_sample_mult_mesh.link_tree(\n",
" path_linked_sample, linked_sample=sample, linked_time=0.0, time=1.5\n",
")\n",
Expand Down Expand Up @@ -929,10 +927,10 @@
"metadata": {},
"outputs": [],
"source": [
"test_pth = f\"/tmp/test_safe_to_delete_{np.random.randint(1e10, 1e12)}\"\n",
"os.makedirs(test_pth)\n",
"test_pth = Path(f\"/tmp/test_safe_to_delete_{np.random.randint(1e10, 1e12)}\")\n",
"test_pth.mkdir(parents=True, exist_ok=True)\n",
"\n",
"sample_save_fname = os.path.join(test_pth, \"test\")\n",
"sample_save_fname = test_pth / \"test\"\n",
"print(f\"saving path: {sample_save_fname}\")\n",
"\n",
"sample.save(sample_save_fname)"
Expand Down Expand Up @@ -969,9 +967,9 @@
"metadata": {},
"outputs": [],
"source": [
"new_sample_2 = Sample.load_from_dir(os.path.join(test_pth, \"test\"))\n",
"new_sample_2 = Sample.load_from_dir(test_pth / \"test\")\n",
"\n",
"show_sample(new_sample)"
"show_sample(new_sample_2)"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions examples/containers/dataset_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# %%
# Import required libraries
import os
from pathlib import Path

# %%
# Import necessary libraries and functions
Expand Down Expand Up @@ -388,8 +389,8 @@ def dprint(name: str, dictio: dict, end: str = "\n"):
# ### Save the dataset to a TAR (Tape Archive) file

# %%
tmpdir = f"/tmp/test_safe_to_delete_{np.random.randint(low=1, high=2_000_000_000)}"
tmpfile = os.path.join(tmpdir, "test_file.plaid")
tmpdir = Path(f"/tmp/test_safe_to_delete_{np.random.randint(low=1, high=2_000_000_000)}")
tmpfile = tmpdir / "test_file.plaid"

print(f"Save dataset in: {tmpfile}")
dataset.save(tmpfile)
Expand Down
10 changes: 5 additions & 5 deletions examples/containers/sample_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# %%
# Import required libraries
import os
from pathlib import Path

# %%
# Import necessary libraries and functions
Expand Down Expand Up @@ -517,10 +517,10 @@ def show_sample(sample: Sample):
# ### Save Sample to as a file tree

# %%
test_pth = f"/tmp/test_safe_to_delete_{np.random.randint(low=1, high=2_000_000_000)}"
os.makedirs(test_pth)
test_pth = Path(f"/tmp/test_safe_to_delete_{np.random.randint(low=1, high=2_000_000_000)}")
test_pth.mkdir(parents=True, exist_ok=True)

sample_save_fname = os.path.join(test_pth, "test")
sample_save_fname = test_pth / "test"
print(f"saving path: {sample_save_fname}")

sample.save(sample_save_fname)
Expand All @@ -537,7 +537,7 @@ def show_sample(sample: Sample):
# ### Load a Sample from a directory via the Sample class

# %%
new_sample_2 = Sample.load_from_dir(os.path.join(test_pth, "test"))
new_sample_2 = Sample.load_from_dir(test_pth / "test")

show_sample(new_sample)

Expand Down
Loading
Loading