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

Report orphaned objects #128

Open
MicahGale opened this issue Feb 3, 2023 · 14 comments
Open

Report orphaned objects #128

MicahGale opened this issue Feb 3, 2023 · 14 comments
Labels
feature request An issue that improves the user interface. good first issue Good for newcomers

Comments

@MicahGale
Copy link
Collaborator

Create a tool to quickly see objects such as transforms, materials, surfaces.

In the immediate create a tips and tricks for this hack:

unused = set()
for surface in problem.surfaces:
    if len(surface.cells) == 0:
         unused.add(surface)

Proposed solution in MCNP_Problem:

def find_unused_objects(self):
    """
    Finds all unused objects.

    :returns: A dictionary mapping a class to the set of unused objects
    :rtype: dict
    """

@bascandr

@MicahGale
Copy link
Collaborator Author

In GitLab by @tjlaboss on Feb 3, 2023, 12:48

unused = {s for s in problem.surfaces if not len(s.cells)}

@MicahGale
Copy link
Collaborator Author

To research: if generator yields nothing is that falsey?

@MicahGale
Copy link
Collaborator Author

In GitLab by @tjlaboss on Feb 3, 2023, 12:55

Yes

@MicahGale
Copy link
Collaborator Author

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

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale
Copy link
Collaborator Author

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)

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale
Copy link
Collaborator Author

Back on topic: thoughts on the proposed function signature?

@MicahGale
Copy link
Collaborator Author

In GitLab by @bascandr on Feb 3, 2023, 13:58

Let's take a second to think about what these unused objects could be:

  1. Surfaces. Should be obvious if they aren't used by a cell, but we should check if they are referenced by a tally (fs card).
  2. Universes. If they don't appear on a fill card.
  3. Cells. The only way for these too be orphaned would be to be assigned to an orphaned universe.
  4. Materials. These could be used by a tally or perturbation.
  5. Transforms.

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale
Copy link
Collaborator Author

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.

@MicahGale MicahGale self-assigned this Jan 12, 2024
@MicahGale MicahGale removed their assignment Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request An issue that improves the user interface. good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant