Skip to content

Commit 2eb0d2e

Browse files
authored
fix: meshstats abstract_eval (#120)
#### Relevant issue or PR n/a #### Description of changes Noticed that meshstats `abstract_eval` is wrong (crashes), so I fixed it + added a test. #### Testing done CI, new test #### License - [x] By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license](https://pasteurlabs.github.io/tesseract/LICENSE). - [x] I sign the Developer Certificate of Origin below by adding my name and email address to the `Signed-off-by` line. <details> <summary><b>Developer Certificate of Origin</b></summary> ```text Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` </details> Signed-off-by: Dion Häfner <dion.haefner@simulation.science>
1 parent fd5fc46 commit 2eb0d2e

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

examples/meshstats/tesseract_api.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
from tesseract_core.runtime import Array, Differentiable, Float32, Int32, ShapeDType
88

9-
109
#
1110
# Schemas
1211
#
12+
13+
1314
class VolumetricMeshData(BaseModel):
1415
"""Mock mesh schema; shapes not validated."""
1516

@@ -25,12 +26,16 @@ class VolumetricMeshData(BaseModel):
2526

2627
@model_validator(mode="after")
2728
def validate_num_points_per_cell(self):
29+
if not isinstance(self.num_points_per_cell, np.ndarray):
30+
return self
2831
if len(self.num_points_per_cell) != self.n_cells:
2932
raise ValueError(f"Length of num_points_per_cell must be {self.n_cells}")
3033
return self
3134

3235
@model_validator(mode="after")
3336
def validate_cell_connectivity(self):
37+
if not isinstance(self.cell_connectivity, np.ndarray):
38+
return self
3439
expected_len = sum(self.num_points_per_cell)
3540
if len(self.cell_connectivity) != expected_len:
3641
raise ValueError(f"Length of cell_connectivity must be {expected_len}")
@@ -59,6 +64,8 @@ class OutputSchema(BaseModel):
5964
#
6065
# Required endpoints
6166
#
67+
68+
6269
def apply(inputs: InputSchema) -> OutputSchema:
6370
points = inputs.mesh.points
6471

@@ -76,15 +83,15 @@ def apply(inputs: InputSchema) -> OutputSchema:
7683

7784

7885
def abstract_eval(abstract_inputs):
79-
input_points_shapedtype = abstract_inputs["mesh"]["points"]
86+
input_points_shapedtype = abstract_inputs.mesh.points
8087

8188
# get dimension of vector space points live in from input
82-
dim = input_points_shapedtype[1]
89+
dim = input_points_shapedtype.shape[1]
8390
dtype = input_points_shapedtype.dtype
8491
return {
8592
"statistics": {
8693
"first_point_coordinates": ShapeDType(shape=(dim,), dtype=dtype),
87-
"barycenter": ShapeDType(shape=(dim,), dtype="float"),
94+
"barycenter": ShapeDType(shape=(dim,), dtype="float32"),
8895
}
8996
}
9097

tests/endtoend_tests/test_examples.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,50 @@ class Config:
542542
np.array([0.0, 666.0, 0.0], dtype="float32"), as_json=True
543543
),
544544
),
545+
SampleRequest(
546+
endpoint="abstract_eval",
547+
payload={
548+
"inputs": {
549+
"mesh": {
550+
"n_points": 5,
551+
"n_cells": 8,
552+
"points": {
553+
"shape": [5, 3],
554+
"dtype": "float32",
555+
},
556+
"num_points_per_cell": {
557+
"shape": [2],
558+
"dtype": "int32",
559+
},
560+
"cell_connectivity": {
561+
"shape": [8],
562+
"dtype": "int32",
563+
},
564+
"cell_data": {
565+
"temperature": {
566+
"shape": [2, 2],
567+
"dtype": "float32",
568+
},
569+
"pressure": {
570+
"shape": [2, 2],
571+
"dtype": "float32",
572+
},
573+
},
574+
"point_data": {
575+
"displacement": {
576+
"shape": [5, 3],
577+
"dtype": "float32",
578+
},
579+
"velocity": {
580+
"shape": [5, 3],
581+
"dtype": "float32",
582+
},
583+
},
584+
}
585+
},
586+
},
587+
output_contains_pattern='"shape":[3],"dtype":"float32"',
588+
),
545589
SampleRequest(
546590
endpoint="jacobian",
547591
payload={

0 commit comments

Comments
 (0)