How to define 2D Polygon with arbitrary number of points

Hi:
I wish to define 2D polygon with arbitrary number of points (around 20 points).

I wish to ask which option is better:
Option 0. Create a user-defined class to import 2D stl file.

Option 1. Create a user-defined class of Polygon using sympy with exact signed distance function (SDF), first calculate the distance of an arbitrary point (x,y) to each line segment in the polygon, then use Sympy Min to obtain the minimum distance.
I tried this option, although Sympy function looks correct, the lambdify of the Sympy function will create a very ridiculous sdf output.

Option 2. Create a user-defined class of Polygon using sympy with ADF (approximate distance function) as sdf. I tried this option and it shows the following error in training:

Error executing job with overrides:
An error occurred during Hydra’s exception formatting:
AssertionError()
Traceback (most recent call last):
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/utils.py”, line 252, in run_and_report
assert mdl is not None
AssertionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “stonecutter-gap0-mod-fourier-val-wjj.py”, line 424, in
run()
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/hydra/utils.py”, line 66, in func_decorated
_run_hydra(
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/utils.py”, line 377, in _run_hydra
run_and_report(
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/utils.py”, line 294, in run_and_report
raise ex
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/utils.py”, line 211, in run_and_report
return func()
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/utils.py”, line 378, in
lambda: hydra.run(
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/hydra.py”, line 111, in run
_ = ret.return_value
File “/opt/conda/lib/python3.8/site-packages/hydra/core/utils.py”, line 233, in return_value
raise self._return_value
File “/opt/conda/lib/python3.8/site-packages/hydra/core/utils.py”, line 160, in run_job
ret.return_value = task_function(task_cfg)
File “stonecutter-gap0-mod-fourier-val-wjj.py”, line 420, in run
slv.solve()
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/continuous/solvers/solver.py”, line 131, in solve
self._train_loop()
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/trainer.py”, line 433, in _train_loop
loss, losses = self.compute_gradients(
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/trainer.py”, line 52, in adam_compute_gradients
losses_minibatch = self.compute_losses(step)
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/continuous/solvers/solver.py”, line 68, in compute_losses
return self.domain.compute_losses(step)
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/continuous/domain/domain.py”, line 99, in compute_losses
constraint_losses = constraint.loss(step)
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/continuous/constraints/constraint.py”, line 126, in loss
pred_outvar = self.model(invar)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 1110, in _call_impl
return forward_call(*input, **kwargs)
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/graph.py”, line 147, in forward
outvar.update(e(outvar))
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 1110, in _call_impl
return forward_call(*input, **kwargs)
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/sympy_utils/torch_printer.py”, line 258, in forward
return {self.name: self.torch_expr(args)}
File “”, line 3, in _lambdifygenerated
RuntimeError: Boolean value of Tensor with more than one value is ambiguous

If I were you I would start from scratch. I have a code that is very close to Modulus but does not use sympy. I manually apply SDF, importance sampling, and other things. Here I get the freedom to use my own data points as the initial sample.

1 Like