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

Clear fields and meshes after indicate error calculated per segment #224

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

acse-ej321
Copy link
Collaborator

Closes #220

  • Modifies indicate_errors to remove extra fields for the base and enriched solutions fields after each subinterval iteration.
  • Likewise deletes the used enriched_mesh_seq mesh after each interaction and resets class variables accordingly.
  • Modified get_enriched_mesh_seq to pass a deepcopy of TimePartition to the enriched mesh sequence constructor to allow for deleting a mesh subinterval and correctly reindexing.

@acse-ej321 acse-ej321 added the optimisation An opportunity to optimise performance label Oct 24, 2024
@acse-ej321 acse-ej321 self-assigned this Oct 24, 2024
@acse-ej321 acse-ej321 changed the title #220 clear fields and meshes after indicate error calculated per segment Clear fields and meshes after indicate error calculated per segment Oct 24, 2024
@acse-ej321
Copy link
Collaborator Author

All the tests are failing for the tfsc cache issue @ddundo fixed in #221, so this would be dependent on that PR?

@ddundo
Copy link
Member

ddundo commented Oct 24, 2024

Thanks for this @acse-ej321! And yeah, sorry... I should have done that separately. Let me open a PR now to fix those and then you can merge it into this branch :)

Comment on lines 243 to 244
enriched_mesh_seq.time_partition.num_subintervals -= 1
enriched_mesh_seq.time_partition.timesteps.pop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to add a method to TimePartition to properly drop the last subinterval and use that here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see commit 8e78325

Copy link
Member

@ddundo ddundo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it since there are still some failing tests, but left some initial comments :)

goalie/go_mesh_seq.py Outdated Show resolved Hide resolved
Comment on lines 236 to 237
self.solutions[f][FWD_OLD].pop()
self.solutions[f][ADJ_NEXT].pop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a situation in which we would not want to destroy these? If so, maybe add a kwarg to not destroy them?

And if we do destroy them, I think you should modify the labels in self.solutions at the end of GoalOrientedMeshSeq.indicate_errors, so that we don't run into errors trying to access data corresponding to those labels.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dundo - At the moment, after indicate errors runs through all subintervals, self.solutions still has a key for all default labels just with empty lists as associated values. Before destroying the label keys in self.solutions, can you think of a case where they might be reused after running indicate errors?

Copy link
Member

@ddundo ddundo Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of something like that, no - in the Hessian adaptation either. But I might be missing something, so I asked that question in the issue #220 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dundo - I've now modified labels and solutions dictionary to destroy the forward_old and adjoint_next categories in 4c0bc

enriched_mesh_seq.solutions[f][ADJ_NEXT].pop()

# delete extra mesh to reduce the memory footprint
enriched_mesh_seq.meshes.pop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to remove function spaces in enriched_mesh_seq._fs in order to fully get rid of the mesh. Maybe somewhere else too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see commit 714f9ef - added call to update_function_spaces which uses the existing MeshSeq method to rebuild enriched_mesh_seq._fs based on the updated subintervals.

Comment on lines +295 to +306
def drop_last_subinterval(self):
"""
Drop the last subinterval and reset lists and counters appropriately.
"""
self.end_time = self.subintervals[-1][0]
self.interval = (self.start_time, self.end_time)
self.num_subintervals -= 1
self.timesteps.pop(-1)
self.subintervals.pop(-1)
self.num_timesteps_per_subinterval.pop(-1)
self.num_timesteps_per_export.pop(-1)
self.num_exports_per_subinterval.pop(-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to modify these arguments that we pass to __init__ and then reinitialise it with self.__init__(*modified_args)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And sorry, why do we actually need to modify the time partition? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ dundo - _function_spaces_consistent checks whether there is a time partition for each subinterval. The modification to time_partition was to comply with that requirement.

# delete current subinterval enriched mesh to reduce the memory footprint
enriched_mesh_seq.meshes.pop(-1)
enriched_mesh_seq.time_partition.drop_last_subinterval()
enriched_mesh_seq._update_function_spaces()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure this would work for p-enrichment (see the last lines of get_enriched_mesh_seq above).

But I think it's also unnecessary extra effort to rebuild all i-1 function spaces since we just want to get rid of the last one :)

Comment on lines +295 to +306
def drop_last_subinterval(self):
"""
Drop the last subinterval and reset lists and counters appropriately.
"""
self.end_time = self.subintervals[-1][0]
self.interval = (self.start_time, self.end_time)
self.num_subintervals -= 1
self.timesteps.pop(-1)
self.subintervals.pop(-1)
self.num_timesteps_per_subinterval.pop(-1)
self.num_timesteps_per_export.pop(-1)
self.num_exports_per_subinterval.pop(-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding a new method please implement unit tests.

# clear empty labels
for f in self.fields:
if self.steady:
self.solutions.labels = "forward"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be inside a tuple?

@ddundo
Copy link
Member

ddundo commented Oct 26, 2024

@acse-ej321 if you want, we can keep this PR simpler and just delete the fields. Then we can deal with labels in a separate PR together with #226?

@ddundo
Copy link
Member

ddundo commented Nov 1, 2024

As we discussed in the meeting, I guess that doing some garbage collection might help after we remove these fields and meshes by using the in-built gc.collect() (as I did in mesh-adaptation/animate#112) and/or firedrake.petsc.garbage_cleanup(comm=COMM_WORLD).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimisation An opportunity to optimise performance
Projects
Development

Successfully merging this pull request may close these issues.

Clear unnecessary fields after error indicators are computed
3 participants