Skip to content
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

Added deepcpy functionality and small test for roadrunner. #1347

Merged
merged 8 commits into from
Apr 5, 2024

Conversation

PaulJonasJost
Copy link
Collaborator

Deepcopy functionality is needed for profiling.

@PaulJonasJost PaulJonasJost self-assigned this Apr 2, 2024
@PaulJonasJost PaulJonasJost changed the title Added deepcpy functionality and small test. Added deepcpy functionality and small test for roadrunner. Apr 2, 2024
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.49%. Comparing base (b791e7f) to head (219596d).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1347      +/-   ##
===========================================
+ Coverage    84.33%   84.49%   +0.16%     
===========================================
  Files          157      157              
  Lines        12911    12906       -5     
===========================================
+ Hits         10888    10905      +17     
+ Misses        2023     2001      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pypesto/objective/roadrunner/road_runner.py Outdated Show resolved Hide resolved
Comment on lines 86 to 89
other_rr = roadrunner.RoadRunner()
state = self.roadrunner_instance.saveStateS()
other_rr.loadStateS(state=state)
other.roadrunner_instance = other_rr
Copy link
Member

@dweindl dweindl Apr 2, 2024

Choose a reason for hiding this comment

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

Maybe you can check with the RR devs if __deepcopy__ could be provided by RR.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Actually, if we remove

def __deepcopy__(self, memodict=None) -> "ObjectiveBase":
"""Create deepcopy of objective object."""
other = type(self)() # maintain type for derived classes
for attr, val in self.__dict__.items():
other.__dict__[attr] = copy.deepcopy(val)
return other

this __deepcopy__ function here wouldn't be needed.

Does anybody recall the purpose of ObjectiveBase.__deepcopy__?

Copy link
Member

Choose a reason for hiding this comment

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

There's an option that deepcopys the objective at Problem instantiation.

if copy_objective:
objective = copy.deepcopy(objective)

But I'm not sure why __deepcopy__ is defined, I would expect a default deepcopy(...) to do what is defined in ObjectiveBase.__deepcopy__ already.

Copy link
Member

Choose a reason for hiding this comment

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

I would expect a default deepcopy(...) to do what is defined in ObjectiveBase.__deepcopy__ already.

Exactly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed. Will remove the default deep copy and see whether all tests still work, then merge for now. Might be reverted when RR developers add a deepcopy function.

Copy link
Member

Choose a reason for hiding this comment

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

Will remove the default deep copy and see whether all tests still work, then merge for now.

Not only ObjectiveBase.__deepcopy__, but also RoadRunnerObjective.__deepcopy__.

Might be reverted when RR developers add a deepcopy function.

No, that wouldn't require any change then.

Copy link
Collaborator Author

@PaulJonasJost PaulJonasJost Apr 5, 2024

Choose a reason for hiding this comment

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

ah so deepcopy in its original behaviour would use the __set/getstate__ functionality from RR?

Copy link
Member

Choose a reason for hiding this comment

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

deepcopy will fall back to __getstate__/ __setstate__, which exist (see Dilan's comment above)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good 👍🏼 will remove it but keep the tests, as I think we should still make sure it is working?

Co-authored-by: Daniel Weindl <dweindl@users.noreply.github.com>
@PaulJonasJost PaulJonasJost merged commit 38d91c4 into develop Apr 5, 2024
18 checks passed
@PaulJonasJost PaulJonasJost deleted the roadrunner_deepcopy branch April 5, 2024 11:37
This was referenced Apr 9, 2024
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.

4 participants