Skip to content

Enable optional PyTorch solver#201

Merged
slarson merged 1 commit into
ow-pytorch-0.0.1from
codex/integrate-pytorch_solver-with-pybind11
Jun 29, 2025
Merged

Enable optional PyTorch solver#201
slarson merged 1 commit into
ow-pytorch-0.0.1from
codex/integrate-pytorch_solver-with-pybind11

Conversation

@slarson
Copy link
Copy Markdown
Member

@slarson slarson commented Jun 29, 2025

Summary

  • allow selecting a PyTorch-based backend
  • expose new torchEnabled() config helper
  • manage Python solver lifetime in owPhysicsFluidSimulator
  • call into Python solver routines instead of OpenCL when selected
  • return position/velocity from Python solver via new get_state

Testing

  • ./test.sh

https://chatgpt.com/codex/tasks/task_b_6861baca2b58832a80a732106b93599b

@slarson slarson requested a review from Copilot June 29, 2025 22:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +483 to +492
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);
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
@slarson slarson merged commit c0024e4 into ow-pytorch-0.0.1 Jun 29, 2025
4 checks passed
@slarson slarson deleted the codex/integrate-pytorch_solver-with-pybind11 branch June 29, 2025 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants