Skip to content

Commit 5c73dd2

Browse files
authored
Merge pull request #833 from CitrineInformatics/single-predict-docs
PLA-12142 Add documentation for `predictor.predict()`
2 parents 284431c + 29a6fa5 commit 5c73dd2

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

docs/source/workflows/design_workflows.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ You can to look up what :doc:`score <scores>` was used for a particular executio
101101
descriptors = execution.descriptors
102102
103103
104+
.. _design_candidate_anchor:
105+
104106
Design Candidate
105107
-----------------
106108

docs/source/workflows/predictors.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,3 +838,51 @@ Because training data are shared by all predictors in the graph, a data source d
838838
If all data sources required to train a predictor are specified elsewhere in the graph, the ``training_data`` parameter may be omitted.
839839
If the graph contains a predictor that requires formulations data, e.g. a :class:`~citrine.informatics.predictors.simple_mixture_predictor.SimpleMixturePredictor` or :class:`~citrine.informatics.predictors.mean_property_predictor.MeanPropertyPredictor`, any GEM Tables specified by the graph predictor that contain formulation data must provide a formulation descriptor,
840840
and this descriptor must match the input formulation descriptor of the sub-predictors that require these data.
841+
842+
Single Predictions
843+
---------------------------------
844+
845+
Once a :class:`~citrine.informatics.predictors.predictor.Predictor` has been trained, a one-off prediction may be made against it by using the :func:`~citrine.informatics.predictors.predictor.Predictor.predict` method.
846+
847+
This method accepts a :class:`~citrine.informatics.predictors.single_predict_request.SinglePredictRequest`, which is akin to a :ref:`DesignCandidate <design_candidate_anchor>` that you can define and modify and is not persisted in the Citrine Platform. When building a :class:`~citrine.informatics.predictors.single_predict_request.SinglePredictRequest` note that only the material properties required to make a prediction (the "input" properties") are required. Indeed, when making a prediction on a predictor using the :func:`~citrine.informatics.predictors.predictor.Predictor.predict` method, the system will automatically filter out any provided material properties that are not inputs to the predictor. The output of a call to ``predict()`` is a :class:`~~citrine.informatics.predictors.single_prediction.SinglePrediction`, which is essentially the :class:`~citrine.informatics.predictors.single_predict_request.SinglePredictRequest` with all of the predicted properties of the material filled in with the predicted values.
848+
849+
Note that a ``random_seed`` may be provided to the :class:`~citrine.informatics.predictors.single_predict_request.SinglePredictRequest`. Providing a consistent ``random_seed`` across requests with the same inputs guantees consistent predictions.
850+
851+
The following is a simple example of several predictions based on a function that builds a list of prediction requests. This example retrieves 3 candidates from a prior design execution, updates them slightly, and makes new predictions with the updated inputs. Note that while this example uses existing an :ref:`DesignCandidate <design_candidate_anchor>` as a convenience to build the update prediction requests, there is no requirement that a prediction request be related to an existing :ref:`DesignCandidate <design_candidate_anchor>` -- rather any arbitrary request can be made as long as the inputs satisfy the requirements of the predictor.
852+
853+
.. code:: python
854+
855+
import os
856+
from citrine import Citrine
857+
from citrine.informatics.predictors.single_predict_request import SinglePredictRequest
858+
from citrine.informatics.predictors.single_prediction import SinglePrediction
859+
860+
# arbitrary example of building a list of requests
861+
def build_requests() -> list[SinglePredictRequest]:
862+
# assuming some my_execution: DesignExecution
863+
my_candidates = my_execution.candidates(per_page = 3)
864+
rs = []
865+
for idx, c in enumerate(my_candidates):
866+
my_candidate = c
867+
my_candidate.material.values["Heat Treatment Time 1"].mean -= 1
868+
rs.append(SinglePredictRequest(
869+
material_id = my_candidate.material_id,
870+
identifiers = my_candidate.identifiers,
871+
material = my_candidate.material,
872+
))
873+
if idx == 2:
874+
break
875+
return rs
876+
877+
# retrieve the predictor you'd like to use
878+
my_predictor = my_project.predictors.get(
879+
uid = PREDICTOR_ID, version = "most_recent")
880+
881+
# Make a prediction for each request and print out relevant results
882+
for request in build_requests():
883+
my_prediction: SinglePrediction = my_predictor.predict(request)
884+
my_id = request.material_id
885+
heat_treatment_time = request.material.values["Heat Treatment Time 1"].mean
886+
predicted_tensile_strength = my_prediction.material.values["Tensile Strength"].mean
887+
print(f"{my_id} updated_time={heat_treatment_time} strength={predicted_tensile_strength}")
888+

src/citrine/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.7.0'
1+
__version__ = '2.8.0'

0 commit comments

Comments
 (0)