force-h2020 / force-bdss-plugin-itwm-example

ITWM Example plugin for the BDSS
0 stars 3 forks source link

[Bug] Impurity Concentration DataSource i/o is inconsistent #45

Open Corwinpro opened 5 years ago

Corwinpro commented 5 years ago

The function value and the gradient vector value provided by the ImpurityConcentrationDataSource.run methods seem to be inconsistent. A brute-force check of the finite-difference gradient versus the provided (analytical) gradients, as in:

finite_difference_gradient = (
    function_value(parameter + perturbation) 
    - function_value(parameter)
    ) / pertrurbation
assert finite_difference == analytical_gradient # False

is failing. For instance, the tested function value of the DataSource at test_basic_evaluation is 0.372027129767. The gradient corresponding to the first input parameter (by default set to 0.5) equals approximately 0.01596.

If we perturb the value of the first parameter by 1.e-4, the function value now is 0.37201671105224304, which is equivalent to the gradient of -0.1041871.

I suggest implementing an automated gradient testing in future.

Update

The problem is apparently not in the gradient calculations, but in the discrepancy between the input parameters and the output gradients: the gradient vector is not (directly) related to the parameters vector.

Corwinpro commented 5 years ago

General refactoring of this DataSource would be very much appreciated.