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

Move number of assemblies out of global space #617

Closed
john-science opened this issue Apr 5, 2022 · 4 comments
Closed

Move number of assemblies out of global space #617

john-science opened this issue Apr 5, 2022 · 4 comments
Labels
architecture Issues related to big picture system architecture

Comments

@john-science
Copy link
Member

There have been several bugs recently due to strange race conditions and edge cases to do with the fact that the total number of assemblies in a reactor is stored in a global variable:

# to count the blocks that we create and generate a block number
_assemNum = 0
def incrementAssemNum():
global _assemNum # tracked on a module level
val = _assemNum # return value before incrementing.
_assemNum += 1
return val

It appears all of these bugs have been present in the code for years. And in the past few weeks I have had to work on several of these issues.

Since the rest of the codebase is Object Oriented, I see now reason why this one Reactor value shouldn't be part of the Reactor object. And that is my suggestion for fixing it.

@john-science john-science added the architecture Issues related to big picture system architecture label Apr 5, 2022
@john-science
Copy link
Member Author

john-science commented Apr 13, 2022

Okay, I found what I think is the only reason that we have a global _assemNum:

if assemNum is None:
assemNum = incrementAssemNum()

When we create a new Assembly object, we want to give it a new, unique assembly number that is only one higher than the next largest assembly number in the Reactor.

@john-science
Copy link
Member Author

Perhaps we could just give each assembly that needs a unique ID one from the linux timestamp:

from time import time

assemNum = int(time() * 1e8)

Then each assembly should have a unique number. And when we need create a reactor, we can go through each assembly and re-number them quickly, starting with zero (and preserving the order).

@john-science
Copy link
Member Author

Also, I feel like the biggest troubles come from giving assemblies number when building a Reactor from a Case Settings file.

It seems like, in that scenario, we can just provide sequential assembly numbers while reading through the CS file.

@john-science
Copy link
Member Author

This was closed with: #1383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Issues related to big picture system architecture
Projects
None yet
Development

No branches or pull requests

1 participant