Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions docs/source/workflows/design_spaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -419,25 +419,3 @@ We will require that formulations contain 2 ingredients, that no more than 1 sol
)

registered_design_space = project.design_spaces.register(design_space)

Sampling from Design Spaces
---------------------------

To sample candidates from a registered design space, follow the example below:

.. code:: python

from citrine import Citrine
from citrine.jobs.waiting import wait_while_executing
from citrine.informatics.design_spaces.sample_design_space import SampleDesignSpaceInput

sample_input = SampleDesignSpaceInput(n_candidates=50)
sample_design_space_collection = design_space.sample_design_space_executions
sample_design_space_execution = sample_design_space_collection.trigger(sample_input)

execution = wait_while_executing(
collection=sample_design_space_collection, execution=sample_design_space_execution
)

sampled_candidates = [candidate.material for candidate in execution.results()]
root_materials = [candidate.root for candidate in sampled_candidates]
60 changes: 0 additions & 60 deletions docs/source/workflows/generative_design.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/source/workflows/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ AI Engine
data_sources
predictor_reports
predictor_evaluations
generative_design
code_examples
2 changes: 1 addition & 1 deletion src/citrine/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.3.2"
__version__ = "5.4.0"
175 changes: 175 additions & 0 deletions src/citrine/_utils/removed_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
"""Stand-ins for the names of features the Citrine Platform has removed.

The platform removed generative design and design space sampling.
Their public names still import, so an existing script reaches a clear error, not an ImportError.
Importing one of these names emits a DeprecationWarning.
Constructing one of the classes, or calling a method on it, raises FeatureRemovedError.
Version 6.0.0 deletes this module and every name it supplies.
"""

from collections.abc import Callable, Iterable
from warnings import warn

from gemd.enumeration.base_enumeration import BaseEnumeration

from citrine.exceptions import FeatureRemovedError

DEPRECATED_IN = "5.4.0"
REMOVED_IN = "6.0.0"

GENERATIVE_DESIGN_REMOVED = "Generative design has been removed from the Citrine Platform."
SAMPLING_REMOVED = "Design space sampling has been removed from the Citrine Platform."


class _RemovedClassMeta(type):
"""Raise FeatureRemovedError when code reads a method the removed class no longer has."""

def __getattr__(cls, name: str):
if name.startswith("__"):
raise AttributeError(name)
raise FeatureRemovedError(cls._removal_message)


class _RemovedClass(metaclass=_RemovedClassMeta):
"""Base of a class whose platform feature was removed."""

_removal_message: str

def __init__(self, *args, **kwargs):
raise FeatureRemovedError(self._removal_message)


class GenerativeDesignInput(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = GENERATIVE_DESIGN_REMOVED


class GenerativeDesignResult(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = GENERATIVE_DESIGN_REMOVED


class GenerativeDesignExecution(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = GENERATIVE_DESIGN_REMOVED


class GenerativeDesignExecutionCollection(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = GENERATIVE_DESIGN_REMOVED


class FingerprintType(BaseEnumeration):
"""Removed along with generative design. Its members remain for existing scripts."""

AP = "AP"
PHCO = "PHCO"
BPF = "BPF"
PATH = "PATH"
ECFP4 = "ECFP4"
ECFP6 = "ECFP6"
FCFP4 = "FCFP4"
FCFP6 = "FCFP6"


class StructureExclusion(BaseEnumeration):
"""Removed along with generative design. Its members remain for existing scripts."""

DOUBLE_BONDS = "DOUBLE_BONDS"
TRIPLE_BONDS = "TRIPLE_BONDS"
ANIONS = "ANIONS"
CATIONS = "CATIONS"
IONS = "IONS"
BORON = "BORON"
PHOSPHORUS = "PHOSPHORUS"
SULFUR = "SULFUR"
NITROGEN = "NITROGEN"
OXYGEN = "OXYGEN"
FLUORINE = "FLUORINE"
BROMINE = "BROMINE"
IODINE = "IODINE"
CHLORINE = "CHLORINE"


class SampleDesignSpaceInput(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = SAMPLING_REMOVED


class SampleDesignSpaceExecution(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = SAMPLING_REMOVED


class SampleDesignSpaceExecutionCollection(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = SAMPLING_REMOVED


class SampleSearchSpaceResultCandidate(_RemovedClass):
"""Removed. Constructing one raises :class:`~citrine.exceptions.FeatureRemovedError`."""

_removal_message = SAMPLING_REMOVED


_REMOVED_NAMES = {
cls.__name__: cls
for cls in (
GenerativeDesignInput,
GenerativeDesignResult,
GenerativeDesignExecution,
GenerativeDesignExecutionCollection,
FingerprintType,
StructureExclusion,
SampleDesignSpaceInput,
SampleDesignSpaceExecution,
SampleDesignSpaceExecutionCollection,
SampleSearchSpaceResultCandidate,
)
}


def deprecated_names(
module_name: str, removal_message: str, names: Iterable[str]
) -> Callable[[str], type]:
"""Build a module ``__getattr__`` that supplies removed names with a DeprecationWarning.

The legacy module must not bind these names itself.
Python calls a module's ``__getattr__`` only for names the module lacks.

Parameters
----------
module_name: str
The ``__name__`` of the module that used to define the names.
removal_message: str
The sentence that states which feature the platform removed.
names: Iterable[str]
The removed names the module supplies.

Returns
-------
Callable[[str], type]
A function to assign to the module's ``__getattr__``.

"""
supplied = {name: _REMOVED_NAMES[name] for name in names}

def __getattr__(name: str) -> type:
if name not in supplied:
raise AttributeError(f"module {module_name!r} has no attribute {name!r}")
warn(
f"{module_name}.{name} is deprecated as of {DEPRECATED_IN} and will be removed "
f"in {REMOVED_IN}. {removal_message}",
DeprecationWarning,
stacklevel=2,
)
return supplied[name]

return __getattr__
7 changes: 7 additions & 0 deletions src/citrine/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class WorkflowNotReadyException(RetryableException):
"""The workflow is not ready to be executed. I.e., still validating. (http status 425)."""


class FeatureRemovedError(NonRetryableException, AttributeError):
"""The feature has been removed from the Citrine Platform.

It is also an AttributeError, so hasattr() and introspection skip the removed accessors.
"""


class PollingTimeoutError(NonRetryableException):
"""Polling for an asynchronous result has exceeded the timeout."""

Expand Down
17 changes: 4 additions & 13 deletions src/citrine/informatics/design_candidate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from citrine._serialization import properties
from citrine._utils import removed_features as _removed_features
from citrine._serialization.polymorphic_serializable import PolymorphicSerializable
from citrine._serialization.serializable import Serializable

Expand All @@ -12,7 +13,6 @@
"MeanAndStd",
"Mixture",
"MolecularStructure",
"SampleSearchSpaceResultCandidate",
"TopCategories",
]

Expand Down Expand Up @@ -206,15 +206,6 @@ class HierarchicalDesignCandidate(Serializable["HierarchicalDesignCandidate"]):
""":HierarchicalDesignMaterial: the material returned by the design workflow"""


class SampleSearchSpaceResultCandidate(Serializable["SampleSearchSpaceResultCandidate"]):
"""A hierarchical candidate material generated by the Citrine Platform.

This class represents the candidate computed by a design execution.
"""

uid = properties.UUID("id")
""":UUID: unique external Citrine ID of the material"""
execution_uid = properties.UUID("id")
""":UUID: unique external Citrine ID of the execution"""
material = properties.Object(HierarchicalDesignMaterial, "material")
""":HierarchicalDesignMaterial: the material returned by the design workflow"""
__getattr__ = _removed_features.deprecated_names(
__name__, _removed_features.SAMPLING_REMOVED, ["SampleSearchSpaceResultCandidate"]
)
23 changes: 8 additions & 15 deletions src/citrine/informatics/design_spaces/sample_design_space.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from citrine._serialization import properties
from citrine._serialization.serializable import Serializable
"""Design space sampling has been removed from the Citrine Platform.

Importing a name from this module emits a DeprecationWarning.
Using one of its classes raises :class:`~citrine.exceptions.FeatureRemovedError`.
"""

class SampleDesignSpaceInput(Serializable["SampleDesignSpaceInput"]):
"""A Citrine Sample Design Space Execution Input.
from citrine._utils import removed_features

Parameters
----------
n_candidates: int
The number of non-correlated samples to draw from the design space domain.

"""

n_candidates = properties.Integer("n_candidates")

def __init__(self, *, n_candidates: int):
self.n_candidates: int = n_candidates
__getattr__ = removed_features.deprecated_names(
__name__, removed_features.SAMPLING_REMOVED, ["SampleDesignSpaceInput"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from citrine._serialization.polymorphic_serializable import PolymorphicSerializable
from citrine._serialization.serializable import Serializable
from citrine._session import Session
from citrine.resources.sample_design_space_execution import SampleDesignSpaceExecutionCollection
from citrine.exceptions import FeatureRemovedError
from citrine._utils.removed_features import SAMPLING_REMOVED

__all__ = ["TopLevelDesignSpace"]

Expand Down Expand Up @@ -72,7 +73,5 @@ def is_locked(self) -> bool:

@property
def sample_design_space_executions(self):
"""Start a Sample Design Space Execution using the current Design Space."""
return SampleDesignSpaceExecutionCollection(
project_id=self._project_id, design_space_id=self.uid, session=self._session
)
"""Removed. Accessing it raises :class:`~citrine.exceptions.FeatureRemovedError`."""
raise FeatureRemovedError(SAMPLING_REMOVED)
9 changes: 8 additions & 1 deletion src/citrine/informatics/executions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# flake8: noqa
from .predictor_evaluation import *
from .design_execution import *
from .generative_design_execution import *

from citrine._utils import removed_features as _removed_features

__getattr__ = _removed_features.deprecated_names(
__name__,
_removed_features.GENERATIVE_DESIGN_REMOVED,
["GenerativeDesignExecution", "GenerativeDesignResult"],
)
Loading
Loading