-
Notifications
You must be signed in to change notification settings - Fork 14
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
Refactor ZOSPy core and remove deprecated functions #107
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
Without this assignment, the weak ref in _instances is immediately garbage collected.
Because OpticStudioSystem._ZOS is not only used internally, it is better to make it public. Furthermore, it is now a weak reference to the ZOS instance, to prevent oss from blocking the termination of ZOS.
To do:
|
LucVV
reviewed
Feb 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proposed change
zpcore
has been refactored and deprecated methods inzospy.zpcore
andzospy.functions
have been removed.Notable changes:
ZOS
is now a singleton. Callingzospy.ZOS
for the second time will raise a warning and return the existing instance. I used aweakref.WeakValueDictionary
to store the existing instance. Because the dictionary will at most contain a single value, using aweakref.ref
object would be possible as well, but this would require explicitly setting the value toNone
on initialization and deletion. The current implementation will automatically empty the dictionary. Alternatively, aweakref.WeakSet
would work as well, but retrieving a single value from a dictionary is a bit easier than retrieving it from a set. Please explain which option you prefer as part of the review.ZOS
has a new classmethodget_instance
that allows to get an existing instance if available. Unlike__init__
, calling this method will not create a new instance. This method could for instance be used to make theoss
parameter for analyses optional, automatically using the primary system of a connected instance ifoss
is not specified.OpticStudioSystem._ZOS
was renamed toZOS
, making it public. We use it quite a lot outsideOpticStudioSystem
itself, e.g. to check for the OpticStudio version, so I think it makes sense to make it a public attribute. Alternatively, we may opt for adding a separateversion
attribute toOpticStudioSystem
. Please comment on this as part of the review.OpticStudioSystem.ZOS
is now aweakref.proxy
object, so removing theZOS
instance (e.g. withdel zos
) will work without first removing theOpticStudioSystem
instance. Previously,oss
blocked the garbage collector from deletingZOS
instances if there were stillOpticStudioSystem
instances around, see Deleting theZOS
instance doesn't (always) work #61.Type of change
Additional information
Related issues
Checklist
If you contributed an analysis:
AttrDict
s for the analysis result data (please use dataclasses instead).If you contributed an example: