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

lazy import via mintpy.cli for more responsive CLI #828

Merged
merged 64 commits into from
Sep 21, 2022

Conversation

avalentino
Copy link
Member

@avalentino avalentino commented Aug 13, 2022

Description of proposed changes

The CLI stuff is move to dedicated modules in the mintpy.cli sub-package.
In this way it is possible to define the single-entry point argument parser without importing all the processing modules.
Processing modules are imported only when necessary depending on the selected sub-command.

See also #823 (comment).

Reminders

  • Pass Codacy code review (green)
  • Pass Circle CI test (green)
  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • If modifying functionality, describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

@avalentino avalentino force-pushed the feature/import-time branch 4 times, most recently from 1213221 to b664bf3 Compare August 13, 2022 15:43
@yunjunz yunjunz requested review from taliboliver and jhkennedy and removed request for taliboliver August 14, 2022 17:54
@yunjunz
Copy link
Member

yunjunz commented Aug 16, 2022

Thank you @avalentino for the useful and large PR! A quick test shows that the mintpy response time is significantly reduced.

[Updated] I am currently occupied with the preparation of the UNAVCO ISCE+ short course and NISAR workshop, will look at this PR more carefully after that (sorry for the delay).

@avalentino avalentino force-pushed the feature/import-time branch 2 times, most recently from 063991f to c667d4b Compare August 20, 2022 08:14
@yunjunz yunjunz changed the title Improve import time to make the CLI more responsive lazy import via mintpy.cli sub-package for more responsive CLI Sep 7, 2022
@yunjunz yunjunz changed the title lazy import via mintpy.cli sub-package for more responsive CLI lazy import via mintpy.cli for more responsive CLI Sep 7, 2022
+ docs/installation.md: update the instruction to install mintpy via path setup

+ adjust to make path setup method working on cmd:
   - add `#!/usr/bin/env python3` to the top of all cli/[a-z]*.py scripts
   - run `chmod +x` to all `cli/[a-z]*.py` scripts
   - run `chmod -x` to all `mintpy/[a-z]*.py` scripts, except for two (add_attribute.py and multi_transect.py).
+ setup:
   - remove gmtsar as it's included in extra
   - remove gps, as both proj and dateutil are not used anymore
   - add notes for geoid and isce
Copy link
Member

@yunjunz yunjunz left a comment

Choose a reason for hiding this comment

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

Thank you @avalentino for the PR and @jhkennedy for the review! I really like the changes here. All the command line helps are now significantly speeded up, which improves the user experience a lot. Cheers!

Update: I will wait for another 12 hours to merge the PR, in case you have any further suggestions, since I modified the PR significantly.

@avalentino
Copy link
Member Author

avalentino commented Sep 21, 2022

@yunjunz there is a small issue.
In mintpy.cli.prep_gamma there is

from mintpy.objects.sensor import SENSOR_NAMES

that triggers the import of numpy and h5py in mintpy.objects.giant.

You chan check it using the following command:

python3 -X importtime -m mintpy -h

My original solution was to have a local copy of the SENSOR_NAMES list, that, I agree, is not nice.
Another option could be to move SENSOR_NAMES to another module that can be imported without triggering the loading of heavy-waight modules like h5py and numpy.
Having lazy imports in mintpy.objects.giant is probably not a good idea.
How do you propose to proceed?

@yunjunz
Copy link
Member

yunjunz commented Sep 21, 2022

Thank you for the importtime command, that's very helpful. The triggering of numpy import is because of the non-empty mintpy.objects.__init__.py file (this should be changed in the next major version), but modifying this now would require quite a lot of changes. How about moving sensor.py from mintpy.objects to mintpy.utils sub-module?

mintpy.utils.__init__.py file is empty, and the related changes (of importing sensor) would be only a few places.

Update: rethinking about this makes me realize that making a copy as you did before was a pretty good solution! Shall we revert back to that?

@avalentino
Copy link
Member Author

avalentino commented Sep 21, 2022

Update: rethinking about this makes me realize that making a copy as you did before was a pretty good solution! Shall we revert back to that?

Probably it is the easiest solution.
If you already plan a refactoring, then it should not be a big issue.

SENSOR_NAMES is now duplicated in mintpy.cli.prep_gamma
@avalentino
Copy link
Member Author

OK, @yunjunz
Commit done.

@yunjunz yunjunz merged commit eec16ba into insarlab:main Sep 21, 2022
@avalentino
Copy link
Member Author

Thanks @yunjunz

@yunjunz
Copy link
Member

yunjunz commented Sep 22, 2022

Thank you @avalentino for the PR!

@avalentino avalentino deleted the feature/import-time branch September 22, 2022 08:51
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Sep 23, 2022
+ workflow/__init__.py: fix the UnboundLocalError of 'mintpy'

+ smallbaselineApp: bring back the individual module import (as proposed in the lazy import PR insarlab#828), to replace the workflow import, for better speed and robustness.
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Sep 23, 2022
+ workflow/__init__.py: fix the UnboundLocalError of 'mintpy'

+ smallbaselineApp: bring back the individual module import (as proposed in the lazy import PR insarlab#828), to replace the workflow import, for better speed and robustness.
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Sep 23, 2022
+ workflow/__init__.py: fix the UnboundLocalError of 'mintpy'

+ smallbaselineApp: bring back the individual module import (as proposed in the lazy import PR insarlab#828), to replace the workflow import, for better speed and robustness.
yunjunz added a commit that referenced this pull request Sep 24, 2022
+ `smallbaselineApp`: bring back the individual module import (as proposed in the lazy import PR #828), to replace the workflow import, for better speed and robustness.

+ `workflow/__init__.py`: fix the UnboundLocalError of 'mintpy'

+ `info`: support `--compact` output to `--date / --num` options

+ general Codacy style suggestions
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.

3 participants