-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implementing weakref and cloning #539
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ also avoided bug with materials not being made after data_inputs
MicahGale
added
bugs
A deviation from expected behavior that does not reach the level of being reportable as an "Error".
feature request
An issue that improves the user interface.
labels
Sep 26, 2024
This needs more testing. |
Hopefully final round of reviews. I:
|
MicahGale
added
the
code improvement
A feature request that will improve the software and its maintainability, but be invisible to users.
label
Oct 9, 2024
tjlaboss
approved these changes
Oct 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bugs
A deviation from expected behavior that does not reach the level of being reportable as an "Error".
code improvement
A feature request that will improve the software and its maintainability, but be invisible to users.
feature request
An issue that improves the user interface.
performance 🐌
Issues related to speed and memory
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This focused on making the copying experience better.
First this implemented
weakref.ref
forself._problem
. This breaks a cyclic/recursive memory reference. This was bad for two reasons. First It made problems nearly impossible to garbage collect due to the cyclic references. Secondly it madecopy.deepcopy
very slow and memory costly due to the near infinite recursion in copying. To use aweakref.ref
you have to call it each. So a new attribute_problem_ref
was added to contain this._problem
was made a property to hide the dereferencing operation.weakref.ref
can't be pickled.This pickling conundrum was handled through
__getstate__
and__setstate__
. When pickling theweakref
would be removed. When unpickling though all these refs were gone. There was no easy way to ensure the refs could be built at unpickling because of the order that objects are unpickled. Rather a hook was added to all containscells
,surfaces
, etc. which would check if it had been unpickled and if so quickly recreate all the weakrefs.The other issue then was that a
deepcopy
of aweakref still points to the same object. So the
deepcopy` method was overwritten for a problem so that the references would be to the new problem, and not the old one. For all other objects when they are copied on their own they will point to the same problem as before.All of this work sounded like
clone
. So that was implemented at the same time. This was done in an OpenMC like way.Fixes #514, fixes #469.
Checklist