Open jacob-ai-bot[bot] opened 3 weeks ago
Hello human! 👋
This PR was created by JACoB to address the issue Modeling's separability_matrix
does not compute separability correctly for nested CompoundModels
Please review the PR carefully. Auto-generated code can and will contain subtle bugs and mistakes.
If you identify code that needs to be changed, please reject the PR with a specific reason. Be as detailed as possible in your comments. JACoB will take these comments, make changes to the code and push up changes. Please note that this process will take a few minutes.
Once the code looks good, approve the PR and merge the code.
Summary:
Consider the following model:
It's separability matrix as you might expect is a diagonal:
If I make the model more complex:
The output matrix is again, as expected, the outputs and inputs to the linear models are separable and independent of each other.
If however, I nest these compound models:
Suddenly the inputs and outputs are no longer separable?
This feels like a bug to me, but I might be missing something?
@jacob-ai-bot --skip-build --branch issue_12906 https://github.com/astropy/astropy/issues/12906
Plan:
Step 1: Edit
/astropy/modeling/separable.py
Task: Fix separability matrix computation for nested CompoundModels
Instructions: Modify the
_separable
function to correctly handle nestedCompoundModel
instances. The function should recursively traverse the compound model tree and apply the appropriate operator function from the_operators
dictionary based on the operator of eachCompoundModel
. Ensure that the separability matrix is computed correctly for each level of nesting, taking into account the inputs and outputs of each component model. The fix should address the issue where the separability matrix incorrectly indicates non-separability for nested compound models when the component models are actually separable.Exit Criteria: The
separability_matrix
function should return the correct separability matrix for nestedCompoundModel
instances, as demonstrated by the example in the issue description. Specifically, for the modelm.Pix2Sky_TAN() & cm
, wherecm = m.Linear1D(10) & m.Linear1D(5)
, the function should return a diagonal matrix indicating separability.Step 2: Edit
/astropy/modeling/tests/test_separable.py
Task: Update tests for nested CompoundModels
Instructions: Add or modify test cases in
/astropy/modeling/tests/test_separable.py
to specifically test the separability matrix computation for nestedCompoundModel
instances. Include test cases that cover different combinations of operators and models, ensuring that theseparability_matrix
function returns the correct results in all scenarios, particularly for the case described in the issue where nested linear models combined withPix2Sky_TAN
resulted in an incorrect separability matrix. Ensure that the tests cover both separable and non-separable nested compound models.Exit Criteria: All new and existing tests in
/astropy/modeling/tests/test_separable.py
should pass, demonstrating the correct computation of separability matrices for nestedCompoundModel
instances.