Huangzizhou / DiffIPC-data

Differentiable solver for time-dependent deformation problems with contact
https://cims.nyu.edu/~zh1476/research/diffipc.html
MIT License
25 stars 3 forks source link

polyfempy issue #3

Open antoinebou12 opened 8 hours ago

antoinebou12 commented 8 hours ago

{
    "name": "TypeError",
    "message": "set_settings(): incompatible function arguments. The following argument types are supported:
    1. (self: polyfempy.polyfempy.Solver, json: object) -> None

Invoked with: <polyfempy.polyfempy.Solver object at 0x7fd70ac9ad70>, '{\"geometry\": [{\"mesh\": \"slide.msh\", \"is_obstacle\": true, \"volume_selection\": 3, \"surface_selection\": 3}, {\"mesh\": \"stanford-bunny.obj_.msh\", \"transformation\": {\"translation\": [0.5, -0.13, -0.7], \"rotation\": [0, 0, 0], \"rotation_mode\": \"xyz\", \"scale\": 4}, \"volume_selection\": 1, \"surface_selection\": 1}], \"space\": {\"discr_order\": 1, \"advanced\": {\"quadrature_order\": 5}}, \"time\": {\"tend\": 1, \"dt\": 0.05}, \"contact\": {\"enabled\": true, \"friction_coefficient\": 0.5}, \"solver\": {\"linear\": {\"solver\": [\"Eigen::PardisoLDLT\", \"Eigen::AccelerateLDLT\", \"Eigen::SimplicialLDLT\"]}, \"nonlinear\": {\"line_search\": {\"method\": \"Backtracking\"}, \"grad_norm\": 1e-06}, \"contact\": {\"barrier_stiffness\": 100000.0}}, \"initial_conditions\": {\"velocity\": [{\"id\": 1, \"value\": [0, 0, 2]}]}, \"boundary_conditions\": {\"rhs\": [0, 9.8, 0], \"dirichlet_boundary\": [{\"id\": 3, \"value\": [0, 0, 0]}]}, \"materials\": {\"type\": \"NeoHookean\", \"E\": 100000.0, \"nu\": 0.48, \"rho\": 1000}, \"output\": {\"paraview\": {\"file_name\": \"sim.pvd\", \"high_order_mesh\": false, \"surface\": true, \"volume\": false, \"vismesh_rel_area\": 1}, \"advanced\": {\"save_time_sequence\": true}, \"directory\": \"result\", \"log\": {\"level\": \"info\"}}, \"root_path\": \"./run.json\"}', True",
    "stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 7
      4     config[\"root_path\"] = root + \"/run.json\"
      6 # Simulation
----> 7 solver1 = create_solver(config)
      8 config[\"contact\"][\"friction_coefficient\"] = 0.1
      9 solver2 = create_solver(config)

Cell In[3], line 5, in create_solver(args)
      3 def create_solver(args):
      4     solver = pf.Solver()
----> 5     solver.set_settings(json.dumps(args), True)
      6     solver.set_log_level(log_level)
      7     solver.load_mesh_from_settings()

TypeError: set_settings(): incompatible function arguments. The following argument types are supported:
    1. (self: polyfempy.polyfempy.Solver, json: object) -> None

Invoked with: <polyfempy.polyfempy.Solver object at 0x7fd70ac9ad70>, '{\"geometry\": [{\"mesh\": \"slide.msh\", \"is_obstacle\": true, \"volume_selection\": 3, \"surface_selection\": 3}, {\"mesh\": \"stanford-bunny.obj_.msh\", \"transformation\": {\"translation\": [0.5, -0.13, -0.7], \"rotation\": [0, 0, 0], \"rotation_mode\": \"xyz\", \"scale\": 4}, \"volume_selection\": 1, \"surface_selection\": 1}], \"space\": {\"discr_order\": 1, \"advanced\": {\"quadrature_order\": 5}}, \"time\": {\"tend\": 1, \"dt\": 0.05}, \"contact\": {\"enabled\": true, \"friction_coefficient\": 0.5}, \"solver\": {\"linear\": {\"solver\": [\"Eigen::PardisoLDLT\", \"Eigen::AccelerateLDLT\", \"Eigen::SimplicialLDLT\"]}, \"nonlinear\": {\"line_search\": {\"method\": \"Backtracking\"}, \"grad_norm\": 1e-06}, \"contact\": {\"barrier_stiffness\": 100000.0}}, \"initial_conditions\": {\"velocity\": [{\"id\": 1, \"value\": [0, 0, 2]}]}, \"boundary_conditions\": {\"rhs\": [0, 9.8, 0], \"dirichlet_boundary\": [{\"id\": 3, \"value\": [0, 0, 0]}]}, \"materials\": {\"type\": \"NeoHookean\", \"E\": 100000.0, \"nu\": 0.48, \"rho\": 1000}, \"output\": {\"paraview\": {\"file_name\": \"sim.pvd\", \"high_order_mesh\": false, \"surface\": true, \"volume\": false, \"vismesh_rel_area\": 1}, \"advanced\": {\"save_time_sequence\": true}, \"directory\": \"result\", \"log\": {\"level\": \"info\"}}, \"root_path\": \"./run.json\"}', True"
}

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[12], [line 13](vscode-notebook-cell:?execution_count=12&line=13)
     [10](vscode-notebook-cell:?execution_count=12&line=10) solver2 = create_solver(config)
     [12](vscode-notebook-cell:?execution_count=12&line=12) param = torch.tensor([0.2], requires_grad=True)
---> [13](vscode-notebook-cell:?execution_count=12&line=13) solution2 = Simulate.apply(solver2, torch.tensor([0.1]))
     [15](vscode-notebook-cell:?execution_count=12&line=15) def loss(param):
     [16](vscode-notebook-cell:?execution_count=12&line=16)     solution1 = Simulate.apply(solver1, param)

File ~/.local/lib/python3.10/site-packages/torch/autograd/function.py:574, in Function.apply(cls, *args, **kwargs)
    [571](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:571) if not torch._C._are_functorch_transforms_active():
    [572](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:572)     # See NOTE: [functorch vjp and autograd interaction]
    [573](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:573)     args = _functorch.utils.unwrap_dead_wrappers(args)
--> [574](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:574)     return super().apply(*args, **kwargs)  # type: ignore[misc]
    [576](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:576) if not is_setup_ctx_defined:
    [577](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:577)     raise RuntimeError(
    [578](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:578)         "In order to use an autograd.Function with functorch transforms "
    [579](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:579)         "(vmap, grad, jvp, jacrev, ...), it must override the setup_context "
    [580](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:580)         "staticmethod. For more details, please see "
    [581](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:581)         "https://pytorch.org/docs/main/notes/extending.func.html"
    [582](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/antoine/polystack/DiffIPC-data/python_scripts/fig21_friction_bunny/~/.local/lib/python3.10/site-packages/torch/autograd/function.py:582)     )

Cell In[2], [line 6](vscode-notebook-cell:?execution_count=2&line=6)
      [3](vscode-notebook-cell:?execution_count=2&line=3) @staticmethod
      [4](vscode-notebook-cell:?execution_count=2&line=4) def forward(ctx, solver, fric):
      [5](vscode-notebook-cell:?execution_count=2&line=5)     # Update solver setup
----> [6](vscode-notebook-cell:?execution_count=2&line=6)     solver.set_friction_coefficient(float(fric[0]))
      [8](vscode-notebook-cell:?execution_count=2&line=8)     # Enable caching intermediate variables in the simulation, which will be used for solve_adjoint
      [9](vscode-notebook-cell:?execution_count=2&line=9)     solver.set_cache_level(pf.CacheLevel.Derivatives)

AttributeError: 'polyfempy.polyfempy.Solver' object has no attribute 'set_friction_coefficient'

the polyfempy got the set_friction_coefficient

antoinebou12 commented 7 hours ago

can you share your polyfempy version

Huangzizhou commented 7 hours ago

Hi Antoine,

You might have used the polyfempy in the polyfem repo, which has been deprecated for a long time. As I mentioned in the readme, please use the polyfempy fork here: https://github.com/Huangzizhou/polyfem-python. We are still working on merging this fork into the official repo.

Zizhou

antoinebou12 commented 7 hours ago

btw cool projects. I was looking in your public repo but i forgot to put the fork filter un github sorry