Skip to content

Commit

Permalink
Merge pull request CEED#1533 from CEED/jrwrigh/smartsim_array_size
Browse files Browse the repository at this point in the history
fluids: Change SmartSim sizeInfo to show minimum global array size
  • Loading branch information
jrwrigh authored Apr 8, 2024
2 parents f5b3f54 + 2398c8d commit 2b0a298
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
26 changes: 21 additions & 5 deletions examples/fluids/smartsim_regression_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ class NoError(Exception):
pass


def assert_np_all(test, truth):
"""Assert with better error reporting"""
try:
assert np.all(test == truth)
except Exception as e:
raise Exception(f"Expected {truth}, but got {test}") from e


def assert_equal(test, truth):
"""Assert with better error reporting"""
try:
assert test == truth
except Exception as e:
raise Exception(f"Expected {truth}, but got {test}") from e


class SmartSimTest(object):

def __init__(self, directory_path: Path):
Expand Down Expand Up @@ -66,8 +82,8 @@ def setup(self):
def test(self, ceed_resource) -> Tuple[bool, Exception, str]:
client = None
arguments = []
exe_path = "../../build/fluids-navierstokes"
try:
exe_path = "../../build/fluids-navierstokes"
arguments = [
'-ceed', ceed_resource,
'-options_file', (fluids_example_dir / 'blasius.yaml').as_posix(),
Expand Down Expand Up @@ -96,16 +112,16 @@ def test(self, ceed_resource) -> Tuple[bool, Exception, str]:
client = Client(cluster=False, address=self.database.get_address()[0])

assert client.poll_tensor("sizeInfo", 250, 5)
assert np.all(client.get_tensor("sizeInfo") == np.array([35, 12, 6, 1, 1, 0]))
assert_np_all(client.get_tensor("sizeInfo"), np.array([35, 12, 6, 1, 1, 0]))

assert client.poll_tensor("check-run", 250, 5)
assert client.get_tensor("check-run")[0] == 1
assert_equal(client.get_tensor("check-run")[0], 1)

assert client.poll_tensor("tensor-ow", 250, 5)
assert client.get_tensor("tensor-ow")[0] == 1
assert_equal(client.get_tensor("tensor-ow")[0], 1)

assert client.poll_tensor("step", 250, 5)
assert client.get_tensor("step")[0] == 2
assert_equal(client.get_tensor("step")[0], 2)

assert client.poll_tensor("y.0", 250, 5)
test_data_path = fluids_example_dir / "tests-output/y0_output.npy"
Expand Down
8 changes: 6 additions & 2 deletions examples/fluids/src/smartsim/sgs_dd_training.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, User user, CeedData ceed_data, Pr

{
PetscSection global_section;
PetscInt num_dofs, num_comps;
PetscInt num_dofs, num_comps, local_min_max[2] = {0.}, global_min_max[2] = {0.};

PetscCall(DMGetGlobalSection(sgs_dd_train->dm_dd_training, &global_section));
PetscCall(DMGetGlobalVectorInfo(sgs_dd_train->dm_dd_training, &num_dofs, NULL, NULL));
PetscCall(PetscSectionGetFieldComponents(global_section, 0, &num_comps));
sgs_dd_train->training_data_array_dims[0] = num_dofs / num_comps;
local_min_max[0] = num_dofs;
PetscCall(PetscGlobalMinMaxInt(user->comm, local_min_max, global_min_max));

sgs_dd_train->training_data_array_dims[0] = global_min_max[0] / num_comps;
sgs_dd_train->training_data_array_dims[1] = num_comps;
}

Expand Down

0 comments on commit 2b0a298

Please sign in to comment.