Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"forward_best_objective": 1481.1424852869957,
"finite_outputs": true
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"adjoint-relative-residual": "/home/liblaf/github/liblaf/apple/exp/2026/01/28/smas/data/31-inverse-smas46-muscle46-activation-stable-neo-hookean-easy-metrics-adjoint-relative-residual.png",
"inverse-grad-absolute": "/home/liblaf/github/liblaf/apple/exp/2026/01/28/smas/data/31-inverse-smas46-muscle46-activation-stable-neo-hookean-easy-metrics-inverse-grad-absolute.png"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,4 @@
"forward_best_objective": 1485.5675728610533,
"finite_outputs": true
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"adjoint-relative-residual": "/home/liblaf/github/liblaf/apple/exp/2026/01/28/smas/data/31-inverse-smas46-muscle46-activation-stable-neo-hookean-zero-metrics-adjoint-relative-residual.png",
"inverse-grad-absolute": "/home/liblaf/github/liblaf/apple/exp/2026/01/28/smas/data/31-inverse-smas46-muscle46-activation-stable-neo-hookean-zero-metrics-inverse-grad-absolute.png"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@
"repeated/forward_failure": false,
"repeated/adjoint_failure": false,
"passed": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16721,4 +16721,4 @@
"repeated/forward_failure": false,
"repeated/adjoint_failure": false,
"passed": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@
"repeated/forward_failure": false,
"repeated/adjoint_failure": false,
"passed": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"forward/line_search_steps": 0,
"forward/stagnation_count": 0,
"time/forward_s": 16.038381466001738
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"forward/line_search_steps": 0,
"forward/stagnation_count": 0,
"time/forward_s": 6.737611743999878
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"forward/line_search_steps": 0,
"forward/stagnation_count": 0,
"time/forward_s": 3.82475233200239
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"forward/line_search_steps": 0,
"forward/stagnation_count": 0,
"time/forward_s": 3.6330396700068377
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"forward/line_search_steps": 0,
"forward/stagnation_count": 0,
"time/forward_s": 4.520490328024607
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"forward/line_search_steps": 0,
"forward/stagnation_count": 0,
"time/forward_s": 6.646797652996611
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The four concrete cases were:
## Results

| case | cells | active tets | steps | target mean cm | target RMS cm | target max cm | all RMS cm | all max cm | forward s |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| 515k, SMAS 100 | 253876 | 58494 | 421 | 0.422151 | 0.475055 | 1.297573 | 0.368954 | 9.127733 | 3.825 |
| 515k, SMAS 1 | 253876 | 58494 | 244 | 0.274502 | 0.318913 | 0.942866 | 0.243835 | 1.195187 | 3.633 |
| 3152k, SMAS 100 | 1127541 | 283391 | 82 | 0.242941 | 0.309361 | 1.033624 | 0.200444 | 3.558038 | 4.520 |
Expand Down
12 changes: 9 additions & 3 deletions exp/2026/05/20/inverse-face/src/10-prepare-inverse-face.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def add_material_fields(mesh: pv.UnstructuredGrid, cfg: Config) -> None:
zero_activation_fields(mesh)


def fixed_point_mask(mesh: pv.UnstructuredGrid, cfg: Config) -> tuple[np.ndarray, dict[str, int]]:
def fixed_point_mask(
mesh: pv.UnstructuredGrid, cfg: Config
) -> tuple[np.ndarray, dict[str, int]]:
fixed = np.zeros(mesh.n_points, dtype=bool)
counts: dict[str, int] = {}
for name in cfg.fixed_point_masks:
Expand Down Expand Up @@ -222,8 +224,12 @@ def metric_summary(
"n_active_tets": int(np.asarray(mesh.cell_data["ActivationMask"]).sum()),
"n_target_points": int(target_mask.sum()),
"n_fixed_points": int(np.asarray(mesh.point_data["FixedBoundary"]).sum()),
"n_fixed_cranium_points": int(np.asarray(mesh.point_data["FixedCranium"]).sum()),
"n_fixed_mandible_points": int(np.asarray(mesh.point_data["FixedMandible"]).sum()),
"n_fixed_cranium_points": int(
np.asarray(mesh.point_data["FixedCranium"]).sum()
),
"n_fixed_mandible_points": int(
np.asarray(mesh.point_data["FixedMandible"]).sum()
),
"muscle_fraction_volume": float(np.sum(muscle * volume)),
"smas_fraction_volume": float(np.sum(smas * volume)),
"target_displacement_mean": float(target_norm.mean()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"IsLipBottom/target_rms": 0.3993310920970844,
"IsLipBottom/target_max": 1.0284059764202034,
"IsLipBottom/rms_ratio_to_target": 0.30975080437456287
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"IsLipBottom/target_rms": 0.3993310920970844,
"IsLipBottom/target_max": 1.0284059764202034,
"IsLipBottom/rms_ratio_to_target": 0.3094006908630162
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"IsLipBottom/target_rms": 0.42244197929946425,
"IsLipBottom/target_max": 1.016519397545366,
"IsLipBottom/rms_ratio_to_target": 0.12364134545496203
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4974,4 +4974,4 @@
"activation_inv/error_rms": 0.2491769718442089,
"activation_inv/error_max_norm": 0.6141888156955176,
"passed": true
}
}
8 changes: 6 additions & 2 deletions exp/2026/05/27/forward-face/src/10-prepare-forward-face.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ def metric_summary(
"activation/n_tets": int(active.sum()),
"target/n_points": int(target_mask.sum()),
"fixed/n_points": int(fixed.sum()),
"fixed/n_cranium_points": int(np.asarray(mesh.point_data["FixedCranium"]).sum()),
"fixed/n_mandible_points": int(np.asarray(mesh.point_data["FixedMandible"]).sum()),
"fixed/n_cranium_points": int(
np.asarray(mesh.point_data["FixedCranium"]).sum()
),
"fixed/n_mandible_points": int(
np.asarray(mesh.point_data["FixedMandible"]).sum()
),
"volume/muscle_fraction": float(np.sum(muscle * volume)),
"volume/smas_fraction": float(np.sum(smas * volume)),
"volume/smas_stiffness_fraction": float(np.sum(smas_stiffness * volume)),
Expand Down
12 changes: 9 additions & 3 deletions exp/2026/05/27/forward-face/src/20-forward-face.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def set_material(
mesh.cell_data[FRACTION.vtk] = np.asarray(fraction, dtype=np.float64)


def unpack_symmetric(values: tuple[float, float, float, float, float, float]) -> np.ndarray:
def unpack_symmetric(
values: tuple[float, float, float, float, float, float],
) -> np.ndarray:
xx, yy, zz, xy, xz, yz = values
return np.asarray(
[[xx, xy, xz], [xy, yy, yz], [xz, yz, zz]],
Expand Down Expand Up @@ -304,7 +306,9 @@ def summarize(
elapsed_s: float,
cfg: Config,
) -> dict[str, Any]:
target_displacement = np.asarray(target.point_data["Displacement"], dtype=np.float64)
target_displacement = np.asarray(
target.point_data["Displacement"], dtype=np.float64
)
active = np.asarray(mesh.cell_data["ActivationMask"], dtype=bool)
volume = np.asarray(mesh.cell_data["Volume"], dtype=np.float64)
muscle = np.asarray(mesh.cell_data["MuscleFraction"], dtype=np.float64)
Expand Down Expand Up @@ -356,7 +360,9 @@ def make_result_mesh(
metrics: dict[str, float | int | bool | str],
) -> pv.UnstructuredGrid:
result = mesh.copy(deep=True)
target_displacement = np.asarray(target.point_data["Displacement"], dtype=np.float64)
target_displacement = np.asarray(
target.point_data["Displacement"], dtype=np.float64
)
error = displacement - target_displacement
result.point_data["Displacement"] = displacement
result.point_data["DisplacementNorm"] = np.linalg.norm(displacement, axis=1)
Expand Down
30 changes: 21 additions & 9 deletions exp/2026/05/27/forward-face/src/30-inverse-face-515k.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ def local_deltas_from_activation_inv(
local_activation_inv = eye + matrix_from_symmetric(local_activation_inv_delta)
local_activation = np.linalg.inv(local_activation_inv)
local_activation_delta = pack_symmetric_np(local_activation[None, ...] - eye)[0]
return local_activation_delta, np.asarray(local_activation_inv_delta, dtype=np.float64)
return local_activation_delta, np.asarray(
local_activation_inv_delta, dtype=np.float64
)


def activation_inv_from_local_delta(
Expand Down Expand Up @@ -553,7 +555,9 @@ def make_result_mesh(

result = mesh.copy(deep=True)
add_masks(result, target_ids, active_ids)
target_displacement = np.asarray(target.point_data["Displacement"], dtype=np.float64)
target_displacement = np.asarray(
target.point_data["Displacement"], dtype=np.float64
)
error = displacement - target_displacement
result.point_data["Displacement"] = displacement
result.point_data["DisplacementNorm"] = np.linalg.norm(displacement, axis=1)
Expand Down Expand Up @@ -698,7 +702,9 @@ def adjoint_solve(self, u_grad: torch.Tensor) -> Any:
device=torch.get_default_device(),
)
local_activation_inv_delta = torch.nn.Parameter(
torch.zeros(6, dtype=torch.get_default_dtype(), device=torch.get_default_device())
torch.zeros(
6, dtype=torch.get_default_dtype(), device=torch.get_default_device()
)
)
optimizer = torch.optim.Adam(
[local_activation_inv_delta],
Expand Down Expand Up @@ -936,7 +942,9 @@ def summarize(
) -> dict[str, Any]:
from liblaf.apple.common import ACTIVATION_INV

target_displacement = np.asarray(target.point_data["Displacement"], dtype=np.float64)
target_displacement = np.asarray(
target.point_data["Displacement"], dtype=np.float64
)
error = displacement - target_displacement
target_error = error[target_ids]
target_error_norm = np.linalg.norm(target_error, axis=1)
Expand Down Expand Up @@ -1039,10 +1047,12 @@ def main(cfg: Config) -> None:
_, local_activation_inv_delta = local_deltas_from_activation_inv(
recovered_local_activation_inv_delta
)
activation, activation_inv, local_activation_delta = full_activation_fields_from_local(
mesh,
active_ids,
local_activation_inv_delta,
activation, activation_inv, local_activation_delta = (
full_activation_fields_from_local(
mesh,
active_ids,
local_activation_inv_delta,
)
)
total_elapsed_s = time.perf_counter() - total_start
summary = summarize(
Expand Down Expand Up @@ -1075,7 +1085,9 @@ def main(cfg: Config) -> None:
try:
save_snapshot(cfg.output_snapshot, result)
except (OSError, RuntimeError, ValueError):
logger.warning("failed to save snapshot: %s", cfg.output_snapshot, exc_info=True)
logger.warning(
"failed to save snapshot: %s", cfg.output_snapshot, exc_info=True
)
save_json(cfg.output_summary, summary)
cherries.log_metrics(numeric_metrics(summary, exclude=frozenset({"trace"})))
print(
Expand Down
Loading
Loading