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

added first iteration of easy_publish #153

Merged
merged 56 commits into from
Sep 29, 2022
Merged

added first iteration of easy_publish #153

merged 56 commits into from
Sep 29, 2022

Conversation

isaac-darling
Copy link
Contributor

DO-NOT-MERGE is added while additional features are considered and testing is conducted

@isaac-darling isaac-darling linked an issue Jul 25, 2022 that may be closed by this pull request
Copy link
Contributor

@ascourtas ascourtas left a comment

Choose a reason for hiding this comment

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

great job Isaac, I think the easy_publish() method will be a huge step in making model publishing even more accessible to the user! I have several questions about code logic, etc. Also, I think allowing the user to set datacite metadata is important.

"pytorch",
"tensorflow",
"sklearn")
serv_options (dict): the servable_type specific arguments that are necessary for publishing
Copy link
Contributor

Choose a reason for hiding this comment

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

please add more context for the user on what the servable options are -- ideally, link to documentation

except Exception as e:
help_err = HelpMessage(f"Help can be found here:\nhttps://dlhub-sdk.readthedocs.io/en/latest/source/dlhub_sdk.models.servables.html#"
f"{model.__module__}.{model.__name__}.create_model")
raise help_err from e
Copy link
Contributor

Choose a reason for hiding this comment

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

just to clarify, this help_err won't eat the original exception message, correct?

Copy link
Contributor Author

@isaac-darling isaac-darling Jul 29, 2022

Choose a reason for hiding this comment

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

No. specifying from e means the traceback will show the original error and say something like "the following error is a direct result of the previous error" and then show the help message. docs on from Exception here.


# raise an error if the provided servable_type is invalid
model = models.get(servable_type)
if model is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if you wanted to shorten this a bit, you could do if servable_type not in models -- slightly more pythonic imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would, but I also need to store the model variable for later. I suppose lookups are quick, but it's a little more visual clutter. up to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

🤷‍♀️ I like "not in models" but not enough to change this here.


# set the required datacite fields
model_info.set_title(title)
creators = [creators] if isinstance(creators, str) else creators
Copy link
Contributor

Choose a reason for hiding this comment

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

I see, so this is handling the case where the user inputs creators as a string instead of a list? please add a small inline comment saying as much (something like # handle creator as string or list or something similar)

# set the required datacite fields
model_info.set_title(title)
creators = [creators] if isinstance(creators, str) else creators
model_info.set_creators(creators, []) # we do not ask for affiliations
Copy link
Contributor

Choose a reason for hiding this comment

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

we should allow the user to still set affiliations if they'd like to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd be happy to talk about what parameters we want to provide for this function. When Logan and I discussed it, we opted to go for the absolute minimum and leave it to the publisher to edit later. All depends on where we want to draw the complexity line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do at least affiliations as a breakout argument.

dlhub_sdk/models/servables/python.py Show resolved Hide resolved
Args:
f (object): A function pointer
autobatch (bool): Whether to run function on an iterable of entries
function_kwargs (dict): Any default options for this function
"""
return cls.create_model(f.__module__, f.__name__, autobatch, function_kwargs)
return cls.create_model(f=f, autobatch=autobatch, function_kwargs=function_kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

what to do about autobatch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that I understand..

dlhub_sdk/models/servables/python.py Show resolved Hide resolved
def test_submit(dl):
# @mark.skipif(not is_gha, reason='Avoid running this test except on larger-scale tests of the system')
# @mark.skip
def test_submit(dl, mocker):
Copy link
Contributor

Choose a reason for hiding this comment

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

nice job with mocking

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we go-ahead and remove the commented-out lines?

@@ -36,7 +36,7 @@ def _type_name_to_type(name: str) -> Union[type, Tuple[type]]:
try:
return type_table.get(name) or __builtins__[name] # getattr(__builtins__, name) if __builtins__ is a module
except KeyError: # AttributeError if __builtins__ is a module
raise ValueError(f"found an unknown type name in servable metadata: {name}")
raise ValueError(f"found an unknown type name in servable metadata: {name}") from None
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if you raise from None? I am not familiar with this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will raise the ValueError without mentioning that it was the result of a KeyError (the user does not need to know that) docs for exception chaining are here if you're interested.

Copy link
Contributor

Choose a reason for hiding this comment

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

The same behavior will happen without the "from None," (i.e., what we had before), if I understand right

Copy link
Contributor Author

@isaac-darling isaac-darling Aug 9, 2022

Choose a reason for hiding this comment

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

From the docs: "Exception chaining happens automatically when an exception is raised inside an except or finally section. This can be disabled by using from None idiom." Since the ValueError is raised in an except chaining will happen automatically unless it is disabled (if I understand correctly).

Copy link
Contributor

Choose a reason for hiding this comment

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

Shows that I know. Let's keep yours

Copy link
Contributor

@WardLT WardLT left a comment

Choose a reason for hiding this comment

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

I think we're ready after the minor changes here

@@ -336,6 +347,59 @@ def get_result(self, task_id, verbose=False):
result = result[0]
return result

def easy_publish(self, title: str, creators: Union[str, list[str]], short_name: str, servable_type: str, serv_options: dict[str, Any]):
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree! We could still keep the "title" and "creators" as other arguments (that take precedent) so that people don't have to know datacite exists.


# raise an error if the provided servable_type is invalid
model = models.get(servable_type)
if model is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

🤷‍♀️ I like "not in models" but not enough to change this here.

# set the required datacite fields
model_info.set_title(title)
creators = [creators] if isinstance(creators, str) else creators
model_info.set_creators(creators, []) # we do not ask for affiliations
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do at least affiliations as a breakout argument.

def test_submit(dl):
# @mark.skipif(not is_gha, reason='Avoid running this test except on larger-scale tests of the system')
# @mark.skip
def test_submit(dl, mocker):
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we go-ahead and remove the commented-out lines?

@@ -36,7 +36,7 @@ def _type_name_to_type(name: str) -> Union[type, Tuple[type]]:
try:
return type_table.get(name) or __builtins__[name] # getattr(__builtins__, name) if __builtins__ is a module
except KeyError: # AttributeError if __builtins__ is a module
raise ValueError(f"found an unknown type name in servable metadata: {name}")
raise ValueError(f"found an unknown type name in servable metadata: {name}") from None
Copy link
Contributor

Choose a reason for hiding this comment

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

The same behavior will happen without the "from None," (i.e., what we had before), if I understand right

@isaac-darling
Copy link
Contributor Author

The changes you mentioned should be added now (aside from the datacite parameter, which I think gets at the overall ease of use/usefulness issue and warrants further consideration).

@WardLT
Copy link
Contributor

WardLT commented Aug 9, 2022

Thanks! I'm happy then. Leaving off datacite for now is a good idea. We can add other fields in smaller PRs

Maybe another for now though: paper_doi so we can add a paper as an associated identifier

@isaac-darling
Copy link
Contributor Author

I gathered what I could from the docs, please let me know if this is not what you were looking for

Copy link
Contributor

@WardLT WardLT left a comment

Choose a reason for hiding this comment

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

Let's simplify the "paper_doi" even more

dlhub_sdk/client.py Outdated Show resolved Hide resolved
@isaac-darling
Copy link
Contributor Author

The relation is now fixed!

@coveralls
Copy link

coveralls commented Sep 16, 2022

Pull Request Test Coverage Report for Build 3101287839

  • 180 of 190 (94.74%) changed or added relevant lines in 9 files are covered.
  • 32 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.8%) to 89.737%

Changes Missing Coverage Covered Lines Changed/Added Lines %
dlhub_sdk/client.py 24 28 85.71%
dlhub_sdk/utils/tests/test_inspect.py 44 50 88.0%
Files with Coverage Reduction New Missed Lines %
dlhub_sdk/models/servables/init.py 1 93.18%
dlhub_sdk/models/servables/tests/test_tensorflow.py 11 76.0%
dlhub_sdk/models/servables/tensorflow.py 20 65.15%
Totals Coverage Status
Change from base Build 2929398202: 0.8%
Covered Lines: 1810
Relevant Lines: 2017

💛 - Coveralls

@ascourtas
Copy link
Contributor

Looks fantastic, excellent work Isaac! Super pumped for these changes for the user

@ascourtas ascourtas merged commit 1bd1ef6 into dev Sep 29, 2022
@isaac-darling isaac-darling deleted the friendly-publish branch October 4, 2022 14:42
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.

add a more user-friendly option for publishing servables
5 participants