-
Notifications
You must be signed in to change notification settings - Fork 37
Add callback-related tests #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@TimSiebert1: Is it possible to run unit tests in pull requests as well? |
|
Hi @chrhansk, Thanks for adding tests! Unfortunately, the tests have to be added into the folder boost-test and to this CmakeLists. Then the tests will run in the workflow for PRs (see here). I saw that you are using headers that I removed on master while refactoring. You can rely on the main header If you have any questions, don't hesitate to ask for support. :) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #157 +/- ##
==========================================
+ Coverage 40.61% 40.62% +0.01%
==========================================
Files 52 52
Lines 14256 14254 -2
==========================================
+ Hits 5790 5791 +1
+ Misses 8466 8463 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I noticed that to evaluate Hessians, the callback function Unfortunately, this function is not well documented despite being used in the interface. I can see here https://github.com/coin-or/ADOL-C/blob/master/ADOL-C/src/ho_rev.cpp#L223-L239 that |
|
The method Despite being used internally for the higher-order methods, I'm not sure if there ever was a use case for having such freedom. Hope that has made things a little clearer. |
|
Hmm, my problem is the following: i.e., it should use the same (and generally non-zero) Lagrange multiplier for all degrees from 1 to d + 1. If rather than or am I reading something wrong? |
|
Sorry, I didn't write it down in a nice way. The method I was definitely wrong with #include <adolc/adolc.h>
#include <iostream>
int main() {
// --- 1. Create tape ---
const short tapeId = 2;
createNewTape(tapeId);
trace_on(tapeId);
{
adouble a;
a <<= 2.0; // independent variable
adouble b = pow(a, 3.0); // function
double out;
b >>= out; // dependent variable
}
trace_off();
// --- 2. Forward Taylor coefficients ---
int dimIn = 1;
int degre = 3;
double x[1] = {1.0}; // base point
auto X = myalloc2(dimIn, 3); // 1 input, 2 Taylor coefficients
X[0][0] = 1.0;
X[0][1] = 2.0;
X[0][2] = 3.0;
double y[1];
auto Y = myalloc2(dimIn, 3); // 1 output, 2 Taylor coefficients
hos_forward(tapeId, dimIn, dimIn, 3, 4, x, X, y, Y);
std::cout << "1: " << Y[0][0] << std::endl;
std::cout << "2: " << Y[0][1] << std::endl;
std::cout << "3: " << Y[0][2] << std::endl;
// --- 3. Prepare lagrange seeds and results ---
int depen = 1; // 1 output
int indep = 1; // 1 input
auto lagrange = myalloc2(depen, degre + 1);
for (int i = 0; i < depen; ++i) {
lagrange[i][0] = 1.0; // 0-th order seed
for (int j = 1; j <= degre; ++j)
lagrange[i][j] = 0.0; // higher orders 0
}
lagrange[0][1] = 1.0;
auto results = myalloc2(indep, degre + 1); // input adjoints
for (int i = 0; i < indep; ++i)
for (int j = 0; j <= degre; ++j)
results[i][j] = 0.0;
// --- 4. Reverse pass ---
hos_ti_reverse(tapeId, depen, indep, degre, lagrange, results);
// --- 5. Print results ---
std::cout << "Input adjoint coefficients:" << std::endl;
for (int k = 0; k <= degre; ++k) {
std::cout << "results[0][" << k << "] = " << results[0][k] << std::endl;
}
// --- 6. Cleanup ---
myfree2(X);
myfree2(Y);
myfree2(lagrange);
myfree2(results);
return 0;
}
If you set |
|
Thanks for the explanation, that does seem to make sense. But given that this function apparently needs to be implemented to get a Hessian of a callback function it would help a lot if this was properly documented. |
|
I agree. Let me see if I can add something in the next days :). |
No description provided.