-
Notifications
You must be signed in to change notification settings - Fork 7
[PNE-6647] Tag default DS with settings object. #992
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "3.20.0" | ||
| __version__ = "3.21.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| from typing import Optional, Union | ||
| from uuid import UUID | ||
|
|
||
| from gemd.enumeration.base_enumeration import BaseEnumeration | ||
|
|
||
| from citrine._rest.resource import Resource | ||
| from citrine._serialization import properties | ||
|
|
||
|
|
||
| __all__ = ["DefaultDesignSpaceMode", "DesignSpaceSettings"] | ||
|
|
||
|
|
||
| class DefaultDesignSpaceMode(BaseEnumeration): | ||
| """The type of default design space to create. | ||
|
|
||
| * ATTRIBUTE results in a product design space containing dimensions required by the predictor | ||
| * HIERARCHICAL results in a hierarchical design space resembling the shape of training data | ||
| """ | ||
|
|
||
| ATTRIBUTE = 'ATTRIBUTE' | ||
| HIERARCHICAL = 'HIERARCHICAL' | ||
|
|
||
|
|
||
| class DesignSpaceSettings(Resource["DesignSpaceSettings"]): | ||
| """The configuration used to produce a default design space.""" | ||
|
|
||
| predictor_id = properties.UUID("predictor_id") | ||
| predictor_version = properties.Optional( | ||
| properties.Union([properties.Integer(), properties.String()]), | ||
| 'predictor_version' | ||
| ) | ||
| mode = properties.Optional(properties.Enumeration(DefaultDesignSpaceMode), "mode") | ||
| exclude_intermediates = properties.Optional(properties.Boolean(), "exclude_intermediates") | ||
| include_ingredient_fraction_constraints = properties.Optional( | ||
| properties.Boolean(), "include_ingredient_fraction_constraints" | ||
| ) | ||
| include_label_fraction_constraints = properties.Optional( | ||
| properties.Boolean(), "include_label_fraction_constraints" | ||
| ) | ||
| include_label_count_constraints = properties.Optional( | ||
| properties.Boolean(), "include_label_count_constraints" | ||
| ) | ||
| include_parameter_constraints = properties.Optional( | ||
| properties.Boolean(), "include_parameter_constraints" | ||
| ) | ||
|
|
||
| def __init__(self, | ||
| *, | ||
| predictor_id: Union[UUID, str], | ||
| predictor_version: Optional[Union[int, str]] = None, | ||
| mode: Optional[DefaultDesignSpaceMode] = None, | ||
| exclude_intermediates: Optional[bool] = None, | ||
| include_ingredient_fraction_constraints: Optional[bool] = None, | ||
| include_label_fraction_constraints: Optional[bool] = None, | ||
| include_label_count_constraints: Optional[bool] = None, | ||
| include_parameter_constraints: Optional[bool] = None): | ||
| self.predictor_id = predictor_id | ||
| self.predictor_version = predictor_version | ||
| self.mode = mode | ||
| self.exclude_intermediates = exclude_intermediates | ||
| self.include_ingredient_fraction_constraints = include_ingredient_fraction_constraints | ||
| self.include_label_fraction_constraints = include_label_fraction_constraints | ||
| self.include_label_count_constraints = include_label_count_constraints | ||
| self.include_parameter_constraints = include_parameter_constraints |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| from citrine.informatics.dimensions import Dimension | ||
| from citrine.informatics.design_spaces import FormulationDesignSpace | ||
| from citrine.informatics.design_spaces.design_space import DesignSpace | ||
| from citrine.informatics.design_spaces.design_space_settings import DesignSpaceSettings | ||
|
|
||
| __all__ = [ | ||
| "TemplateLink", | ||
|
|
@@ -150,6 +151,8 @@ class HierarchicalDesignSpace(EngineResource["HierarchicalDesignSpace"], DesignS | |
|
|
||
| """ | ||
|
|
||
| _settings = properties.Optional(properties.Object(DesignSpaceSettings), "metadata.settings") | ||
|
|
||
| root = properties.Object(MaterialNodeDefinition, "data.instance.root") | ||
| subspaces = properties.List( | ||
| properties.Object(MaterialNodeDefinition), "data.instance.subspaces" | ||
|
|
@@ -179,6 +182,9 @@ def __init__( | |
| def _post_dump(self, data: dict) -> dict: | ||
| data = super()._post_dump(data) | ||
|
|
||
| if self._settings: | ||
| data["settings"] = self._settings.dump() | ||
|
Comment on lines
+185
to
+186
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. Note that for registration, they're added in a different place than they're read. This is intentional. |
||
|
|
||
| root_node = data["instance"]["root"] | ||
| data["instance"]["root"] = self.__unwrap_node(root_node) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from citrine._rest.engine_resource import EngineResource | ||
| from citrine._serialization import properties | ||
| from citrine.informatics.design_spaces.design_space import DesignSpace | ||
| from citrine.informatics.design_spaces.design_space_settings import DesignSpaceSettings | ||
| from citrine.informatics.dimensions import Dimension | ||
|
|
||
| __all__ = ['ProductDesignSpace'] | ||
|
|
@@ -28,6 +29,8 @@ class ProductDesignSpace(EngineResource['ProductDesignSpace'], DesignSpace): | |
|
|
||
| """ | ||
|
|
||
| _settings = properties.Optional(properties.Object(DesignSpaceSettings), "metadata.settings") | ||
|
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 above. |
||
|
|
||
| subspaces = properties.List(properties.Object(DesignSpace), 'data.instance.subspaces', | ||
| default=[]) | ||
| dimensions = properties.Optional( | ||
|
|
@@ -50,6 +53,10 @@ def __init__(self, | |
|
|
||
| def _post_dump(self, data: dict) -> dict: | ||
| data = super()._post_dump(data) | ||
|
|
||
| if self._settings: | ||
| data["settings"] = self._settings.dump() | ||
|
Comment on lines
+57
to
+58
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 above. |
||
|
|
||
| for i, subspace in enumerate(data['instance']['subspaces']): | ||
| if isinstance(subspace, dict): | ||
| # embedded design spaces are not modules, so only serialize their config | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,28 +3,16 @@ | |
| from typing import Iterable, Optional, TypeVar, Union | ||
| from uuid import UUID | ||
|
|
||
| from gemd.enumeration.base_enumeration import BaseEnumeration | ||
|
|
||
| from citrine._utils.functions import format_escaped_url | ||
| from citrine.informatics.design_spaces import DesignSpace, EnumeratedDesignSpace, \ | ||
| HierarchicalDesignSpace | ||
| from citrine.informatics.design_spaces import DefaultDesignSpaceMode, DesignSpace, \ | ||
| DesignSpaceSettings, EnumeratedDesignSpace, HierarchicalDesignSpace | ||
| from citrine._rest.collection import Collection | ||
| from citrine._session import Session | ||
|
|
||
| CreationType = TypeVar('CreationType', bound=DesignSpace) | ||
|
|
||
|
|
||
| class DefaultDesignSpaceMode(BaseEnumeration): | ||
|
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. Although the class definition is moved, since it's still being imported here, it will not break user imports. |
||
| """The type of default design space to create. | ||
|
|
||
| * ATTRIBUTE results in a product design space containing dimensions required by the predictor | ||
| * HIERARCHICAL results in a hierarchical design space resembling the shape of training data | ||
| """ | ||
|
|
||
| ATTRIBUTE = 'ATTRIBUTE' | ||
| HIERARCHICAL = 'HIERARCHICAL' | ||
|
|
||
|
|
||
| class DesignSpaceCollection(Collection[DesignSpace]): | ||
| """Represents the collection of design spaces as well as the resources belonging to it. | ||
|
|
||
|
|
@@ -154,7 +142,7 @@ def list_archived(self, *, per_page: int = 20) -> Iterable[DesignSpace]: | |
|
|
||
| def create_default(self, | ||
| *, | ||
| predictor_id: UUID, | ||
| predictor_id: Union[UUID, str], | ||
| predictor_version: Optional[Union[int, str]] = None, | ||
| mode: DefaultDesignSpaceMode = DefaultDesignSpaceMode.ATTRIBUTE, | ||
| include_ingredient_fraction_constraints: bool = False, | ||
|
|
@@ -209,19 +197,20 @@ def create_default(self, | |
|
|
||
| """ | ||
| path = f'projects/{self.project_id}/design-spaces/default' | ||
| payload = { | ||
| "predictor_id": str(predictor_id), | ||
| "mode": mode.value, | ||
| "include_ingredient_fraction_constraints": include_ingredient_fraction_constraints, | ||
| "include_label_fraction_constraints": include_label_fraction_constraints, | ||
| "include_label_count_constraints": include_label_count_constraints, | ||
| "include_parameter_constraints": include_parameter_constraints | ||
| } | ||
| if predictor_version: | ||
| payload["predictor_version"] = predictor_version | ||
| settings = DesignSpaceSettings( | ||
| predictor_id=predictor_id, | ||
| predictor_version=predictor_version, | ||
| mode=mode, | ||
| include_ingredient_fraction_constraints=include_ingredient_fraction_constraints, | ||
| include_label_fraction_constraints=include_label_fraction_constraints, | ||
| include_label_count_constraints=include_label_count_constraints, | ||
| include_parameter_constraints=include_parameter_constraints | ||
| ) | ||
|
|
||
| data = self.session.post_resource(path, json=payload, version=self._api_version) | ||
| return self.build(DesignSpace.wrap_instance(data["instance"])) | ||
| data = self.session.post_resource(path, json=settings.dump(), version=self._api_version) | ||
| ds = self.build(DesignSpace.wrap_instance(data["instance"])) | ||
| ds._settings = settings | ||
| return ds | ||
|
|
||
| def convert_to_hierarchical( | ||
| 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.
These settings are just metadata intended to be carried to DS registration, not for users to tinker with. The only effect messing with them will have is screwing up filtering in the UI.