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

Import tracking #66

Closed
wants to merge 15 commits into from
Closed

Import tracking #66

wants to merge 15 commits into from

Conversation

jkanem
Copy link
Contributor

@jkanem jkanem commented Jan 31, 2022

The serialization of the workflow, which results in dispatch_source.py, now includes imports from files external to the Covalent code-base.

  • I have added the tests to cover my changes.
  • I have updated the documentation, VERSION, and CHANGELOG accordingly.
  • I have read the CONTRIBUTING document.

statements that were used in end-user scripts.

Helper functions _get_cova_imports, _get_imports_from_source,
_scan_source_files, and parse_source_for_imports were added
to _shared_files/utils.py to help get external imports.

_write_dispatch_to_python_file now inccludes external import
statements that were used in end-user scripts.
A helper function, _remove_import_dupes, was written to
remove duplicate entries from the result of _write_dispatch_to_python_file

Added function get_imports to executors/base.py which is
just a call to imports_from_sources in utils.py.
(dispatch_source.py) created in _write_dispatch_to_python_file.
@CLAassistant
Copy link

CLAassistant commented Jan 31, 2022

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Feb 1, 2022

Codecov Report

Merging #66 (5e0a755) into develop (fb7f432) will increase coverage by 0.95%.
The diff coverage is 86.36%.

❗ Current head 5e0a755 differs from pull request most recent head 1f9396a. Consider uploading reports for the commit 1f9396a to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #66      +/-   ##
===========================================
+ Coverage    71.50%   72.46%   +0.95%     
===========================================
  Files           27       27              
  Lines         1509     1565      +56     
===========================================
+ Hits          1079     1134      +55     
- Misses         430      431       +1     
Impacted Files Coverage Δ
covalent/_shared_files/defaults.py 100.00% <ø> (ø)
covalent/executor/base.py 47.93% <60.00%> (+8.61%) ⬆️
covalent/_results_manager/result.py 90.13% <64.28%> (-3.77%) ⬇️
covalent/_shared_files/utils.py 85.50% <93.93%> (+6.50%) ⬆️
covalent/_shared_files/config.py 87.03% <0.00%> (-6.72%) ⬇️
covalent/_workflow/electron.py 77.51% <0.00%> (ø)
covalent_dispatcher/_cli/service.py 37.64% <0.00%> (+0.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb7f432...1f9396a. Read the comment docs.

Copy link
Member

@wjcunningham7 wjcunningham7 left a comment

Choose a reason for hiding this comment

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

I'm getting a problem in a very simple example, written in the Python console, which is not inspectable:

import covalent as ct
from covalent._shared_files.utils import get_serialized_function_str
@ct.electron
def test_func(input1: str, input2: int) -> str:
    return f"{input1} {input2}"
funcstr = get_serialized_function_str(test_func)
print(funcstr)

This says the source is not inspectable.

covalent/_results_manager/result.py Outdated Show resolved Hide resolved
@wjcunningham7
Copy link
Member

CLA assistant check Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

Jalani Kanem seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jkanem make sure all your commits use the email associated with your GitHub account. You can do this with git commit --amend --author="My Name <my@email.com>" followed by a force push to your branch.

@jkanem
Copy link
Contributor Author

jkanem commented Feb 1, 2022

I'm getting a problem in a very simple example, written in the Python console, which is not inspectable:

import covalent as ct
from covalent._shared_files.utils import get_serialized_function_str
@ct.electron
def test_func(input1: str, input2: int) -> str:
    return f"{input1} {input2}"
funcstr = get_serialized_function_str(test_func)
print(funcstr)

This says the source is not inspectable.

The main work-horse of this functionality is the inspect module. Which works with files. Trying to use it in a console or Jupyter results in OSError: could not get source code.

Copy link
Member

@kessler-frost kessler-frost left a comment

Choose a reason for hiding this comment

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

For the following workflow ran on a jupyter notebook,

import covalent as ct

@ct.electron
def sample_task(x):
    """Sample task."""

    return x ** 2

@ct.lattice
def sample_workflow(a, b):
    """Sample workflow."""

    c = sample_task(a)
    d = sample_task(b)
    return c, d

Sadly the dispatch_source file that I'm getting contains a huge list of imports. Maybe there is an already open issue for that or maybe we want to solve it in this one, I'm not sure.

covalent/_shared_files/utils.py Outdated Show resolved Hide resolved
covalent/_shared_files/utils.py Outdated Show resolved Hide resolved
covalent/_shared_files/utils.py Outdated Show resolved Hide resolved
covalent/executor/base.py Outdated Show resolved Hide resolved
@jkanem
Copy link
Contributor Author

jkanem commented Feb 2, 2022

For the following workflow ran on a jupyter notebook,

import covalent as ct

@ct.electron
def sample_task(x):
    """Sample task."""

    return x ** 2

@ct.lattice
def sample_workflow(a, b):
    """Sample workflow."""

    c = sample_task(a)
    d = sample_task(b)
    return c, d

Sadly the dispatch_source file that I'm getting contains a huge list of imports. Maybe there is an already open issue for that or maybe we want to solve it in this one, I'm not sure.

This is a Jupyter issue; Jupyter is external to the covalent code-base, and is seen as part of the end-user scripts. Possibly, making this work with Jupyter should be a separate issue.

@kessler-frost
Copy link
Member

I agree. Just curious, were you able to reproduce this too?

kessler-frost
kessler-frost previously approved these changes Feb 2, 2022
@kessler-frost
Copy link
Member

@jkanem Approved! Looks great, I'll merge this to develop once the tests pass and its synced with develop.

@kessler-frost kessler-frost dismissed their stale review February 2, 2022 17:51

We'll need to fix the slowdown caused by get_serialized_str before this gets merged as it will make things worse.

now determined by a configuration parameter.

Added some if/then clauses in the import scanning in order to avoid errors.
… that

determines whether imports are scanned in get_serialized_function_str.
@jkanem
Copy link
Contributor Author

jkanem commented Feb 4, 2022

I think this is ready for another look. The scanning for imports is now behind a configuration parameter in the sdk section:

[sdk]
full_dispatch_source = "false"

I'm open to a different name or section.
As mentioned, this will cause a regression in that, by default, covalent-related decorators will not be commented out in dispatch_source.py.

@jkanem
Copy link
Contributor Author

jkanem commented Feb 5, 2022

This shouldn't be merged until #92 is.

@jkanem jkanem linked an issue Feb 5, 2022 that may be closed by this pull request
@kessler-frost
Copy link
Member

@jkanem Do you think this PR is also blocked by #80 ?

@jkanem
Copy link
Contributor Author

jkanem commented Feb 9, 2022

@jkanem Do you think this PR is also blocked by #80 ?

No, I think this is a (non-ideal) solution to #80. This gets rid of the unreasonable time that it takes to get function strings, but it also gets rid of the import statements in dispatch_source.py.

@wjcunningham7 wjcunningham7 added covalent-dispatcher Related to the dispatcher module feature New feature addition labels Feb 14, 2022
@jkanem
Copy link
Contributor Author

jkanem commented Feb 17, 2022

This PR is now deprecated by #123

@jkanem jkanem closed this Feb 17, 2022
@FyzHsn FyzHsn deleted the import_tracking branch February 14, 2023 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
covalent-dispatcher Related to the dispatcher module feature New feature addition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing configuration parameters raise error
4 participants