Open MicahGale opened 1 year ago
In GitLab by @tjlaboss on Feb 3, 2023, 12:48
unused = {s for s in problem.surfaces if not len(s.cells)}
To research: if generator yields nothing is that falsey?
In GitLab by @tjlaboss on Feb 3, 2023, 12:55
Yes
Nope in my testing it's truthy:
test = []
def func():
for val in test:
yield val
bool(func())
is True, but next(func())
raises StopIteration
though
In GitLab by @tjlaboss on Feb 3, 2023, 13:01
Whoa, I guess it only works for range
. Which as it turns out, is a class.
Right so thinking about it more it makes complete sense. Iterators in python are super basic. They only need to implement __next__
and raise StopIteration
when there is nothing else. There is no standard way to peek ahead and see if there is a value without calling next and crossing your fingers that an exception isn't raised. So all the __bool__
can really do is see if it's a valid function and hasn't seen stopIteration... yet.
So this raises a new longer but funner way to do things:
unused = set()
for surface in problem:
try:
next(surface.cells)
except StopIteration:
unused.add(surface)
Upon further inspection I don't know if a Generator is every falsy with codespace from above test I did:
>>> handle = func()
>>> bool(handle)
True
>>> next(handle)
.... STopIteration
>>> bool(handle)
True.
Back on topic: thoughts on the proposed function signature?
In GitLab by @bascandr on Feb 3, 2023, 13:58
Let's take a second to think about what these unused objects could be:
I'm nervous about universes though, because it would meaning shifting a lot of things out into a new universe (0) that wasn't expecting it.
Very good point about materials.
Also transforms can be used in trcl
and fill
and on surfaces. Any other uses?
I'm thinking only support objects once MCNPy can parse all dependent use cases.
In GitLab by @bascandr on Feb 3, 2023, 16:28
The universes may need to just start out as an identify only type of thing. I still want a tool for figuring out what may be safe to delete, but the process of modifying them is more complex.
The surface use of transforms is one of the things that really slowed me down this week. Any tool that can recognize (and replace) these would be helpful.
So first, I think this function should never just delete them, just ID them. How would you replace them though? Kind of by definition they shouldn't need to be replaced.
In GitLab by @bascandr on Feb 6, 2023, 13:05
In the case of some of these older ATR models, I would consider either renumbering them to reclaim the universe numbers or deleting them and reclaiming the cell/surface numbers that they contain.
Create a tool to quickly see objects such as transforms, materials, surfaces.
In the immediate create a tips and tricks for this hack:
Proposed solution in MCNP_Problem:
@bascandr