[go: up one dir, main page]

Chain rule and adjoint optimized detection of differentiated inputs and outputs fails for processes with parallel branches

Summary

The chain rule and adjoint optimized detection of differentiated inputs and outputs fails for processes with parallel branches. For such a process, it then leads to incorrect total derivatives.

Gemseo version

Current develop

Platform info

Not relevant

Environment info

Not relevant

Steps to reproduce

The following code reproduces the bug:

from __future__ import annotations

from pathlib import Path

import numpy as np
import pytest
from gemseo.core.coupling_structure import MDOCouplingStructure
from gemseo.core.derivatives.jacobian_assembly import JacobianAssembly
from gemseo.core.discipline import MDODiscipline
from gemseo.core.grammars.json_grammar import JSONGrammar
from gemseo.core.grammars.simple_grammar import SimpleGrammar
from gemseo.mda.mda_chain import MDAChain
from numpy import array
from numpy import isclose
from numpy import ones

from tests.mda.test_mda import analytic_disciplines_from_desc

disciplines = analytic_disciplines_from_desc(
    (
        {"a": "x"},
        {"y1": "x1", "b": "a+1"},
        {"x1": "1.-0.3*y1"},
        {"y2": "x2", "c": "a+2"},
        {"x2": "1.-0.3*y2"},
        {"obj1": "x1+x2"},
        {"obj2": "b+c"},
        {"obj": "obj1+obj2"},
    )
)
mdachain = MDAChain(disciplines, name="mdachain_lower")
assert mdachain.check_jacobian(inputs=["x"], outputs=["obj"])

What is the current bug behavior?

In the test above, the assertion fails

What is the expected correct behavior?

The assertion should pass

Relevant logs and/or screenshots

Not relevant

Possible fixes

Investigations are on-going. It seems that the graph traversal algorithm may be the root cause of the issue.