citrine.resources.predictor module
Resources that represent collections of predictors.
- class citrine.resources.predictor.AsyncDefaultPredictor
Bases:
Resource
[AsyncDefaultPredictor
]Return type for async default predictor generation and retrieval.
- access_control_dict() dict
Return an access control entity representation of this resource. Internal use only.
- classmethod build(data: dict) Self
Build an instance of this object from given data.
- dump() dict
Dump this instance.
- predictor = None
Optional[GraphPredictor]:
- status = None
short description of the resource’s status
- Type:
str
- status_detail = []
a list of structured status info, containing the message and level
- Type:
List[StatusDetail]
- uid = None
Citrine Platform unique identifier for this task.
- Type:
UUID
- class citrine.resources.predictor.AutoConfigureMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
BaseEnumeration
The format to use in building auto-configured assets.
PLAIN corresponds to a single-row GEM table and plain predictor
FORMULATION corresponds to a multi-row GEM table and formulations predictor
INFER auto-detects the GEM table and predictor type
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count(sub[, start[, end]]) int
Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith(suffix[, start[, end]]) bool
Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find(sub[, start[, end]]) int
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- format(*args, **kwargs) str
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping) str
Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index(sub[, start[, end]]) int
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if the string is printable, False otherwise.
A string is printable if all of its characters are considered printable in repr() or if it is empty.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, count=-1, /)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind(sub[, start[, end]]) int
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- rindex(sub[, start[, end]]) int
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith(prefix[, start[, end]]) bool
Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- FORMULATION = 'FORMULATION'
- INFER = 'INFER'
- PLAIN = 'PLAIN'
- class citrine.resources.predictor.PredictorCollection(project_id: UUID, session: Session)
Bases:
Collection
[GraphPredictor
]Represents the collection of all predictors for a project.
- Parameters:
project_id (UUID) – the UUID of the project
- archive(uid: UUID | str)
[UNSUPPORTED] Use archive_root or archive_version instead.
- archive_root(uid: UUID | str)
Archive a root predictor.
- uid: Union[UUID, str]
Unique identifier of the predictor to archive.
- archive_version(uid: UUID | str, *, version: int | str) GraphPredictor
Archive a predictor version.
- build(data: dict) GraphPredictor
Build an individual Predictor.
- check_for_update(uid: UUID | str) GraphPredictor | None
Check if there are updates available for a predictor.
Typically these are updates to the training data. For example, a GEM Table may have been re-built to include additional rows.
This check does not update the predictor; it just returns the update that is available. To perform the update, the response should then be used to call PredictorCollection.update
- Parameters:
uid (Union[UUID, str]) – Unique identifier of the predictor to check
- Returns:
The update, if an update is available; None otherwise.
- Return type:
Optional[Predictor]
- create_default(*, training_data: DataSource, pattern: str | AutoConfigureMode = AutoConfigureMode.INFER, prefer_valid: bool = True) GraphPredictor
Create a default predictor for some training data.
This method will return an unregistered predictor generated by inspecting the training data and attempting to automatically configure the predictor.
The configuration generated while using the AutoConfigureMode.SIMPLE pattern includes featurizers for chemical formulas/molecular structures, and AutoMLPredictor`s for any variables identified as responses in the training data. The configuration generated while using the `AutoConfigureMode.FORMULATION pattern includes these same components, as well as a SimpleMixturePredictor, LabelFractionsPredictor, IngredientFractionsPredictor, and a series of MeanPropertyPredictor`s to handle featurization of formulation quantities and ingredient properties. The `AutoConfigureMode.INFER pattern chooses an appropriate mode based on whether the data source contains formulations data or not.
- Parameters:
training_data (DataSource) – The data to configure the predictor to model.
pattern (AutoConfigureMode or str) – The predictor pattern to use, either “PLAIN”, “FORMULATION”, or “INFER”. The “INFER” pattern auto-detects whether the DataSource contains formulations data or not. If it does, then a formulation predictor is created. If not, then a plain predictor is created.
prefer_valid (Boolean) – If True, enables filtering of sparse descriptors and trimming of excess graph components in attempt to return a default configuration that will pass validation. Default: True.
- Returns:
Automatically configured predictor for the training data
- Return type:
- create_default_async(*, training_data: DataSource, pattern: str | AutoConfigureMode = AutoConfigureMode.INFER, prefer_valid: bool = True) AsyncDefaultPredictor
Similar to PredictorCollection.create_default, except asynchronous.
This begins a long-running task to generate the predictor. The returned object contains an ID which can be used to track its status and get the resulting predictor once complete. PredictorCollection.get_default_async is intended for that purpose.
See PredictorCollection.create_default for more details on the generation process and parameter specifics.
- Parameters:
training_data (DataSource) – The data to configure the predictor to model.
pattern (AutoConfigureMode or str) – The predictor pattern to use, either “PLAIN”, “FORMULATION”, or “INFER”. The “INFER” pattern auto-detects whether the DataSource contains formulations data or not. If it does, then a formulation predictor is created. If not, then a plain predictor is created.
prefer_valid (Boolean) – If True, enables filtering of sparse descriptors and trimming of excess graph components in attempt to return a default configuration that will pass validation. Default: True.
- Returns:
Information on the long-running default predictor generation task.
- Return type:
- delete(uid: UUID | str)
Predictors cannot be deleted at this time.
- generate_feature_effects_async(uid: UUID | str, *, version: int | str) GraphPredictor
Begin generation of feature effects.
version can be any numerical version (which exists), “latest”, or “most_recent”. Although note that this will fail if the predictor is not already trained.
Feature effects are automatically generated for all new predictors after a successful training as of the end of 2024. This call allows either regenerating those values, or generating them for older predictors.
This call just begins the process; generation usually takes a few minutes, but can take much longer. As soon as the call completes, the old values will be inaccessible. To wait for the generation to complete, and to retrieve the new values once they’re ready, use GraphPredictor.feature_effects.
- get(uid: UUID | str, *, version: int | str = 'most_recent') GraphPredictor
Get a predictor by ID and (optionally) version.
If version is omitted, the most recent version will be retrieved.
- get_default_async(*, task_id: UUID | str) AsyncDefaultPredictor
Get the current async default predictor generation result.
The status field will indicate if it’s INPROGRESS, SUCCEEDED, or FAILED. While INPROGRESS, the predictor will also be None. Once it’s SUCCEEDED, it will be populated with a GraphPredictor, which can then be registered to the platform. If it’s FAILED, look to the status_detail field for more information on what went wrong.
- get_featurized_training_data(uid: UUID | str, *, version: int | str = 'most_recent') List[HierarchicalDesignMaterial]
Retrieve a list of featurized materials for a trained predictor.
Featurized materials contain the input variables found in the training data source along with any internal features generated by the predictor while training. If not available, retraining the predictor will generate new featurized data.
- Parameters:
uid (UUID) – the UUID of the predictor
version (str) – the version of the predictor (if omitted, the most recent will be used)
- Return type:
A list of featurized materials, formatted as design materials
- is_stale(uid: UUID | str, *, version: int | str) bool
Returns True if a predictor is stale, False otherwise.
A predictor is stale if it’s in the READY state, but the platform cannot load the previously trained object.
- list(*, per_page: int = 20) Iterable[GraphPredictor]
List the most recent version of all non-archived predictors.
- list_all(*, per_page: int = 20) Iterable[GraphPredictor]
List the most recent version of all predictors.
- list_archived(*, per_page: int = 20) Iterable[GraphPredictor]
List the most recent version of all archived predictors.
- list_archived_versions(uid: UUID | str = None, *, per_page: int = 20) Iterable[GraphPredictor]
List all archived versions of the given Predictor.
- list_versions(uid: UUID | str = None, *, per_page: int = 100) Iterable[GraphPredictor]
List all non-archived versions of the given Predictor.
- register(predictor: GraphPredictor, *, train: bool = True) GraphPredictor
Register and optionally train a Predictor.
This predctor will be version 1, and its draft flag will be True. If train is True and training completes successfully, the draft flag will be set to False. Otherwise, it will remain True.
- rename(uid: UUID | str, *, version: int | str, name: str | None = None, description: str | None = None) GraphPredictor
Rename an existing predictor.
Both the name and description can be changed. This does not trigger retraining. Any existing version of the predictor can be renamed, or “most_recent”.
- restore(uid: UUID | str)
[UNSUPPORTED] Use restore_root or restore_version instead.
- restore_root(uid: UUID | str)
Restore an archived root predictor.
- uid: Union[UUID, str]
Unique identifier of the predictor to restore.
- restore_version(uid: UUID | str, *, version: int | str) GraphPredictor
Restore a predictor version.
- retrain_stale(uid: UUID | str, *, version: int | str) GraphPredictor
Begins retraining a stale predictor.
This can only be used on a stale predictor, which is when it’s in the READY state, but the platform cannot load the previously trained object. Using it on a non-stale predictor will result in an error.
- root_is_archived(uid: UUID | str) bool
Determine if the predictor root is archived.
- uid: Union[UUID, str]
Unique identifier of the predictor to check.
- train(uid: UUID | str) GraphPredictor
Train a predictor.
If the predictor is not a draft, a new version will be created which is a copy of the current predictor version as a draft, which will be trained. Either way, if training completes successfully, the Predictor will no longer be a draft.
- update(predictor: GraphPredictor, *, train: bool = True) GraphPredictor
Update and optionally train a Predictor.
If the predictor is a draft, this will overwrite its contents. If it’s not a draft, a new version will be created with the update.
In either case, training will begin after the update if train is True. And if training completes successfully, the Predictor will no longer be a draft.