vgvassilev / clad

clad -- automatic differentiation for C/C++
GNU Lesser General Public License v3.0
290 stars 122 forks source link

Two functions #903

Closed kkaryos closed 5 months ago

kkaryos commented 5 months ago

I have encountered this error with this code:

Code: double integral(double alpha){ double h=alpha*2; return h; } double si(double x){ double alpha = 1/x ; // a=(M/m)/(kB T) double h =0; h= integral(alpha);

return h; } double x=100.0; std::cout<<si(x); auto Sigma1_dT = clad::differentiate(si,"x");

Error: input_line_42:4:14: error: no matching function for call to 'differentiate' auto Si_dx = clad::differentiate(si,"x"); ^~~~~~~ /home/kkaryos/miniconda3/envs/xeus-clad/include/clad/Differentiator/Differentiator.h:303:3: note: candidate template ignored: substitution failure [with BitMaskedOpts = <>, ArgSpec = const char , F = double ()(double)]: no type named 'type' in 'clad::ExtractDerivedFnTraitsForwMode<double ()(double), void>' differentiate(F fn, ArgSpec args = "", ^ /home/kkaryos/miniconda3/envs/xeus-clad/include/clad/Differentiator/Differentiator.h:323:3: note: candidate template ignored: substitution failure [with BitMaskedOpts = <>, ArgSpec = const char , F = double (&)(double)]: no type named 'type' in 'clad::ExtractDerivedFnTraitsForwMode<double (&)(double), void>' differentiate(F&& f, ArgSpec args = "", ^ /home/kkaryos/miniconda3/envs/xeus-clad/include/clad/Differentiator/Differentiator.h:346:3: note: candidate template ignored: substitution failure [with BitMaskedOpts = <>, ArgSpec = const char , F = double ()(double), DerivedFnType = void (*)(double, clad::array_ref)]: no member named 'value' in 'std::is_class<double (double)>' differentiate(F fn, ArgSpec args = "", ^

Interpreter Error:

I am using jupyter-lab with C++17.

vgvassilev commented 5 months ago

This worked for me:

image

Perhaps the problem is the jupyter kernel somehow?

Can you take a look at our binder service here: https://mybinder.org/v2/gh/vgvassilev/clad/master?labpath=%2Fdemos%2FJupyter%2FIntro.ipynb

kkaryos commented 5 months ago

Thank you very much! The problem seams to be with the use of vectors.I have noticed that when there is a vector in any form in the function, it crashes, even when I am just accessing an element of the vector. The same does not happen with arrays...

Capture d’écran du 2024-05-22 09-41-40 Capture d’écran du 2024-05-22 09-42-01

kkaryos commented 5 months ago

Also the kernel restart on it's own: Capture d’écran du 2024-05-22 16-18-34

vgvassilev commented 5 months ago

Perhaps you are hitting #750. Can you use a fixed-size array in your example until the issue is fixed?

Also, in what context the kernel is automatically restarted?

kkaryos commented 5 months ago

Yes, I have managed to make it work with arrays , but it's not really appropriate for my application (this is just a minimal reproducible example for the error). The kernel restarts running the last cell (In[5]).

vgvassilev commented 5 months ago

Yes, I have managed to make it work with arrays , but it's not really appropriate for my application (this is just a minimal reproducible example for the error).

Ah, I see. Then we will have to wait until that bug report is resolved :(.

The kernel restarts running the last cell (In[5]).

Do you know which kernel you are running? xeus-cling, xeus-cpp?

kkaryos commented 5 months ago

Yes, I have managed to make it work with arrays , but it's not really appropriate for my application (this is just a minimal reproducible example for the error).

Ah, I see. Then we will have to wait until that bug report is resolved :(. It's ok , thanks for your help

The kernel restarts running the last cell (In[5]).

Do you know which kernel you are running? xeus-cling, xeus-cpp? xeus-cling, but I don't think this is the problem because I also get errors when running it in vscode with clad "Built from source".

vgvassilev commented 5 months ago

Yes, I have managed to make it work with arrays , but it's not really appropriate for my application (this is just a minimal reproducible example for the error). Ah, I see. Then we will have to wait until that bug report is resolved :(. It's ok , thanks for your help

The kernel restarts running the last cell (In[5]).

Do you know which kernel you are running? xeus-cling, xeus-cpp? xeus-cling, but I don't think this is the problem because I also get errors when running it in vscode with clad "Built from source".

Can you submit a bug report for the crash if it happens in xeus-cpp or via the static compiler?

kkaryos commented 5 months ago

Yes, I have managed to make it work with arrays , but it's not really appropriate for my application (this is just a minimal reproducible example for the error). Ah, I see. Then we will have to wait until that bug report is resolved :(. It's ok , thanks for your help

The kernel restarts running the last cell (In[5]).

Do you know which kernel you are running? xeus-cling, xeus-cpp? xeus-cling, but I don't think this is the problem because I also get errors when running it in vscode with clad "Built from source".

Can you submit a bug report for the crash if it happens in xeus-cpp or via the static compiler?

Yes, I will ...