Note that your Python main ptsc4py program can call C/C++ code for some of 
its computations, so if you have a lot of C/C++ code you do not need to change 
it all to Python. It is also possible to call Petsc4py (and hence PyTorch) from 
a C/C++ main but a bit more cumbersome so not recommended. See 
src/ksp/ksp/tutorials/ex100.c and ex100.py for an example of a C/C++ main that 
uses petsc4py (in a limited way). 

> On Jun 13, 2022, at 4:42 PM, Zhang, Hong via petsc-users 
> <[email protected]> wrote:
> 
> No. It is not common to execute Python scripts or libraries from C/C++ code. 
> If you are looking for ways to use PETSc and PyTorch together, it is best to 
> build your application in Python so that you can use both petsc4py and 
> PyTorch. See the following code for an example:
> https://github.com/caidao22/pnode <https://github.com/caidao22/pnode>
> 
> Hong (Mr.)
> 
>> On Jun 13, 2022, at 9:50 AM, Amneet Bhalla <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> 
>> Hi Guys,
>> 
>> Is there a PETSc interface to make calls to Python scripts or libraries 
>> (e.g., Pytorch) from a C/C++ code making use of PETSc? If so, are there some 
>> examples that I refer to?
>> 
>> Thanks, 
>> -- 
>> --Amneet 
>> 
>> 
>> 
> 

Reply via email to