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
65 changes: 65 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# AGENTS.md

`citrine-python` is the Python SDK for the Citrine Platform. Users install it from PyPI as `citrine`. It calls the platform REST APIs and builds on the `gemd` package from `gemd-python`.

## Layout

| Path | Contents |
|------|----------|
| `src/citrine/citrine.py` | `Citrine`, the client entry point |
| `src/citrine/_session.py` | HTTP session, auth, and request logging |
| `src/citrine/resources/` | Platform resources and their collections, such as projects, teams, and datasets |
| `src/citrine/informatics/` | AI Engine models: predictors, design spaces, constraints, and workflows |
| `src/citrine/gemtables/`, `src/citrine/gemd_queries/` | GEM Table definitions and GEMD query criteria |
| `src/citrine/_rest/`, `src/citrine/_serialization/` | Base collection and pagination classes, and the base classes for serialization |
| `src/citrine/__version__.py` | Package version, read by setuptools |
| `tests/` | Unit tests, which mirror `src/citrine/`. Shared fakes and factories are in `tests/utils/` |
| `docs/source/` | Sphinx source in `.rst` |
| `scripts/` | Test runner, version-bump check, and docs build |

## Commands

CI installs dependencies with pip from `requirements.txt` and `test_requirements.txt`, which pin exact versions. The repo has no `uv.lock`, and CI uses none of the dependency groups in `pyproject.toml`. Set up a virtual environment the same way:

```bash
pip install -r requirements.txt -r test_requirements.txt
pip install --no-deps -e .
```

| Task | Command |
|------|---------|
| Lint | `flake8 src/citrine` |
| Format | `ruff format src tests` |
| Expired deprecations | `derp src src/citrine/__version__.py` |
| Tests with coverage | `pytest --cov=src/citrine --cov-report term-missing:skip-covered --cov-config=tox.ini --no-cov-on-fail --cov-fail-under=100 tests/` |
| Version-bump check | `python scripts/validate_version_bump.py`. It runs `git fetch origin` first. |
| Version check, lint, deprecations, and tests | `scripts/run_tests.sh`. It exits with an error on `main`. |
| Docs | `pip install -r doc_requirements.txt`, then `make -C docs html` |

## CI gates

Pull requests into `main` and `release/**` run `.github/workflows/pr-checks.yml` and `pr-tests.yml`. Both call shared workflows in `CitrineInformatics/common-gh-actions`. To pass, a PR needs:

1. A higher version in `src/citrine/__version__.py` than `origin/main` has.
2. A clean `flake8` run on `src/citrine`.
3. No `removed_in` deprecation at or below the current version, checked by `derp`.
4. Passing tests at 100% line coverage, on Python 3.10 through 3.14, on Linux, macOS, and Windows.

The docs job builds with `-W` but has `continue-on-error`, so doc warnings do not block. Publishing a GitHub release deploys to PyPI and GitHub Pages.

## Conventions

- Style is PEP 8 with a 99-character code limit and a 119-character docstring limit. `tox.ini` holds the flake8 config and its ignore list.
- Lint with `flake8` and format with `ruff format`. `pyproject.toml` holds the ruff config.
- Write Numpy-style docstrings. Sphinx autogenerates `docs/source/reference/`, which git ignores.
- Make arguments keyword-only, except a first argument that is required, obvious, and shared by similar methods.
- Name an object's own identifier `uid`. Name the identifier of another type `<type>_id`, such as `bar_id`.
- Mark unsupported experimental APIs with `[ALPHA]` at the start of the docstring.
- Add runtime dependencies to `pyproject.toml` and pin them in `requirements.txt`. Pin test-only dependencies in `test_requirements.txt`.
- `Citrine()` reads `CITRINE_API_KEY` and `CITRINE_API_HOST` when the caller passes no `api_key` or `host`. Unit tests use fake sessions from `tests/utils/` and run offline.

## Further reading

- `CONTRIBUTING.md`: style rules, logging, docs layout, and the release-notes template
- `.github/pull_request_template.md`: the PR checklist
- Published docs: https://citrineinformatics.github.io/citrine-python/
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
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.0"
__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__
6 changes: 6 additions & 0 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 Down Expand Up @@ -203,3 +204,8 @@ class HierarchicalDesignCandidate(Serializable["HierarchicalDesignCandidate"]):
""":int: rank by score amongst other candidates produced by the design workflow"""
material = properties.Object(HierarchicalDesignMaterial, "material")
""":HierarchicalDesignMaterial: the material returned by the design workflow"""


__getattr__ = _removed_features.deprecated_names(
__name__, _removed_features.SAMPLING_REMOVED, ["SampleSearchSpaceResultCandidate"]
)
17 changes: 8 additions & 9 deletions src/citrine/informatics/design_spaces/sample_design_space.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Design space sampling has been removed; this name remains so existing scripts fail clearly."""
"""Design space sampling has been removed from the Citrine Platform.

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

SAMPLING_REMOVED = "Design space sampling has been removed from the Citrine Platform."
from citrine._utils import removed_features


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

def __init__(self, *args, **kwargs):
raise FeatureRemovedError(SAMPLING_REMOVED)
__getattr__ = removed_features.deprecated_names(
__name__, removed_features.SAMPLING_REMOVED, ["SampleDesignSpaceInput"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from citrine._serialization.serializable import Serializable
from citrine._session import Session
from citrine.exceptions import FeatureRemovedError
from citrine.informatics.design_spaces.sample_design_space import SAMPLING_REMOVED
from citrine._utils.removed_features import SAMPLING_REMOVED

__all__ = ["TopLevelDesignSpace"]

Expand Down
8 changes: 8 additions & 0 deletions src/citrine/informatics/executions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# flake8: noqa
from .predictor_evaluation import *
from .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"],
)
13 changes: 13 additions & 0 deletions src/citrine/informatics/executions/generative_design_execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Generative design 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`.
"""

from citrine._utils import removed_features

__getattr__ = removed_features.deprecated_names(
__name__,
removed_features.GENERATIVE_DESIGN_REMOVED,
["GenerativeDesignExecution", "GenerativeDesignResult"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""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`.
"""

from citrine._utils import removed_features

__getattr__ = removed_features.deprecated_names(
__name__,
removed_features.SAMPLING_REMOVED,
["SampleDesignSpaceExecution", "SampleSearchSpaceResultCandidate"],
)
53 changes: 10 additions & 43 deletions src/citrine/informatics/generative_design.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
"""Generative design has been removed; these names remain so existing scripts fail clearly."""
"""Generative design has been removed from the Citrine Platform.

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

from citrine.exceptions import FeatureRemovedError
from citrine._utils import removed_features

GENERATIVE_DESIGN_REMOVED = "Generative design has been removed from the Citrine Platform."


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

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


class FingerprintType(BaseEnumeration):
"""Removed along with generative design; kept so scripts reach the removal error."""

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


class StructureExclusion(BaseEnumeration):
"""Removed along with generative design; kept so scripts reach the removal error."""

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"
__getattr__ = removed_features.deprecated_names(
__name__,
removed_features.GENERATIVE_DESIGN_REMOVED,
["GenerativeDesignInput", "GenerativeDesignResult", "FingerprintType", "StructureExclusion"],
)
Loading