-
Notifications
You must be signed in to change notification settings - Fork 7
[PNE-7018] Add new evaluations API and deprecate PEWs. #997
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I debated whether to change this filename to predictor_evaluations.rst, but left it for now to avoid any broken links coming into it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "3.23.1" | ||
| __version__ = "3.24.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| from functools import lru_cache | ||
| from typing import List, Optional, Union | ||
| from uuid import UUID | ||
|
|
||
| from citrine.informatics.predictor_evaluation_result import PredictorEvaluationResult | ||
| from citrine.informatics.predictor_evaluator import PredictorEvaluator | ||
| from citrine.resources.status_detail import StatusDetail | ||
| from citrine._rest.engine_resource import EngineResourceWithoutStatus | ||
| from citrine._rest.resource import PredictorRef | ||
| from citrine._serialization import properties | ||
| from citrine._serialization.serializable import Serializable | ||
| from citrine._utils.functions import format_escaped_url | ||
|
|
||
|
|
||
| class PredictorEvaluatorsResponse(Serializable['EvaluatorsPayload']): | ||
| """Container object for a default predictor evaluator response.""" | ||
|
|
||
| evaluators = properties.List(properties.Object(PredictorEvaluator), "evaluators") | ||
|
|
||
| def __init__(self, evaluators: List[PredictorEvaluator]): | ||
| self.evaluators = evaluators | ||
|
|
||
|
|
||
| class PredictorEvaluationRequest(Serializable['EvaluatorsPayload']): | ||
| """Container object for a predictor evaluation request.""" | ||
|
|
||
| predictor = properties.Object(PredictorRef, "predictor") | ||
| evaluators = properties.List(properties.Object(PredictorEvaluator), "evaluators") | ||
|
|
||
| def __init__(self, | ||
| *, | ||
| evaluators: List[PredictorEvaluator], | ||
| predictor_id: Union[UUID, str], | ||
| predictor_version: Optional[Union[int, str]] = None): | ||
| self.evaluators = evaluators | ||
| self.predictor = PredictorRef(predictor_id, predictor_version) | ||
|
|
||
|
|
||
| class PredictorEvaluation(EngineResourceWithoutStatus['PredictorEvaluation']): | ||
| """The evaluation of a predictor's performance.""" | ||
|
|
||
| uid: UUID = properties.UUID('id', serializable=False) | ||
| """:UUID: Unique identifier of the evaluation""" | ||
| evaluators = properties.List(properties.Object(PredictorEvaluator), "data.evaluators", | ||
| serializable=False) | ||
| """:List{PredictorEvaluator]:the predictor evaluators that were executed. These are used | ||
| when calling the ``results()`` method.""" | ||
| predictor_id = properties.UUID('metadata.predictor_id', serializable=False) | ||
| """:UUID:""" | ||
| predictor_version = properties.Integer('metadata.predictor_version', serializable=False) | ||
| status = properties.String('metadata.status.major', serializable=False) | ||
| """:str: short description of the evaluation's status""" | ||
| status_description = properties.String('metadata.status.minor', serializable=False) | ||
| """:str: more detailed description of the evaluation's status""" | ||
| status_detail = properties.List(properties.Object(StatusDetail), 'metadata.status.detail', | ||
| default=[], serializable=False) | ||
| """:List[StatusDetail]: a list of structured status info, containing the message and level""" | ||
|
|
||
| def _path(self): | ||
| return format_escaped_url( | ||
| '/projects/{project_id}/predictor-evaluations/{evaluation_id}', | ||
| project_id=str(self.project_id), | ||
| evaluation_id=str(self.uid) | ||
| ) | ||
|
|
||
| @lru_cache() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this exceptionally slow or called a large number of times? Seems like maybe an unnecessary optimization.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair question, but I'm not sure. This is just copied from the |
||
| def results(self, evaluator_name: str) -> PredictorEvaluationResult: | ||
| """ | ||
| Get a specific evaluation result by the name of the evaluator that produced it. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| evaluator_name: str | ||
| Name of the evaluator for which to get the results | ||
|
|
||
| Returns | ||
| ------- | ||
| PredictorEvaluationResult | ||
| The evaluation result from the evaluator with the given name | ||
|
|
||
| """ | ||
| params = {"evaluator_name": evaluator_name} | ||
| resource = self._session.get_resource(self._path() + "/results", params=params) | ||
| return PredictorEvaluationResult.build(resource) | ||
|
|
||
| @property | ||
| def evaluator_names(self): | ||
| """Names of the predictor evaluators. Used when calling the ``results()`` method.""" | ||
| return list(iter(self)) | ||
|
|
||
| def __getitem__(self, item): | ||
| if isinstance(item, str): | ||
| return self.results(item) | ||
| else: | ||
| raise TypeError("Results are accessed by string names") | ||
|
|
||
| def __iter__(self): | ||
| return iter(e.name for e in self.evaluators) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
|
|
||
|
|
||
| class PredictorEvaluationExecution(Resource['PredictorEvaluationExecution'], Execution): | ||
| """The execution of a PredictorEvaluationWorkflow. | ||
| """[DEPRECATED] The execution of a PredictorEvaluationWorkflow. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the |
||
|
|
||
| Possible statuses are INPROGRESS, SUCCEEDED, and FAILED. | ||
| Predictor evaluation executions also have a ``status_description`` field with more information. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
|
|
||
| class PredictorEvaluationWorkflow(Resource['PredictorEvaluationWorkflow'], | ||
| Workflow, AIResourceMetadata): | ||
| """A workflow that evaluations a predictor. | ||
| """[DEPRECATED] A workflow that evaluates a predictor. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,15 +129,15 @@ def _list_base(self, *, per_page: int = 100, archived: Optional[bool] = None): | |
| per_page=per_page) | ||
|
|
||
| def list_all(self, *, per_page: int = 20) -> Iterable[DesignSpace]: | ||
| """List the most recent version of all design spaces.""" | ||
| """List all design spaces.""" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just fixing some unclear wording that slipped by for a while. |
||
| return self._list_base(per_page=per_page) | ||
|
|
||
| def list(self, *, per_page: int = 20) -> Iterable[DesignSpace]: | ||
| """List the most recent version of all non-archived design spaces.""" | ||
| """List non-archived design spaces.""" | ||
| return self._list_base(per_page=per_page, archived=False) | ||
|
|
||
| def list_archived(self, *, per_page: int = 20) -> Iterable[DesignSpace]: | ||
| """List the most recent version of all archived predictors.""" | ||
| """List archived design spaces.""" | ||
| return self._list_base(per_page=per_page, archived=True) | ||
|
|
||
| def create_default(self, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to re-think this page at a later date - introducing the idea of
workflowsseems odd given that there really is only 1. But, given this is the deprecation PR and we still have PEW collateral in the "workflows" directory under informatics, I think we should take a look at re-factoring this part of the documentation for v4.0