How to define 2D Polygon with arbitrary number of points

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:
Traceback (most recent call last):
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/”, line 252, in run_and_report
assert mdl is not None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 424, in
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/hydra/”, line 66, in func_decorated
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/”, line 377, in _run_hydra
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/”, line 294, in run_and_report
raise ex
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/”, line 211, in run_and_report
return func()
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/”, line 378, in
File “/opt/conda/lib/python3.8/site-packages/hydra/_internal/”, line 111, in run
_ = ret.return_value
File “/opt/conda/lib/python3.8/site-packages/hydra/core/”, line 233, in return_value
raise self._return_value
File “/opt/conda/lib/python3.8/site-packages/hydra/core/”, line 160, in run_job
ret.return_value = task_function(task_cfg)
File “”, line 420, in run
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/continuous/solvers/”, line 131, in solve
File “/opt/conda/lib/python3.8/site-packages/modulus-22.3-py3.8.egg/modulus/”, 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/”, 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/”, 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/”, 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/”, line 126, in loss
pred_outvar = self.model(invar)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/”, 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/”, line 147, in forward
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/”, 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/”, line 258, in forward
return { 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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.