Skip to content

Ability to run Python functions in C++ #394

@mattpurvance

Description

@mattpurvance

As per discussion with @IvanGrigorik on March 9, 2026 and Slack messages with @JBludau, this issue is a request for added functionality to be able to run a function defined in Python inside a C++ parallel_ loop. The goal is for users to easily change functionality in the C++ loop without having to change the C++ code base and recompile. Say there is a simple C++ function like:

KOKKOS_FUNCTION void compute(const Matrix<double,6,1> &strain,Matrix<double,6,1> &stress) const {
    stress += strain * 100;
}

That is used inside a parallel_ loop such as:

Kokkos::parallel_for("updateStrainStress",Kokkos::RangePolicy<ExecSpace>(0, num_),KOKKOS_CLASS_LAMBDA(uint64_t mp) {
    DMat vGrad = velGrad_.view_device()(mp);
    SymTen strainInc(0);
    compXX(strainInc) = vGrad(0,0) * timestep;
    compXY(strainInc) = (vGrad(0,1) + vGrad(1,0)) * hTimeStep;
    compYY(strainInc) = vGrad(1,1) * timestep;
    compute(strainInc,stress_.view_device()(mp));
});

The goal is to be able to write a Python function instead for the compute method and then be able to call it inside the updateStrainStress parallel_for loop in C++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions