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

Fix bug in loading previously run Batch and ComponentModeler from file when custom medium present #1817

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

tylerflex
Copy link
Collaborator

@tylerflex tylerflex commented Jul 10, 2024

Fixes #1816.

@tylerflex tylerflex requested a review from momchil-flex July 10, 2024 17:09
@tylerflex tylerflex force-pushed the tyler/fix/batch_json branch 2 times, most recently from 028cc98 to f3b0bd7 Compare July 10, 2024 17:19
@tylerflex tylerflex marked this pull request as draft July 10, 2024 17:23
@tylerflex tylerflex force-pushed the tyler/fix/batch_json branch from f3b0bd7 to 0c70f7d Compare July 10, 2024 17:50
@tylerflex tylerflex force-pushed the tyler/fix/batch_json branch from 0c70f7d to dbb17b3 Compare July 10, 2024 17:54
@tylerflex tylerflex marked this pull request as ready for review July 10, 2024 17:56
@tylerflex tylerflex added 2.7 will go into version 2.7.* .2 labels Jul 10, 2024
Copy link
Collaborator

@momchil-flex momchil-flex left a comment

Choose a reason for hiding this comment

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

We can get this in for now if it fixes things but it really looks like it needs a rethink... Two things strike me as not good design:

  1. The existence and difference of both Job._cached_properties["task_id"] and a Job.task_id_cached and the fact that those differ, and the fact that we have to call updated_copy on Job just to update this.
  2. self = self.updated_copy(batch_cached=batch_cached) just looks... bad, no?

@tylerflex
Copy link
Collaborator Author

Yea I'm also not very happy with it. Ultimately, it comes down to (a) our choice of immutability (b) making things like task_id properties.

For example, the Job.task_id doesn't exist until the Job is .upload()-ed. So it makes sense to make it a property. However, this task_id property gets lost when we save Job to file. So if the job has been run, after loading from file it seems like it has not. So either:

  1. We manually save task_id to file, and load it as a special field (this PR)
  2. We make Job and Batch mutable, and set self.task_id = task_id upon upload.
  3. We make a more general way to handle saving and loading cached_property fields to and from file.

Any thoughts? In some sense, we treat Job and Batch as mutable objects, since they have a state (whether they've been updated, run, etc). In fact the task itself has a state too.. so this could make some sense to me.

@tylerflex
Copy link
Collaborator Author

Also, we never upload Job and Batch directly

The existence and difference of both Job._cached_properties["task_id"] and a Job.task_id_cached and the fact that those differ,

They have to differ because one is a property and one is a field.. in pydantic v2, there are computed_fields, which sort of are properties that can be saved to file, this is what we would need. For now we're sort of stuck with this.

and the fact that we have to call updated_copy on Job just to update this.

Yea, because of the immutability, I dont see a good way around this.

self = self.updated_copy(batch_cached=batch_cached) just looks... bad, no?

It sure does, but I dont see any way. Note that because of how I'm using super(SuperClass, new_self), I dont think re-assigning self matters here.

@momchil-flex
Copy link
Collaborator

Generally this seems to be pointing towards potentially making container classes mutable, which may not be a terrible idea? The contained simulations will still be immutable unless I'm really misunderstanding something.

@tylerflex
Copy link
Collaborator Author

tylerflex commented Jul 11, 2024

Yea I think in general it would make some sense to create a distinction between (1) core components tidy3d/components, which can continue to be immutable and (2) web components tidy3d/web, which essentially transform these core components, eg Job(simulation).run() -> SimulationData, which could be mutable?

Although I think maybe this could go into the ominous web API refactor or the 3.0 redesign..

@momchil-flex
Copy link
Collaborator

Yea I think in general it would make some sense to create a distinction between (1) core components tidy3d/components, which can continue to be immutable and (2) web components tidy3d/web, which essentially transform these core components, eg Job(simulation).run() -> SimulationData, which could be mutable?

Sorry, which part here would be mutable? Just Job?

Although I think maybe this could go into the ominous web API refactor or the 3.0 redesign..

This wouldn't really be compatibility breaking in any user-facing way and may not be too big of a change so there may not be a need to wait for that, but I guess depends on priority if we have something working even if ugly.

@tylerflex
Copy link
Collaborator Author

just Job and Batch would be mutable.

guess we wouldn't need to wait, I'm just not sure if we want to open this can of worms just for this bug fix, and should consider waiting for a time when we're doing a more comprehensive overhaul.

@momchil-flex
Copy link
Collaborator

Ok merging this and made an issue to follow up. #1823

@momchil-flex momchil-flex merged commit 3589d91 into develop Jul 11, 2024
16 checks passed
@momchil-flex momchil-flex deleted the tyler/fix/batch_json branch July 11, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.7 will go into version 2.7.* .2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix cached values in web containers
2 participants