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

Using Type annotations in functions annotated by @is_fairstep raises issues #199

Open
vemonet opened this issue Dec 21, 2022 · 0 comments
Open

Comments

@vemonet
Copy link

vemonet commented Dec 21, 2022

Hi, I am trying to use fairworkflows to describe a simple ML workflow, but I am facing a few issues

For example whenever I try to use a type annotation to annotate the input or return value of a function I get an error

  • Type annotation in function parameters:
@is_fairstep(label='Create and fit classifier', is_script_task=True)
def fit_classifier(hyper_params: Dict[str, float], data, y):
    clf = RandomForestClassifier(
        n_jobs=hyper_params['n_jobs'],
        random_state=hyper_params['random_state'],
    )
    clf.fit(data, y)
    return clf

Will raise something like:

Traceback (most recent call last):
  File "my-model/src/my_model/train.py", line 51, in <module>
    def fit_classifier(hyper_params: Dict[str, float], data, y):
  File "site-packages/fairworkflows/fairstep.py", line 452, in _modify_function
    inputs = _extract_inputs_from_function(func, kwargs)
  File "site-packages/fairworkflows/fairstep.py", line 504, in _extract_inputs_from_function
    computational_type = argspec.annotations[arg].__name__
  File "/opt/conda/lib/python3.9/typing.py", line 711, in __getattr__
    raise AttributeError(attr)
AttributeError: __name__
  • Type annotation for function return:
@is_fairstep(label='Evaluate the trained model', is_script_task=True)
def evaluate() -> Dict[str, float]:
    return {
        'precision': 0.85,
        'recall': 0.80,
        'accuracy': 0.85,
        'roc_auc': 0.90,
        'f1': 0.75,
        'average_precision': 0.85,
    }

will raise:

Traceback (most recent call last):
  File "my-model/src/my_model/train.py", line 61, in <module>
    def evaluate(model) -> Dict[str, float]:
  File "site-packages/fairworkflows/fairstep.py", line 453, in _modify_function
    outputs = _extract_outputs_from_function(func, kwargs)
  File "site-packages/fairworkflows/fairstep.py", line 551, in _extract_outputs_from_function
    computational_type = return_annotation.__name__ if return_annotation is not None else None
  File "/opt/conda/lib/python3.9/typing.py", line 711, in __getattr__
    raise AttributeError(attr)
AttributeError: __name__
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

No branches or pull requests

1 participant