-
Notifications
You must be signed in to change notification settings - Fork 44
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
Make scipy
an optional dependency
#2062
Comments
One other thing that comes to mind is we may want to add it to the
That is effectively what this block achieves, albeit in a bit of a dirty way. Lines 41 to 48 in 3f087b5
But yeah MC basically comments that out for the validation API. So the question to me is if scipy can be moved inside this block. It was moved up I think because of that trimesh issue actually, because the other 3 things that you point out should not be needed for validation. Well actually I think we have a validator for custom data that checks that the data the user has provided can be interpolated (e.g. has no repeated coords), so it may be needed for that too. |
Not really sure what the minimum requirements for MC are but autograd depends on scipy (as does xarray as @tylerflex pointed out). That seems pretty tricky to get around? |
yea it does, i wonder if we just need to say that we only validate the |
I would like to share some background about the problem. We use Web Assembly (More specifically, Pyodide) to import Tidy3D so that we can implement some features, like plot source_time, script objects, show grid, plot permittivity and so on. If we can't limit the core dependencies of Tidy3D, the front-end webpage will suffer from crashing because of out-of-memory issues. For now, @majinge7846 accomplished lots of work to remove Scipy for front-end Tidy3D utilization. However, the problem becomes critical when upgrading Tidy3d to v2.7.6. Recently, we want to improve the user experience for frequently used functions (Validate/Estimate). We plan to use the same technical solution to implement it. However, we are facing the same problem. Refer to this. Currently, we use lambda to do validation/estimation and pipeline as backup, which will spend lots of time wasted during the simulation.json file transmission. Instead, if we use web assembly to implement validation/estimation, users can get the results immediately. |
https://github.com/pydata/xarray/blob/9b632fd36edba7c6fcd1eea778ba3d8710c68349/pyproject.toml#L36 scipy is an optional deependency of xarray. And I found that it just used for interpolate(scipy.interpolate.interp1d). webgui can even do a check, if tidy3d wasm error/log validation error, "lack scipy please install first" , this is acceptable, we can use lambda/pipeline as fallback. (Of course, it would be better if numpy or other methods can be used to avoid calling Scipy) I think webgui validation not need designed to handle all simulation cases, just most simulation cases are OK too. lightweight base package may not be needed. |
oh nevermind, scipy is optional in autograd too. i guess that's good news then. what would be the best way to go here? sounds to me like it would make sense to add something like a |
Just catching up on this. Ultimately, this is one of the package refactor aspects we want to implement in 3.0. In the sense that we want to have an This kind of leads to the issue of how to approach this right now (edit to be clear 3.0 is a bit far away still). Unfortunately poetry does not enable us to "minimize" the base package If the pipeline can be a good fallback for all the other non-web-assembly local validation cases then I think this could be a good way to get it to work before 3.0! We'd just have to check the scipy to be sure they are on-the-fly per-function like Tyler mentioned. Happy to do a PR for this if this is the approach we want to go for. |
So my thoughts:
|
Nice, yeah I agree! How urgent is this out of curiosity? If it is very urgent for the web UI (sounds a bit?), probably someone else should do this given my current limited timing constraints. Otherwise, think I've got a few ideas how to implement and properly test this with the right environments as you suggest and happy to focus on cracking on this. Or happy to propose a few implementation approaches too as need be. |
test for web to usage: |
I spoke with MC and they are saying this is becoming a very urgent issue. Can we come up with a plan for it and assign someone? |
So I began a PR that is linked, unfortunately I'm in crunch time on the first thesis submission by the end of the month so I can't really devote any more extra time on top of the backend PRs I was helping with recently. I become more free early December to devote extra time but maybe someone else can finish implementing this? I was also a bit concerned on the timelines that weren't super clear to me. In the PR I've been focused on the testing implementation using Sorry to nominate @yaugenst-flex if you'd be ok with that? |
Thanks @daquinteroflex , let's also consider whether there's a really simple approach that removes scipy but still allows us to create and validate components (unless your branch already plans to implement that?) |
So if I understand things correctly,
So is our refactor really blocking for them? |
I think there's at least one validator that explicitly uses but yea other than that maybe we can just make it work without scipy? we could make that validator skip on an import error for example |
Well it depends on what they are trying to do, if they are trying to validate it should not skip but fall back on something that can validate properly. I think there's a trimesh validator that also requires scipy internally. |
yes, and webGUI do not try to support trimesh validation, because although trimesh itself is a pure python package, but it depeends on networkx / rtree (hard to get wasm version) and scipy (big), It is acceptable to fallback to pipeline when meet these case. |
yes, In the short term remove scipy here is a good and big start for wasm validation.
And gui do not want to lose the ability to check simulation includes stl and custom source/medium with custom dataset . So could we do not skip. |
I tinkered around a bit with this, see #2087. This right now just fails if there is a medium on which to interpolate. However, if we need to validate |
can we just change the validator in question to not |
I think it's intended to just catch an edge cases that pops up from time to time on the backend, but maybe we can target that edge case without doing the interp directly. |
Yeah we could loosen the validator. The original issue was that there were arrays provided which had repeated coords along some dimensions. We could revert to testing that only (we made it more general to potentially capture other errors). However like I mentioned I'm pretty sure there was at least one other validator that required scipy internally. @yaugenst-flex did you try loading e.g. the tests |
@momchil-flex ok yeah i tested with I'm also not super sure what
|
Motivation: allow a more lightweight base package for validation
Not sure if it's possible:
SimulationData.to_mat
) so lazy import should be fine there.Either way, we probably want regular
pip install tidy3d
users to have scipy andinterp()
support. So not sure if to accomplish this goal of having a "lightweight" tidy3d package if we just need to create a more custom installation script to MC rather than usingpyproject.toml
?Thoughts @daquintero @yaugenst @momchil-flex ?
The text was updated successfully, but these errors were encountered: