Skip to content

Conversation

RohitP2005
Copy link
Contributor

Description

Refactored the process function in base_solver.pyto simplify its logic and improve maintainability.

Fixes #4970

Type of change

Refactor (non-breaking change that improves code structure) to the process function in the base solver to enforce return_jacp_stacked=True .

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@RohitP2005
Copy link
Contributor Author

@martinjrobins
I've refactored the process function in base_solver.py to simplify the logic Could you please take a look at the changes? If everything looks good, we can go ahead and check the CI tests.

Thanks!

Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @RohitP2005, I think there is much more to do on this (than just removing the arg. Have you run the tests locally?

else:
jac = None
jac_action = None
jac = func.get_jacobian() if use_jacobian else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the single if statement is less complex then multiple, plus you are removing the report, so I'd disagree with this change

else:
jacp = None

if use_jacobian:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this one

f"Calculating sensitivities for {name} with respect "
f"to parameters {model.calculate_sensitivities} using "
"CasADi"
report(f"Calculating sensitivities for {name} using CasADi")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its useful to have the printout of model.calculate_sensitivities here, so keep this

)
# Compute derivate wrt p-stacked (can be passed to solver to
# compute sensitivities online)
if return_jacp_stacked:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this if statement is only a small part of this change, you will also need to change the behaviour of the solvers that depend on this functionality (I believe, but I'll run the tests so we can check)

@RohitP2005
Copy link
Contributor Author

Hi @RohitP2005, I think there is much more to do on this (than just removing the arg. Have you run the tests locally?

Yes , I ran the tests locally and there are errors that needs to addressed.
we fix those issues and make the requested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: always return_jacp_stacked
2 participants