Enable optional PyTorch solver#201
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enables an optional PyTorch-based backend for the fluid simulator by adding a new Torch solver and associated configuration, managing its Python interpreter lifecycle, and updating simulation routines accordingly.
- Introduces a torchEnabled flag and related configuration in owConfigProperty.
- Implements initialization and reset routines for the PyTorch solver in owPhysicsFluidSimulator.
- Updates the Python pytorch_solver module with additional methods including a get_state routine.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/owPhysicsFluidSimulator.cpp | Adds PyTorch solver initialization, simulation step updates, and Python cleanup. |
| src/owConfigProperty.cpp | Introduces a new flag and command-line processing for torch-based simulation. |
| pytorch_solver.py | Refactors some functions and adds a get_state method for solver state retrieval. |
| inc/owPhysicsFluidSimulator.h | Declares new torchSolver and useTorchBackend members. |
| inc/owConfigProperty.h | Adds accessor and member for torchEnabled and useTorch flag. |
| ocl_solver = | ||
| new owOpenCLSolver(position_cpp, velocity_cpp, | ||
| config); // Create new openCLsolver instance | ||
| torchSolver = nullptr; |
There was a problem hiding this comment.
The initialization logic for the torchSolver is duplicated between the constructor and reset method. Consider refactoring this code into a helper function to improve maintainability.
| PyObject_CallMethod(torchSolver, "run_hash_particles", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_sort", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_index", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_index_post_pass", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_find_neighbors", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_compute_density", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_compute_pressure", nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_compute_pressure_force_acceleration", | ||
| nullptr); | ||
| PyObject_CallMethod(torchSolver, "run_integrate", nullptr); |
There was a problem hiding this comment.
The series of PyObject_CallMethod calls in simulationStep do not check their return values. Consider verifying these calls to handle potential failures in the Python solver routines.
| PyObject_CallMethod(torchSolver, "run_hash_particles", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_sort", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_index", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_index_post_pass", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_find_neighbors", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_compute_density", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_compute_pressure", nullptr); | |
| PyObject_CallMethod(torchSolver, "run_compute_pressure_force_acceleration", | |
| nullptr); | |
| PyObject_CallMethod(torchSolver, "run_integrate", nullptr); | |
| PyObject *result = PyObject_CallMethod(torchSolver, "run_hash_particles", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_sort", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_index", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_index_post_pass", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_find_neighbors", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_compute_density", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_compute_pressure", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_compute_pressure_force_acceleration", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); | |
| result = PyObject_CallMethod(torchSolver, "run_integrate", nullptr); | |
| if (!result) { PyErr_Print(); return -1; } Py_XDECREF(result); |
Summary
torchEnabled()config helperowPhysicsFluidSimulatorget_stateTesting
./test.shhttps://chatgpt.com/codex/tasks/task_b_6861baca2b58832a80a732106b93599b