NVIDIA / modulus-sym

Framework providing pythonic APIs, algorithms and utilities to be used with Modulus core to physics inform model training as well as higher level abstraction for domain experts
https://developer.nvidia.com/modulus
Apache License 2.0
147 stars 60 forks source link

🚀[FEA]: Highly inefficient sampling in Vector_Test #26

Open zinccat opened 1 year ago

zinccat commented 1 year ago

When working on a 3D problem, the memory usage of Vector_Test is too high compared to the actual sampled points. An example is shown below which caused crash.

test_fn = Test_Function(
            name_ord_dict={
                Trig_test: [k for k in range(8)],
            },
            diff_list=["grad"],
            box=self.box,
)
self.v = Vector_Test(test_fn, test_fn, test_fn, mix=10)

This is because sample_vector_test in test_functions.py used itertools to perform the sampling, which takes too much memory when range(self.v1.num_fcn) is high. E.g.,

import random
import itertools

output_ind = random.sample(
    set(
        itertools.product(
            range(1080),
            range(1080),
            range(1080),
        )
    ),
    10,
)
print(output_ind)

Maybe choosing random indices from the whole product indices pool (rangr(abc)) is a better choice.