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

146 function data steady label #149

Merged
merged 8 commits into from
Apr 10, 2024
Merged

Conversation

acse-ej321
Copy link
Collaborator

Address issues in #146 by:

  • building labels list in both data_by_label and data_by_subfunction from self.time_partition.field_types as was already done in data_by_field.
  • added test functionality to include steady case in addition to unsteady case.

@acse-ej321 acse-ej321 requested a review from jwallwork23 March 27, 2024 13:39
@acse-ej321 acse-ej321 self-assigned this Mar 27, 2024
Copy link
Member

@jwallwork23 jwallwork23 left a comment

Choose a reason for hiding this comment

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

Thanks for reporting this issue and providing a fix. However, I have a couple of requests.

Apologies for pushing to your branch - I realised an oversight in my own implementation so thought I'd fix it here. Hope you don't mind.

test/test_function_data.py Outdated Show resolved Hide resolved
Comment on lines 84 to 93
_labels = []
for field_type in tp.field_types:
_labels.extend(self._label_dict[field_type])

return AttrDict(
{
label: AttrDict(
{field: self._data_by_field[field][label] for field in tp.fields}
)
for label in self.labels
for label in _labels
Copy link
Member

Choose a reason for hiding this comment

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

Instead of duplicating this, why not just implement it once in the __init__ method of the base class? The labels attribute that is computed there is never used with these changes. Why not just overwrite that definition with this new one? It works for me when I do that locally.

Copy link
Member

Choose a reason for hiding this comment

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

Also, a list comprehension (rather than extend) would be more in line with the style used in Goalie.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in commit 6679c33

I originally used extend to avoid the doubly nested list and having to add a [0] at the end of the list comprehension which seems a bit less readable. Hope it works now. The individual functions should be back to how they were before commit c56c4af.

@jwallwork23 jwallwork23 added the bug Something isn't working label Mar 28, 2024
@jwallwork23 jwallwork23 added this to the Version 1 milestone Mar 28, 2024
@jwallwork23 jwallwork23 linked an issue Mar 28, 2024 that may be closed by this pull request
@acse-ej321 acse-ej321 requested a review from jwallwork23 March 28, 2024 12:22
Comment on lines 32 to 39
self.labels = (
[
[label for label in self._label_dict[field]]
for field in self.time_partition.field_types
][0]
if self.time_partition.fields
else []
)
Copy link
Member

Choose a reason for hiding this comment

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

I'm really confused by this. Is it not sufficient to just do the following?

self.labels = self._label_dict["steady" if time_partition.steady else "unsteady"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jwallwork23 - I had missed the steady attribute. Yes, that does significantly simplify things. See commit #32119bf

Copy link
Member

Choose a reason for hiding this comment

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

Oh actually it's not quite so simple because (as @ddundo has pointed out previously) some fields might be "steady" and some might be "unsteady". So I don't think we can just set self.labels for all cases in this way. Instead, it should be determined per-field.

Apologies! So some refactoring will be required. Does what I said here sound right to you both?

Copy link
Member

@ddundo ddundo Apr 3, 2024

Choose a reason for hiding this comment

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

Ah yes, I should have also pointed that out in #116... sorry! That looks like it complicates _data_by_label in this mixed case, where we have both steady-unsteady fields, since unsteady fields will have labels that steady ones don't. Although, in this mixed case the "steady" fields aren't actually steady, so the notion of "forward_old" and "adjoint_next" still makes sense for them, right?

The reason why we introduced field types was to not get the no dependency error in MeshSeq._dependency. So I don't actually see a reason why we would care about field type anywhere else... so maybe we can get rid of this distinction in the solutions dictionaries here, and just extract "forward_old" and "adjoint_next" in a sensible way for these "steady" fields (i.e. not from dependencies).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ddundo - I think it would help to have a simple mixed case test. Do you have one already implemented elsewhere in the code base I can use as a go-by?

Copy link
Collaborator Author

@acse-ej321 acse-ej321 Apr 4, 2024

Choose a reason for hiding this comment

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

It looks like in time_partition.py the field_types variable is set for all fields as unsteady as long as there is more than one subinterval or more than one timestep. If it is just one interval with one timestep, all fields are set to steady. That is, it looks like the field_types is automatically set to the same variable for all fields dependent on the time_partition.

As @ddundo pointed out, in a mixed case, there would be more than one timestep by default so even the steady field in a mixed case would need to be handled over all the timesteps. The additional unsteady labels forward_old and/or adjoint_next would still apply to the steady component of the mixed case to handle it over more than one timestep?

@jwallwork23 I am not sure that further refactoring is needed, given the current setup? I would like to first implement a mixed steady, unsteady case to see where the current setup fails.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @acse-ej321, that would indeed be useful! I could probably simplify my ice evolution problem, but maybe someone at the meeting today will be able to propose a better example :)

Copy link
Member

@jwallwork23 jwallwork23 left a comment

Choose a reason for hiding this comment

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

Okay I'm happy for this to be merged, noting that we should keep an eye out for whether an issue crops up when addressing #152.

@acse-ej321 acse-ej321 merged commit c95a3a9 into main Apr 10, 2024
1 check passed
@jwallwork23 jwallwork23 deleted the 146_function_data_steady_label branch April 12, 2024 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get function_data by label for steady state case
3 participants