Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@santisoler
Copy link
Member

Summary

Import objects from simpeg.electromagnetics.static.utils in simpeg.electromagnetics.static.resistivity.utils and simpeg.electromagnetics.static.induced_polarization.utils to make them more discoverable. Add tests that check if those imports are available.

PR Checklist

  • If this is a work in progress PR, set as a Draft PR
  • Linted my code according to the style guides.
  • Added tests to verify changes to the code.
  • Added necessary documentation to any new functions/classes following the
    expect style.
  • Marked as ready for review (if this is was a draft PR), and converted
    to a Pull Request
  • Tagged @simpeg/simpeg-developers when ready for review.

Reference issue

What does this implement/fix?

Fixes #1440

Additional information

Import objects from `simpeg.electromagnetics.static.utils` in
`simpeg.electromagnetics.static.resistivity.utils` and
`simpeg.electromagnetics.static.induced_polarization.utils` to make them
more discoverable. Add tests that check if those imports are available.
@jcapriot
Copy link
Member

I understand the want to make them more discoverable, but I feel like there should be only be one place to import them from. You could add a link to those functions in the induced_polarization documentation pages instead?

@jcapriot
Copy link
Member

jcapriot commented Apr 29, 2024

Should it just be in simpeg.electromagnetics.static.utils?

@codecov
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.20%. Comparing base (f04ba47) to head (b41e433).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1442   +/-   ##
=======================================
  Coverage   86.19%   86.20%           
=======================================
  Files         432      434    +2     
  Lines       56119    56131   +12     
  Branches     5209     5209           
=======================================
+ Hits        48373    48385   +12     
  Misses       6350     6350           
  Partials     1396     1396           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@santisoler
Copy link
Member Author

I agree that having utils everywhere can be annoying, and having a single place for them would be much better. I was trying to tackle #1440 based on @lheagy's comments. But I'm totally open to a better solution.

@lheagy having all the utils in simpeg.electromagnetics.static.utils sounds like a good alternative?

@lheagy
Copy link
Member

lheagy commented May 22, 2024

Thanks @santisoler and @jcapriot! And sorry for my slow reply here.

Having the utils be consolidated under simpeg.electromagnetics.static.utils sounds good to me. But as a user, I would still like to be able to access those under the relevant physics, e.g.

from simpeg.electromagnetics.static import resistivity as dc
dc.utils  # should contain all utils under simpeg.electromagnetics.static.utils

That way, once you import any of they physics, they come "fully loaded" as a user, it is subtle that you need to import utils from somewhere else

@jcapriot
Copy link
Member

I don’t think it’s necessary, and it encourages users to work in isolated modes. SimPEG is about modularity!

Ideally, I’d love for all utility code to exist in a single module: simpeg.utils

@lheagy
Copy link
Member

lheagy commented May 23, 2024

Thanks Joe, I don't necessarily think that having the ability to import the relevant utils from the related physics module goes against modularity. If it can help with the discoverability of useful things without adding maintenance load (all this would be is a file that imports the relevant functions in the resitivity module), then I view that as a positive. Otherwise, we are placing a pretty high load on users expecting them to have a mental map of where pieces live. We want users to build the mental map of the big picture pieces -- how simulations work and how to set up inversions, but for stuff like utils, I think a user should be able to explore what is relevant via tab completion -- e.g. I imported resistivity as dc, now what can I do with it? dc. [tab] and then you find utils and can start to explore.

This touches a bit on a bigger picture question about imports. I would like to see us simplify some of this e.g. having to go 4 layers deep to get to DC resistivity is pretty deep (simpeg.electromagnetics.static.resistivity), I think it would be useful if we could start to make better use of private namespaces to allow us to keep the same modular design, but simplify things for users (I think we should be able to import simpeg.electromagnetics.resistivity). But anyways, that is a bigger conversation that we can parse into a separate issue.

The organization of utils will take a bit of thought. For example, plotting pseudosections is only relevant to DC, IP, and SP, so I think it is appropriate to keep them with the static code.

For now, I still think that we should help users discover relevant utils by having it available with the physics that they import

@jcapriot
Copy link
Member

I guess my biggest issue with it is that it goes against the Zen of Python.
Specifically:
“There should be one-- and preferably only one --obvious way to do it.”

@lheagy
Copy link
Member

lheagy commented Jun 6, 2024

Sorry for my late reply! That is a reasonable point Joe. I am not too hung up on this, importing from static.utils is much better than the previous import path. I think it is still worth us thinking about how utils are discovered, but that doesn't need to hold up this pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENHC: make static utils discoverable under dc.utils, ip.utils

4 participants