WorksMathematics
Bayesian optimization with known experimental and design constraints for chemistry applications
Abstract
Optimization strategies driven by machine learning, such as Bayesian optimization, are being explored across experimental sciences as an efficient alternative to traditional design of experiment. When combined with automated laboratory hardware and high-performance computing, these strategies enable next-generation platforms for autonomous experimentation. However, the practical application of these approaches is hampered by a lack of flexible software and algorithms tailored to the unique requirements of chemical research. One such aspect is the pervasive presence of constraints in the experimental conditions when optimizing chemical processes or protocols, and in the chemical space that is accessible when designing functional molecules or materials. Although many of these constraints are known a priori, they can be interdependent, non-linear, and result in non-compact optimization domains. In this work, we extend our experiment planning algorithms Phoenics and Gryffin such that they can handle arbitrary known constraints via an intuitive and flexible interface. We benchmark these extended algorithms on continuous and discrete test functions with a diverse set of constraints, demonstrating their flexibility and robustness. In addition, we illustrate their practical utility in two simulated chemical research scenarios: the optimization of the synthesis of o-xylenyl Buckminsterfullerene adducts under constrained flow conditions, and the design of redox active molecules for flow batteries under synthetic accessibility constraints. The tools developed constitute a simple, yet versatile strategy to enable model-based optimization with known experimental constraints, contributing to its applicability as a core component of autonomous platforms for scientific discovery.
Introduction
The design of advanced materials and functional molecules often relies on combinatorial, high-throughput screening strategies enabled by high-performance computing and automated laboratory equipment. Despite the successes of high-throughput experimentation in chemistry, biology, and materials science, these approaches typically employ exhaustive searches that scale exponentially with the size of the search space. Data-driven strategies that can adaptively search parameter spaces without the need for exhaustive exploration are thus replacing traditional design of experiment approaches in many instances. These strategies use machine-learnt surrogate models trained on all data generated through the experimental campaign, and are updated each time new data is collected. One such approach is Bayesian optimization which, based on the surrogate model, defines a utility function that prioritize experiments based on their expected informativeness and performance.⁶–⁸ These data-driven optimization strategies have already demonstrated superior performance in chemistry and materials science applications, e.g., in reaction optimization,⁹,¹⁰ the discovery of magnetic resonance imaging agents,¹¹ the fabrication of organic photovoltaic materials,¹²,¹³ virtual screening of ultra-large chemical libraries,¹⁴ and the design of mechanical structures with additively manufactured components.¹⁵
Machine learning-driven experiment planning strategies can also be combined with automated laboratory hardware or high-performance computing to create self-driving platforms capable of achieving research goals autonomously.¹⁶–²² Prototypes of these autonomous research platforms have already shown promise in diverse applications, including the optimization of chemical reaction conditions,⁹,¹⁰ the design of photocatalysts for the production of hydrogen from water,²³ the discovery of battery electrolytes,²⁴ the design of nanoporous materials with tailored adsorption properties,²⁵ the optimization of multicomponent polymer blend formulations for organic photovoltaics,[12] the discovery of phase-change memory materials for photonic switching devices,26 and self-optimization of metal nanoparticle synthesis,27 to name a few.[13] [28] While self-driving platforms seem poised to deliver a next-generation approach to scientific discovery, their practical application is hampered by a lack of flexible software and algorithms tailored to the unique requirements of chemical research.
To provide chemistry-tailored data-driven optimization tools, our group has developed Phoenics29 and Gryffin,30 among others31–33. Phoenics is a linear-scaling Bayesian optimizer for continuous spaces that uses a kernel regression surrogate model and natively supports batched optimization. Gryffin is an extension of this algorithm to categorical, as well as mixed continuous-categorical spaces. Furthermore, Gryffin is able to leverage expert knowledge in the form of descriptors to enhance its optimization performance, which was found particularly useful in combinatorial optimizations of molecules and materials.30 As Gryffin is the more general algorithm, and Phoenics is included within its capabilities, from here on we will refer only to Gryffin. These algorithms have already found applications ranging from the optimization of reaction conditions[10] and synthetic protocols,27,34 to that of manufacturing of thin film materials[13] and organic photovoltaic devices.[12] However, a number of extensions are still required to make these tools suitable to the broadest range of chemistry applications. In particular, Gryffin, like the majority of Bayesian optimization tools available, does not handle known experimental or design constraints.
There are often many constraints on the experiment being performed or molecule being designed. A flexible data-driven optimization tool should be able to accommodate and handle such constraints. The type of constraints typically encountered may be separated into those that affect the objectives of the optimization (e.g., reaction yield, desired molecular properties), and those that affect the optimization parameters (e.g., reaction conditions). Those affecting the objectives usually arise in multi-objective optimization, where one would like to optimize a certain property while constraining another to be above/below a desired value.31,35,36 For instance, we might want to improve the solubility of a drug candidate, while keeping its protein-binding affinity in the nanomolar range. Conversely, parameter constraints limit the range of experiments or molecules we have access to. Depending on the source of the constraints, these may be referred to as known or unknown. Known constraints are those we are aware of a priori,37–40 while unknown ones are discovered through experimentation37–40. For instance, a known constraint might enforce the total volume for two liquids to not exceed the available volume in the container in which they are mixed. While this poses a restriction on the parameter space, we are aware of it in advance and can easily compute which regions of parameter space are infeasible. An unknown constraint may instead be the synthetic accessibility in a molecular optimization campaign. In this case, we might not know in advance which areas of chemical space are easily accessible, and have to resort to trial and error to identify feasible and infeasible synthetic targets. While constraints of the objectives were the subject of our previous work,31 and unknown constraints of the parameters are the subject of on-going work, this paper focuses on data-driven optimization with known parameter constraints, which we will refer to simply as known constraints from here on.
Generally, known constraints arise due to physical or hardware restrictions, safety concerns, or user preference. An example of a physically imposed constraint is the fact that the temperature of a reaction cannot exceed the boiling temperature of its solvent. As such, one may want temperature to be varied in the interval °C for experiments using water, and in °C for experiments using tetrahydrofuran. The fact that the sum of volumes of different solutions cannot exceed that of the container they are mixed in is an example of a hardware-imposed constraint. In synthetic chemistry, specific combinations of reagents and conditions might need to be avoided for safety reasons instead. Finally, constraints could also be placed by the researchers to reflect prior knowledge about the performance of a certain protocol. For example, a researcher might know in advance that specific combinations of solvent, substrate, and catalyst will return poor yields. These examples are not natively handled by Gryffin and the majority of data-driven optimization tools currently available. In fact, given any number of continuous or categorical parameters, their full Cartesian product is assumed to be accessible by the optimization algorithm. Returning to the example where solvents have different boiling temperatures, this means that if the optimization range for the variable is set to °C, this range will be applied to all solvents considered. In practice, known constraints are often interdependent, non-linear, and can result in non-compact optimization domains.
In this work, we extend the capabilities of Gryffin to optimization over parameter domains with known constraints. First, we provide a formal introduction to the known constraint problem and detail how Gryffin was extended to be able to flexibly handle such scenarios. Then, we benchmark our new constrained version of Gryffin on a range of analytical functions subject to a diverse set of constraints. Finally, we demonstrate our method on two chemistry applications: the optimization of the synthesis of o-xylyl Buckminsterfullerene adducts under constrained flow conditions, and the design of redox active molecules for flow batteries under synthetic accessibility constraints. Across all tests, we compare Gryffin’s performance to that of other optimization strategies, such as random search and genetic algorithms, which can also handle complex constraints.
Methods
An optimization task involves the identification of parameters, , that yield the most desirable outcome for an objective . In a chemistry context, these parameters may be experimental conditions or different R groups in a molecule, while the objectives may be the yield of a reaction or absorbance at a specific wavelength. Formally, for a minimization problem, the solution of the optimization is the set of parameters that minimizes the objective ,
where is the optimization domain, or parameter space; i.e., the space of all experimental conditions that could have been explored during the optimization. In a Bayesian optimization setting, the objective function is considered to be unknown, but can be empirically evaluated at specific values of . Evaluating is assumed to be expensive and/or time consuming, and its measurement subject to noise. We also assume that we have no access to gradient information about .
In a constrained optimization problem, can be evaluated only for a subset of the optimization domain, . A constraint function determines which parameters are feasible and thus in , and which are not. Contrary to unknown constraints, known constraints are those for which we have access to a priori, that is, we are aware of them before performing the optimization. Importantly, we can evaluate the functions and independently of one another. The solution of this constrained optimization problem may be written formally as
The physically meaning of is case dependent and domain specific. In chemistry, known constraints may reflect safety concerns, physical limits imposed by laboratory equipment, or simply researcher preference. The types of known constraints described above, and the subject of this work, are hard constraints. They restrict irrefutably and no measurement outside of is permitted. However, the use of soft constraints has also been explored. While soft constraints bias the optimization algorithm away from regions that are thought to yield undesirable outcomes, they ultimately still allow the full exploration of . As such, soft constraints have been used as means to introduce inductive biases into an optimization campaign based on prior knowledge.41,42
The goal of this work is to equip Gryffin with the ability to satisfy arbitrary constraints, as described by a user-defined constraint function . This can be achieved by constraining the optimization of the acquisition function .43 defines the utility (or risk) of evaluating the parameters , and the parameters proposed by the algorithm are those that optimize . Thus, constrained optimization of the acquisition function also constrains the overall optimization problem accordingly. However, contrary to objective function , the acquisition function is easy to optimize, as its analytical form is known and can be evaluated cheaply.
Acquisition optimization in Gryffin
Gryffin’s acquisition function, which is to be minimized, is defined as
where are the kernels of the kernel regression model used as the surrogate, are the measured objective function values, and is a user-defined parameter that determines the exploration-exploitation behavior of the algorithm. The index refers to each past observation, for a total number of observations .
For continuous parameters, Gryffin uses Gaussian kernels with prior precision sampled from a Gamma distribution, , with prior hyperparameters and . For categorical and discrete parameters, it uses Gumbel-Softmax44,45 kernels with a prior temperature parameter of . These prior parameters are, however, updated by a Bayesian neural network in light of the observed data.29 As the prior precision of the kernels increases with the number of observations, the surrogate model is encouraged to fit the observations more accurately as more data is acquired.
Acquisition function optimization in Gryffin generally follows a two-step strategy in which a global search is followed by local refinement. First, sets of input parameters are sampled uniformly from the optimization domain. By default, the number of samples is set to be directly proportional to the dimensionality of the optimization domain. Then, continuous parameters are optimized with a gradient method for a pre-defined number of iterations. While early versions of Gryffin employed second order methods such as L-BFGS, the default gradient-based approach is now Adam.46 Categorical and discrete parameters are optimized instead following a hill-climbing approach (which we refer to as Hill), in which each initial sample is modified uniformly at random, one dimension at a time, and each move is accepted only if it improves .
In addition to gradient-based optimization of the acquisition function, in this work we have implemented gradient-free optimization via a genetic algorithm. The population of parameters is firstly selected uniformly at random, as described above. Then, each in the population is evolved via crossover, mutation and selection operations, with elitism applied. This approach handles continuous, discrete, and categorical parameters by applying different mutations and cross-over operations depending on the type. A more detailed explanation of the genetic algorithm used for acquisition optimization is provided in SI Sec. S.1.B. This approach is implemented in Python and makes use of the DEAP library.47,48
Figure 1 provides a visual example of how these two approaches optimize the acquisition function of Gryffin. While Adam optimizes each random sample (black crosses) via small steps towards better values (grey to white crosses), the genetic approach does so via larger stochastic jumps in parameter space.

Figure 1. Illustration of unconstrained (top row) and constrained (bottom row) acquisition function optimization using strategies based on the Adam optimizer and a genetic algorithm. Initial, random samples are shown as black crosses. Grey crosses represent the updated parameter locations for these initial samples, while white crosses show the final locations after ten optimization iterations. The purple star indicates the global optima of the unconstrained acquisition function, which lies in the infeasible region in the constrained example.
Constrained acquisition optimization with Adam or Hill
To constrain the optimization of the acquisition function according to a user-defined constraint function , we first sample a set of feasible parameters with rejection sampling. That is, we sample uniformly from the optimization domain and we retain only samples that satisfy the constraint function . Sampling is performed until the desired number of feasible samples is drawn. Local optimization of parameters is then performed with Adam, as described above, but it is terminated as soon as an update results in infeasible (Fig. 1). For categorical and discrete parameters, Hill is used rather than Adam, but the constraint protocol is equivalent. In this case, after rejection sampling, any move in parameter space is accepted only if it improves and subject to .
In addition to the above, we also modify the prior precisions of the kernels used by the surrogate model. In particular, we substitute the number of observations with the observation density in the prior hyperparameters for the Gaussian and Gumbel-Softmax kernels, where is the volume of the feasible region as a fraction of the overall optimization domain. When no constraints are used, , and the formulation reduces to the original one used by Gryffin. However, when known constraints are present, this approach ensures that the kernels’ bandwidths reflect the information density of the data and avoids underfitting. As is known and can be computed in advance, the user is asked to provide it when using constraints. However, for convenience, and in case of fairly complex sets of constraints, we extend Gryffin to also numerically estimate . While this approach to kernel scaling may not be optimal in the presence of non-isotropic feasible regions, in which the viable optimization domain may expand to different extent in different dimensions, it is simple as well as independent of the details of the constraints, such that it results in no additional overheads.
Constrained acquisition optimization with a genetic algorithm
The population of the genetic optimization procedure is initialized with rejection sampling as described above for gradient approaches. However, to keep the optimized parameters within the feasible region, a subroutine is used to project infeasible offspring onto the feasibility boundary using binary search (SI Sec. S.1.B). In addition to guaranteeing that the optimized parameters satisfy the constraint function, this approach also ensures sampling of parameters close to the feasibility boundary (Fig. 1). We also use modified prior kernel precisions as described in the previous section.
Despite having implemented constraints in Gryffin independently, when preparing this manuscript we realized that known constraints in Dragonfly49 have been implemented following a very similar strategy. However, rather than projecting infeasible offspring solution on the feasibility boundary, Dragonfly relies solely on rejection sampling.
A practical advantage of the genetic optimization strategy is its favourable computational scaling compared to its gradient-based counterpart. We conducted benchmarks in which the time needed by Gryffin to optimize the acquisition function was measured for different numbers of past observations and parameter space dimensions (SI Sec. S.1.C). In fact, acquisition optimization is the most costly task in most Bayesian optimization algorithms, including Gryffin. The genetic strategy provided a speedup of approximately 5× over Adam when the number of observations was varied, and of approximately 2.5× when the dimensionality of the optimization domain was varied. The better time complexity of the zeroth-order approach is primarily due to derivatives of not having to be computed. In fact, our Adam implementation currently computes derivatives numerically. Future work will focus on deriving the analytical gradients for Gryffin’s acquisition function, or taking advantage of automatic differentiation schemes, such that this gap might reduce or disappear in future versions of the code.
User interface
With user-friendliness and flexibility in mind, we extended Gryffin’s Python interface such that it can take a user-defined constraint function among its inputs. As an example, the following code snippet shows an instantiation of Gryffin where the sum of two volumes is constrained.
from gryffin import Gryffin
# set path to optimization configuration
config_file = "config.json"
def my_constraints(params):
vol0 = params["volume_0"]
vol1 = params["volume_1"]
if vol0 + vol1 > 50:
return False
else:
return True
gryffin = Gryffin(config_file=config_file,
known_constraints=my_constraints)
This example could be that of a minimization over two parameters, , subject to the constraint that the sum of and does not exceed some upper bound ,
Current limitations
We note two limitations of our approach to known constraints. First, in continuous spaces, the current implementation handles only inequality constraints. Equality constraints, such as , effectively change the dimensionality of the optimization problem and can be tackled via a re-definition of the optimization domain or analytical transforms. For instance, for the two-dimensional example above, the constraint can be satisfied simply by optimizing over , while setting .
Second, because of the rejection sampling procedure used (§ 2.B), the cost of acquisition optimization is inversely proportional to the fraction of the optimization domain that is feasible. The smaller the feasible volume fraction is, the more samples need to be drawn uniformly at random before reaching the predefined number of samples to be collected for acquisition optimization. It thus follows that the feasible region, as determined by the user-defined constraint function, should not be exceedingly small (e.g., less than 1% of the optimization domain), as in that case Gryffin’s acquisition optimization would become inefficient. In practice we find that when only a tiny fraction of the overall optimization domain is considered feasible, it is because of a sub-optimal definition of the optimization domain, which can be solved by re-framing the problem. A related issue may arise if the constraints define disconnected feasible regions with vastly different volumes. In this scenario, given uniform sampling, little or no samples may be drawn from the smaller region. However, this too is an edge case that is unlikely to arise in practical applications, as the definition of completely separate optimization regions with vastly different scales tends to imply a scenario where multiple separate optimizations would be a more suitable solution. Future work will focus on overcoming these two challenges. For instance, deep learning techniques like invertible neural networks50 may be used to learn a mapping from the unconstrained to the constrained domain, such that the optimization algorithm would be free to operate on the hypercube while the proposed experimental conditions would satisfy the constraints.
Results and Discussion
In this section we test the ability of Gryffin to handle arbitrary known constraints. First, we show how Gryffin can efficiently optimize continuous and discrete (ordered) benchmark functions with a diverse set of constraints. Then, we demonstrate the practical utility of handling known constraints on two relevant chemistry examples: the optimization of the synthesis of o-xylyl Buckminsterfullerene adducts under constrained flow conditions, and the design of redox active molecules for flow batteries under synthetic accessibility constraints.
In addition to testing Gryffin—with both gradient and evolutionary based-acquisition optimization strategies, referred to as Gryffin (Adam/Hill) and Gryffin (Genetic), respectively—we also test three other constrained optimization strategies amenable to experiment planning. Specifically, we use random search (Random), a genetic algorithm (Genetic), and Bayesian optimization with a Gaussian process surrogate model (Dragonfly). Genetic is the same algorithm developed for constrained acquisition function optimization, but it is here employed directly to optimize the objective function (§ 2.C). Dragonfly uses the Dragonfly package49 for optimization. Similar to Gryffin, Dragonfly allows for the specification of arbitrarily complex constraints via a Python function, which is not the case for most other Bayesian optimization packages. Dragonfly was not employed in the two chemistry examples, due to an implementation incompatibility with using both constraints and the multi-objective optimization strategy required by the applications.
Analytical benchmarks
Here, we use eight analytical functions (four continuous and four discrete) to test the ability of Gryffin to perform sample-efficient optimization while satisfying a diverse set of user-defined constraints. More specifically, we consider the following four two-dimensional continuous surfaces, as implemented in the Olympus package51: Branin, Schwefel, Dejong, and Discrete Ackley (Figure 2). While Branin has three degenerate global minima, we apply constraints such that only one minimum is present

Figure 2. Constrained optimization benchmarks on analytical functions with continuous parameters. The upper row shows contour plots of the surfaces with constrained regions darkly shaded. Gray crosses show sample observation locations using the Gryffin (Genetic) strategy and purple stars denote the location(s) of unconstrained global optima. The bottom row show optimization traces for each strategy. Shaded regions around the solid trace represent 95% confidence intervals.
in the feasible region. In Schwefel, a highly unstructured constraint function where the global minimum is close to the boundary of the infeasible region. In Dejong, we use a set of constraints that result in a non-compact optimization domain where the global minimum cannot be reached, and there is an infinite number of feasible minima along the feasibility boundary. Discrete Ackley is a discretized version of the Ackley function, which is an example of an extremely rugged surface. The four, two-dimensional discrete surfaces considered are: Slope, Sphere, Michalewicz, and Camel (Figure 3). Each variable in these discrete surfaces is comprised of integer numbers from 0 to 20, for a design space of 441 options in total.

Figure 3. Constrained optimization benchmarks on analytical functions with discrete, ordered parameters. The upper row shows heatmaps of the discrete optimization domain. Shaded regions indicate infeasible regions, where constraints have been applied. The locations of the global optima are indicated by purple stars. Gray crosses show parameters locations that have been probed in a sample optimization run using Gryffin (Genetic) before the optimum being identified. The bottom row shows, as superimposed box-and-whisker and swarm plots, the distributions of the number of evaluations needed to identify the global optimum for each optimization strategy (numerical values can be found in Table S1).
Results of constrained optimization experiments on continuous surfaces are shown in Figure 2. These results were obtained by performing 100 repeated optimizations for each of the five strategies considered, while allowing a maximum of 100 objective function evaluations. Optimization performance is assessed using the distance between the best function value found at every iteration of the optimization campaign and the global optimum, a metric known as regret, . The regret after optimization iterations is
are the parameters associated with best objective value observed in the optimization campaign after iterations, sometimes referred to as the incumbent point, i.e. for a minimization problem , where is the current dataset of observations. are the parameters associated with the global optimum of the function. Sample-efficient algorithms should find parameters that return better (in this case lower) function values with fewer objective evaluations.
All optimization strategies tested obeyed the known constraints (Figure 2, top row). We observe that the combination of analytical function and user-defined constraint have great influence on the relative optimization performance of the considered strategies. On all functions, the performance of Gryffin was insensitive to the acquisition optimization strategy, with Gryffin (Adam) and Gryffin (Genetic) performing equally well. On smooth functions, such as Branin and Dejong, Dragonfly displayed strong performance, given that its Gaussian process surrogate model approximates these functions extremely well. In addition, Dragonfly appears to propose parameter points that are closer to previous observations than Gryffin does, showcasing a more exploitative character, which in this case is beneficial to achieve marginal gains in performance when in very close proximity to the optimum (see SI Sec. S.2.C for additional details). Although their performance is slightly worse than Dragonfly, Gryffin strategies still displayed improved performance over Random and Genetic on Branin, and comparable performance to Dragonfly on Dejong. Gryffin strategies showed improved performance compared to Dragonfly on Schwefel and DiscreteAckley. These observations are consistent with previous work29 where it was observed that, due to the different surrogate models used, Gryffin returned better performance on functions with discontinuous character, while Gaussian process-based approaches better performed on smooth surfaces. On Schwefel, our Genetic strategy also showed improved performance over that of Random and Dragonfly, comparable with that of Gryffin. Finally, note that in Figure 2 differences between strategies are exaggerated by the use of a logarithmic scale, used to highlight statistically significant differences. We also report the same results using a linear scale, which de-emphasizes significant yet marginal differences in regret values (e.g. between Dragonfly and Gryffin on the Branin function) in SI Fig. S2.
Results of constrained optimization experiments on discrete synthetic surfaces are shown in Figure 3. These results are also based on 100 repeated optimizations, each initialized with a different random seed. Optimizations were allowed to continue until the global optimum was found. As a measure of performance, the number of objective function evaluations required to identify the optimum was used. As such, a more efficient algorithm should identify the optimum with fewer function evaluations on average.
Here too, all strategies tested correctly obeyed each constraint function (Figure 3, top row), and Bayesian optimization algorithms (Gryffin and Dragonfly) outperformed Random and Genetic on all four benchmarks (Figure 3, bottom row). Random needed to evaluate about half of the feasible space before identifying the optimum. Genetic required significantly fewer evaluations, generally between a half and a third of those required by Random. On discrete surfaces, the approaches based on Gryffin and Dragonfly returned equal performance overall, with no considerable differences (Table S1). As it was observed for continuous surfaces, the performance of Gryffin (Adam) and Gryffin (Genetic) was equivalent.
| Slope (311) | Sphere (362) | Michalewicz (323) | Camel (347) | |
| Random | 157.3 ± 9.4 | 162.3 ± 9.7 | 167.8 ± 9.2 | 171.0 ± 10.8 |
| Genetic | 55.2 ± 2.7 | 61.5 ± 2.7 | 47.7 ± 2.4 | 92.9 ± 6.2 |
| Gryffin (Hill) | 12.7 ± 1.0 | 19.0 ± 0.8 | 18.4 ± 0.9 | 33.8 ± 1.6 |
| Gryffin (Genetic) | 12.4 ± 1.0 | 20.2 ± 0.8 | 18.7 ± 0.8 | 36.0 ± 2.6 |
| Dragonfly | 11.0 ± 0.1 | 13.6 ± 0.3 | 29.8 ± 1.2 | 39.0 ± 2.3 |
Table S1. Mean and standard error of the number of evaluations needed by each strategy to identify the global optimum of each constrained discrete surface tested. The integer in parentheses in the header is the number of feasible tiles for the surface after the constraint is applied, out of a total of input combinations.
Process-constrained optimization of o-xylenyl C₆₀ adducts synthesis
Compared to their inorganic counterparts, organic solar cells have the advantage of being flexible, lightweight and easily fabricated.52,53 Bulk heterojunction polymer-fullerene cells are an example of such devices, in which the photoactive layer is composed of a blend of polymeric donor material and fullerene derivative acceptor molecules.54 The fullerene acceptor is oftentimes functionalized to tune its optoelectronic properties. In particular, mono and bis o-xylenyl adducts of Buckminsterfullerene are acceptor molecules which have received much attention in this regard. On the other hand, higher-order adducts are avoided as they have a detrimental impact on the power conversion efficiencies of the resulting device.55 Therefore, synthetic protocols that provide accurate control over the degree of C₆₀ functionalization are of primary interests for the manufacturing of these organic photovoltaic devices.
In this example application of constrained Bayesian optimization, we consider the reaction of C₆₀ with an excess of sultine, the cyclic ester of a hydroxy sulfinic acid, to form first, second, and third order o-xylenyl adducts of Buckminsterfullerene (Figure 4a). This application is based on previous work by Walker et al. (35) who reported the optimization of this reaction with an automated, single-phase capillary-based flow reactor. Because this reaction is cascadic, a mixture of products is always present, with the relative amounts of each species depending primarily on reaction kinetics. The overall goal of the optimization is thus to tune reaction conditions such that the yield of first- and second-order adducts is maximized and reaches at least 90%, while the cost of reagents is minimized. We estimated reagents cost by considering the retail price listed by a chemical supplier (S.3.B). In effect, we derive a simple estimate of per-minute operation cost of the flow reactor, which is to be minimized as the second optimization objective.

Figure 4. Experimental setup and results of the process-constrained synthesis of -xylenyl C adducts. (a) Synthesis of -xylenyl C adducts. 1,4-dihydro-2,3-benzoxathiin 3-oxide (sultine) is converted to -quinodimethane (QDM) in situ, which then reacts with C by Diels-Alder cycloaddition to form the -xylenyl adducts. (b) Schematic of the single-phase capillary-based flow reactor (as reported by Walker et al.35), along with the optimization parameters, constraints, and objectives. The C and sultine flow rates are modulated by syringe pumps, and the reaction temperature is controlled by a solid state heater. Online HPLC and absorption spectroscopy is used for analysis. (c) Results of the constrained optimization experiments. Plots show the mean and 95% confidence interval of the best objective values found after varying numbers of experiments, for each optimization algorithm studied. The background color indicates the desirability of the objective values, with grey being less, and white more desirable. For the first objective (left-hand side), the grey region below the value of 0.9 indicates values for the objective that do not satisfy the optimization goal that was set.
The controllable reaction conditions are the temperature (), the flow rate of C₆₀ (), and the flow rate of sultine (), which determine the chemical composition of the reaction mixture and are regulated by syringe pumps (Figure 4b). is allowed to be set anywhere between 100 and 150°C, and flow rates can be varied between 0 and 200 L/min. However, the values of the flow rates are constrained. First, the total flow rate cannot exceed 310 L/min, or be below 10 L/min. Second, cannot be more than twice , and vice-versa cannot be more than twice . More formally, the inequality constraints can be defined as , and .
The relative concentrations of each adduct—, , and for the mono, bis, and tris adduct, respectively—are measured via online high performance liquid chromatography (HPLC) and absorption spectroscopy. Following from the above discussion, we would like to maximize the yield of and , which are the adducts with desirable optoelectronic properties. However, we would also like to reduce the overall cost of the raw materials. These multiple goals are captured via the use of Chimera as a hierarchical scalarizing function for multi-objective optimization.31 Specifically, we set the first objective as the maximization of , with a minimum target goal of 0.9, and the minimization of reagents cost as the secondary goal. Effectively, this setup corresponds to the minimization of cost under the constraint that .
To perform numerous repeated optimizations with different algorithms, as well as collect associated statistics, we constructed a deep learning model to simulate the above-described experiment. In particular, we trained a Bayesian neural network based on the data provided by Walker et al.,35 which learns to map reaction conditions to a distribution of experimental outcomes (SI Sec. S.3.A). The measurement is thus stochastic, as expected experimentally.
This emulator takes , , and as input, and returns mole fractions of the un- (), singly- (), doubly- (), and triply-functionalized () C. The model displayed excellent interpolation performance across the parameter space for each adduct type (Pearson coefficient of 0.93 − 0.96 on the test sets). This enabled us to perform many repeated optimizations thanks to rapid and accurate simulated experiments.
Results of the constrained optimization experiments are shown in Figure 4c. Optimization traces show the objective values associated with the best scalarized merit value. The constrained Gryffin strategies obeyed all flow rate constraints defined. All strategies rapidly identified reaction conditions producing high yields. Upon satisfying the first objective, Chimera guided the optimization algorithms towards lowering the cost of the reaction. Gryffin achieved cheaper protocols faster than the other strategies tested. In SI Sec. S.3.B we examine the best reactions conditions identified by each optimization strategy after 100 experiments. We find that for the majority of cases, strategies decreased the C flow rate (the more expensive reagent) to minimize the cost of the experiment, while simultaneously decreasing the sultine flow rate to maintain a stoichiometric ratio close to one and preserve the high ( combined mole fraction) yield of and adducts. In principle, the yield is allowed to degrade with an accompanying decrease (im-
provement) in cost. However, we did not see the trade-off between yield and cost being required within the experimental budget of 100 experiments. In this case study we used GPyOpt, as opposed to Dragonfly, as a representative of an established Bayesian optimization algorithm, because its implementation was compatible with the requirements of this specific scenario. That is, the presence of known constraints and the use of an external scalarizing function for multi-objective optimization. Use of Chimera as an external scalarizing function requires updating the entire optimization history at each iteration. Thus, the optimization library must be used via an ask-tell interface. Although Dragonfly does have such an interface, to the best of our knowledge it does not yet support constrained and multi-objective optimizations with external scalarizing functions. In this instance, GPyOpt with expected improvement as the acquisition function performed similarly to Genetic and Random on average.
Design of redox-active materials for flow batteries with synthetic accessibility constraints
Long-duration, stationary energy storage devices are needed to handle the rapid growth in intermittent energy sources.57 Toward this goal, redox flow batteries offer a potentially promising solution.58–62 Second-generation non-aqueous redox flow batteries are based on organic solvent as opposed to water, which enables a much larger electrochemical window and higher energy density, the potential to increase the working temperature window, as well as the use of cheap, earth abundant redox-active materials.63 Nevertheless, the multiobjective design of redox-active materials poses a significant challenge in materials science. Recently, the anolyte redox material 2,1,3-benzothiadiazole was shown to have low redox potential, high stability and promising electrochemical cycling performance.64–66 Furthermore, derivatization of benzothiadiazole enabled self-reporting of battery health by fluorescence emission.67
In this application we demonstrate our constrained optimization approach for the multi-objective design of retro-synthetically accessible redoxmer molecules. We utilize a previously reported dataset that comprises 1408 benzothiadiazole derivatives (Figure 5a) for which the reduction potential , solvation free energy , and maximum absorption wavelength were computed with DFT.68 This example application thus simulates a DFT-based computational screen69–71 that aims to identify redoxmer candidates with self-reporting features and a high probability of synthetic accessibility.

Figure 5. Optimization setup and results for the design of redox-active materials. (a) Markush structure of the benzothiadiazole scaffold and all substituents considered. The entire design space consists of 1408 candidates ( options). (b) Synthetic constraints applied to the optimization. The was used to score synthesizability. The histogram shows the distribution of synthesizability scores for all 1408 candidates. We constrain the optimization to those candidates with an . (c) Objectives of the molecular optimization. (d) Results of the constrained optimization experiments. Grey shaded regions indicate objective values failing to achieve the desired objectives. Traces depict the objective values corresponding to the best achieved merit at each iteration, where error bars represent 95% confidence intervals.
To impose synthetic accessibility constraints we used RAscore,56 a recently-reported synthetic accessibility score based on the computer-aided synthesis planner AiZynthFinder.72 RAscore predicts the probability of AiZynthFinder being able to identify a synthetic route for a target organic molecule. While other measures of synthetic accessibility are available,34,73–75 RAscore was chosen for its performance and intuitive interpretation. In our experiments, we constrained the optimization to candidates with RAscore (Figure 5b, additional details in SI Sec. S.4.B). This synthetic accessibility constraint reduces the design space of feasible candidates to a total of 959 molecules.
We aimed at optimizing three objectives concurrently: the absorption wavelength , the reduction potential , and the solvation free energy of the candidates (Figure 5c). Specifically, we aimed at identifying molecules that would (i) absorb in the 350–400 nm range, (ii) improve upon the reduction potential of the base scaffold (2.04 V against a Li/Li reference electrode; SI Sec. S.4.A), and (iii) provide the lowest possible solvation free energy, here used as a proxy for solubility. The hierarchical scalarizing function Chimera31 was used to guide the optimization algorithms toward achieving these desired properties.
Results of the constrained optimization experiments are displayed in Figure 5d. Each optimization strategy was given a budget of 100 molecules to be tested; the experiments were repeated 100 times and initialized with different random seeds. Optimization traces show the values of , , and associated with the best molecule identified among those tested. In these tests, the dynamic version of Gryffin was used.30 This approach can take advantage of physicochemical descriptors in the search for optimal molecules. In this case, Gryffin was provided with several descriptors for each R group in the molecule: number of heavy atoms, number of hetero atoms, molecular weight, geometric diameter, polar surface area, polarizability, fraction of sp carbons (SI Sec. S.4.C).76
Constrained Gryffin avoided redoxmer candidates predicted to be retro-synthetically inaccessible. All optimization strategies rapidly identified candidates with between 350 and 400 nm, and whose is lower than that of the starting scaffold. However, Gryffin strategies managed to identify candidates with lower faster than Random and Genetic. Consistent with previous tests, we did not observe a statistically different performance between Gryffin (Hill) and Gryffin (Genetic). Overall, Gryffin (Hill) and Gryffin (Genetic) identified molecules with better , , and properties than Random or Genetic after probing 100 molecules. Furthermore, within this budget, Gryffin identified molecules with better properties more efficiently than the competing strategies tested. Without the aid of physicochemical descriptors, Gryffin’s performance deteriorated, as expected,30 yet it was still superior than that of Random and Genetic (SI Fig. S8).
Conclusion
In this work, we extended the capabilities of Gryffin to handle a priori known, hard constraints on parameter domain, a pragmatic requirement for the development of autonomous research platforms in chemistry. Known constraints constitute an important class of restrictions placed on optimization domains, and may reflect physical constraints or limitations in laboratory equipment capabilities. In addition, known constraints may provide a straightforward avenue to inject prior knowledge or intuition into a chemistry optimization task. In Gryffin, we allow the user to define arbitrary known constraints via a flexible and intuitive Python interface. The constraints are then satisfied by constraining the optimization of its acquisition function. In all our benchmarks, Gryffin obeyed the (sometimes complex) constraints defined, showed superior performance to more traditional search strategies based on random search and evolutionary algorithms, and was competitive to state-of-the-art Bayesian optimization approaches. Finally, we demonstrated the practical utility of handling known constraints with Gryffin in two research scenarios relevant to chemistry. In the first, we demonstrated
how to perform an efficient optimization for the synthesis of o-xylenyl adducts of Buckminsterfullerene while subjecting the experimental protocol to process constraints. In the second, we showed how known constraints may be used to incorporate synthetic accessibility considerations in the design of redox active materials for non-aqueous flow batteries. It is our hope that simple, flexible, and scalable software tools for model-based optimization over constrained parameter spaces will enhance the applicability of data-driven optimization in chemistry and material science, and will contribute to the operationalization of self-driving laboratories.
Data availability
An open-source implementation of Gryffin with known constraints is available on GitHub at https://github.com/aspuru-guzik-group/gryffin, under an Apache 2.0 license. The data and scripts used to run the experiments and produce the plots in this paper are also available on GitHub at https://github.com/aspuru-guzik-group/gryffin-known-constraints.
Acknowledgments
The authors thank Dr. Martin Seifrid, Marta Skreta, Ben Macleod, Fraser Parlane, and Michael Elliott for valuable discussions. R.J.H. gratefully acknowledges the Natural Sciences and Engineering Research Council of Canada (NSERC) for provision of the Postgraduate Scholarships-Doctoral Program (PGSD3-534584-2019). M.A. was supported by a Postdoctoral Fellowship of the Vector Institute. A.A.-G. acknowledges support from the Canada 150 Research Chairs program and CIFAR, as well as the generous support of Anders G. Frös eth. This work relates to the Department of Navy award (N00014-18-SB-001) issued by the office of Naval Research. The United States Government has a royalty-free license throughout the world in all copyrightable material contained herein. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the Office of Naval Research. Computations reported in this work were performed on the computing clusters of the Vector Institute and on the Niagara supercomputer at the SciNet HPC Consortium.77,78 Resources used in preparing this research were provided, in part, by the Province of Ontario, the Government of Canada through CIFAR, and companies sponsoring the Vector Institute. SciNet is funded by the Canada Foundation for Innovation, the Government of Ontario, Ontario Research Fund - Research Excellence, and by the University of Toronto.
Conflicts of interest
A.A.-G is the Chief Visionary Officer and founding member of Kebotix, Inc.
Constrained optimization of the acquisition function
Minima of the acquisition function, (main text Eq. (1)), determine the parameter space point to be proposed for objective function measurement, thus, its optimization is an important subroutine in Bayesian optimization. Acquisition function optimization in Gryffin consists of two main steps. First, a set of initial parameter space points are drawn from the domain using rejection sampling according to constraint function producing the set of initial samples , where ; s.t. feasible. These samples are then refined by one of several optimization strategies, returning a set of refined proposals . In the following subsections, we detail the each acquisition function optimization strategy and compare their computational scaling.
A Adam/Hill optimizer
For continuous parameters, the Adam optimizer[1] is used to optimize the acquisition function, with built in checks for whether the optimized samples obey the defined known constraints. For discrete and categorical parameter types, we use a “hill-climbing” strategy, in which each initial sample is randomly updated for a predefined number of iterations, with the candidate that has the best merit maintained and eventually returned. Algorithm 1 shows this strategy’s basic pseudocode.
B Genetic optimizer
Our genetic algorithm implementation is based on the DEAP library[2, 3] and consists of crossover (), mutation () and tournament selection () operations. The size of the initial population is determined by the number of initial random samples, . At each generation, offspring are chosen using tournament-style selection (tournament size of 3); elitism is applied to 5% of the population. Each parent in the resulting population is given a chance to mate (using either uniform or two-point crossover, depending on the dimensionality of the parameter space, with a crossover probability of 0.5), as well as a chance to mutate. We employ a custom mutation operator, which can handle continuous, discrete and categorical parameter types. The mutation probability is set to 0.4, with the probability of mutating each individual parameter set to 0.2. The maximum number of generations is set to 10, but the search is terminated early if the diversity of the population reaches a specified threshold. Specifically, if the population is concentrated in a small subvolume of parameter space, where each attribute does not span more than 10% of the allowed range, then the search is terminated. consists of different mutations for each parameter type. For continuous parameters, a perturbation is sampled from a Gaussian distribution with scale 0.1, i.e. , . The same is true for discrete parameter types, except is first rounded to the nearest integer value. For categorical parameters, the mutated offspring are sampled randomly from the set of options for that parameter.
In order to constrain the genetic optimization procedure according to the known constraint function, a subroutine is used to project infeasible population offspring onto the feasibility boundary using a binary search procedure. After each application of or to parent , the feasibility of each resulting offspring is tested with , where is the user-defined constraints function. If returns False, i.e. the constraint is not satisfied and is in the infeasible region, the following procedure is employed project onto the boundary of the feasible region. For
Algorithm 1: Constrained acquisition function optimization with Adam/Hill climbing
Data: initial samples $P_{\mathrm{init}}$, acquisition function $\alpha(\cdot)$, constraint function $c(\cdot)$, max iterations $i_{\mathrm{max}}$
Result: refined samples $P_{\mathrm{ref}}$
$P_{\mathrm{ref}} \gets \varnothing$;
for $x_n$ in $P_{\mathrm{init}}$ do
for $i$ in $i_{\mathrm{max}}$ do
$x_n \gets \operatorname{AdamStep}(x_n^{\mathrm{cont}})$; /* continuous optimization step */
$x_n \gets \operatorname{HillStep}(x_n^{\mathrm{cat}})$; /* categorical optimization step */
$x_n \gets \operatorname{HillStep}(x_n^{\mathrm{disc}})$; /* discrete optimization step */
if $c(x_n) \not\to$ infeasible then
$P_{\mathrm{ref}} \mathrel{+ \gets} x_n^{i-1}$; /* add feasible sample from previous iteration to refined samples */
else
$P_{\mathrm{ref}} \mathrel{+ \gets} x_n$; /* add current sample to refined samples */
end
end
end
Function $\operatorname{HillStep}(x_n)$:
$y_{\mathrm{best}} \gets \alpha(x_n)$;
for $z_d$ in $x_n^{\mathrm{cat}}$ do
$z_d^{\mathrm{new}} \gets z_d^{\mathrm{new}} \sim S_d$; /* sample from set of categorical options $S_d$ */
$x_n^{\mathrm{new}}$ updated with $z_d^{\mathrm{new}}$;
$y_{\mathrm{new}} \gets \alpha(x_n^{\mathrm{new}})$;
if $y_{\mathrm{new}} < y_{\mathrm{best}}$ then
$y_{\mathrm{best}} \gets y_{\mathrm{new}}$;
$x_n \gets x_n^{\mathrm{new}}$;
end
end
return $x_n$
continuous parameters, we consider the midpoint of the line segment bounded by and . If is feasible, then the parent is set to the midpoint; if it is infeasible, the offspring is set to the midpoint. This process is repeated until the distance between and is below a tolerance threshold. As a default, we use the criterion to terminate the search, i.e., when we are guaranteed to be within a 1% of relative distance from the feasibility boundary in all parameter dimensions. Throughout this procedure, is guaranteed to always be feasible while is always infeasible. Hence, once the search is terminated, the is set equal to and is returned. For discrete parameters, the same process is performed but the search is terminated when the closest point to the feasibility boundary is identified. Categorical parameters of infeasible offspring are instead simply reset to those of the feasible parent. When mixed continuous, discrete, and categorical parameters are present, we (i) set the categorical parameters of to those of its parent, to obtain . If is feasible, we return it, otherwise we (ii) perform the binary search procedure described above for the continuous and/or discrete parameters and obtain . Then, we (iii) reset the categorical parameters of to their original values in , obtaining . If is feasible, we return it, otherwise we return . Given this approach relies on binary searches, it has a favorable logarithmic scaling and adds little overhead to the optimization of the acquisition function.
Algorithm 2 shows the basic pseudocode for our implementation. We show pseudocode for our custom mutation function (referred to as Mutation), but we omit definition of our subroutine which projects infeasible points to the feasible boundary for brevity. The function is referred to in Algorithm 2 by ProjectToFeasible. We direct the interested reader to the source code of Gryffin for more details (https://github.com/aspuru-guzik-group/gryffin).
Empirical time complexity of the Adam and genetic acquisition optimizers
Computational scaling experiments were carried out to compare the relative cost of the Adam and Genetic acquisition optimization strategies. The time taken to optimize the acquisition function was measured with increasing number of past observations while keeping the problem dimensionality constant, and with increasing number of parameter dimensions while keeping the number of observations constant. All parameters were continuous and in . Tests were performed with and without optimization constraints. When relevant, the constraint used was , where is dimension of the parameter space and are the individual elements of the -dimensional parameter vector. That is, we assumed half of the optimization domain to be infeasible. Results of these tests are shown in Figure S1. Each datapoint was obtained as the average elapsed time for 60 repeated acquisition function optimizations Algorithm 2: Constrained acquisition function optimization with genetic algorithm

Figure S1. Empirical measurements of the time required by Gryffin to optimize its acquisition function. The Adam and Genetic optimization strategies were compared at varying number of past observations and optimization domain dimensions, with and without the presence of constraints.
Data: , , , , crossover operator with prob , custom mutation operator with prob and independent prob , tournament selection operator Result: refined population ; ; for in do ; /* tournament selection of offspring from population / for in mating pairs do if crossover sample then ; ; ; end end for in do if mutant sample then ; ; end end ; / evaluate the fitness of offspring / ; / add elites to the offspring / ; / set population as the offspring for next generation / end ; Function Mutation(, ): for in do if independent mutation sample then if is continuous then ; / sample perturbation from unit Gaussian, i.e. / else if is discrete then ; / sample perturbation from unit Gaussian, i.e. / else if is categorical then ; / sample from set of categorical options, i.e. */ end end end return
(20 for each ). No appreciable overhead was observed when constraints were present. When keeping the dimensionality constant, the Genetic strategy showed favourable scaling compared to Adam, being roughly 20% as expensive as Adam after 100 observations. Similar results were observed in the experiments with a constant number of observations, where the optimization cost with the Genetic strategy took, on average, less time than Adam.
Constrained optimization of analytical functions
In this section, we provide more details about the constrained analytical functions used for testing Gryffin’s implementation and performance.
A Benchmark functions and constraints used
Our synthetic benchmark experiments consisted of four continuous and four discrete surfaces in two dimensions. The original implementations of the surfaces can be accessed via the Olympus package.4 We used Python wrappers for each of the surfaces to implement constraints on the parameter space. While the full implementation is available on GitHub, code snippets are provided here as well to show a user may implement different constraint functions to be used by Gryffin. These constraint functions, called is_feasible(), expect a dictionary, params, containing the parameter values and evaluate their feasibility; True is returned for feasible, False for infeasible. Note that, while here we report the definition of the analytical functions and the input domain typically used, Olympus normalizes the input domain to the unit hypercube for ease of use (i.e. all analytical function can be expected to be supported in ). As such, the constraint functions below assume each parameter to be normalized between zero and one.
Branin This surface is evaluated on the domain , , and has the form , with , , , . There are three degenerate global minima at , and . Two of these minima were removed by the constraints defined below.
def is_feasible(params):
x0 = params['x0']
x1 = params['x1']
y0 = (x0-0.12389382)**2 + (x1-0.81833333)**2
y1 = (x0-0.961652)**2 + (x1-0.165)**2
if y0 < 0.2**2 or y1 < 0.35**2:
return False
else:
return True
Schwefel: This surface is a complex optimization problem with many local minima. In dimensions, it is evaluated on the hypercube and is described by the expression . The surface has a global optima at .
def is_feasible(params):
np.random.seed(42)
N = 20
centers = [np.random.uniform(low=0.0, high=1.0, size=2) for i in range(N)]
radii = [np.random.uniform(low=0.05, high=0.15, size=1) for i in range(N)]
x0 = params['x0']
x1 = params['x1']
Xi = np.array([x0, x1])
for c, r in zip(centers, radii):
if np.linalg.norm(c - Xi) < r:
return False
return True
Dejong: This surface generalizes a parabola to higher dimensions. It is convex and unimodal an evaluated on the -dimensional hypercube , . In two dimensions, this surface has a global minimum at with .
def is_feasible(params):
x0 = params['x0']
x1 = params['x1']
y = (x0-0.5)**2 + (x1-0.5)**2
if np.abs(x0-x1) < 0.1:
return False
if 0.05 < y < 0.15:
return False
else:
return True
Discrete Ackley: This surface is the discrete analogue to the Ackley function.
def is_feasible(self, params):
x0 = params['x0']
x1 = params['x1']
if np.logical_or(0.41 < x0 < 0.46, 0.54 < x0 < 0.59):
return False
if np.logical_or(0.34 < x1 < 0.41, 0.59 < x1 < 0.66):
return False
return True
Slope This surface generalizes a plane to discrete domains. The surface’s values linearly increase along each dimension. Constraints form three area elements defined by circles with increasing radii.
def is_feasible(params):
x0 = params['x0']
x1 = params['x1']
y = x0**2 + x1**2
if 5 < y < 25:
return False
if 70 < y < 110:
return False
if 200 < y < 300:
return False
return True
Sphere: This surfaces generalizes a parabola to discrete spaces. It features a degenerate global minimum if the number of options along at least one dimension is even,and a well-defined minimum if the number of options for all dimensions is odd. Constraints remove the same two integer inputs, 9 and 11, from consideration in both dimensions.
def is_feasible(params):
x0 = params['x0']
x1 = params['x1']
if x0 in [9, 11]:
return False
if x1 in [9, 11]:
return False
return True
Michalewicz: This surface features a sharper well where the global optimum is located. The number of pseudo-local minima scales factorially with the number of dimensions. Constraints consist of the area element between a circle centred around with radii and , as well as two rectangular areas.
def is_feasible(params):
x0 = params['x0']
x1 = params['x1']
y = ((x0-14))**2 + (x1-10)**2
if 5 < y < 30:
return False
if 12.5 < x0 < 15.5:
if x1 < 5.5:
return False
if 8.5 < x1 < 11.5:
if x0 < 9.5:
return False
return True
Camel: This surface features a degenerate and pseudo-disconnected global minimum. In 2-dimensions, it has global minima at and . Constraints are generated by randomly sampling 100 infeasible locations and excluding the optima.
def is_feasible(params):
# choose infeasible points at random
num_opts = 21
options = [i for i in range(0,num_opts,1)]
num_infeas = 100
np.random.seed(42)
infeas_arrays = np.array([np.random.choice(options, size=num_infeas,replace=True),
np.random.choice(options, size=num_infeas, replace=True)]).T
infeas_tuples = [tuple(x) for x in infeas_arrays]
# always exclude the other minima
infeas_tuples.append((7, 11))
infeas_tuples.append((7, 15))
infeas_tuples.append((13, 5))
x0 = params['x0']
x1 = params['x1']
sample_tuple = (x0, x1)
if sample_tuple in infeas_tuples:
return False
return True
Results of the constrained optimization benchmarks
Figure S2 shows the results of the continuous optimization benchmarks where regret is displayed on a linear scale, which highlights how performance differences between Gryffin and Dragonfly on Branin and Dejong are marginal. Table S1 reports the optimization performance achieved by the strategies tested on the discrete surfaces.

Figure S2. Constrained optimization benchmarks on analytical functions with continuous parameters. The upper row shows contour plots of the surfaces with constrained regions darkly shaded. Gray crosses show sample observation locations and purple stars denote the location(s) of unconstrained global optima. The bottom row show optimization traces for each strategy. Shaded regions around the solid trace represent 95% confidence intervals.
Empirical comparison of sampling in Gryffin and Dragonfly
In this section, we examine the sampling tendencies of Gryffin and Dragonfly on the constrained, continuous analytical benchmark functions. Specifically, we compare the tendency of each algorithm to suggest parameter point which are in close proximity to past observations. The first row of Figure S3 shows the minimum Euclidean distance between any two parameter points selected during an optimization campaign by each planner (boxplots show this metric over the 100 independently seeded runs). Dragonfly is able to recommend parameter points which are significantly closer to past observations than Gryffin (Adam) or Gryffin (Genetic). The greater exploitative tendency of Dragonfly is beneficial on smooth continuous surfaces as it allows for marginal improvement on regret values (main text Fig. 2). Gryffin strategies, on the other hand, contain a self-avoidance routine which biases the search away from past observations in an attempt to avoid redundant measurements. For practical experimental applications in chemistry, the resolution on input parameters is determined by precision of laboratory equipment and/or human error, and should be considered before commencing the experiment. The bottom two rows show the location of observations for Gryffin (Adam) and Dragonfly strategies around the minima of each surface. Visually, it is apparent that Dragonfly has a greater tendency to recommend parameter points which are considerably closer to past observations than does Gryffin.

Figure S3. Empirical evaluation of the sampling behaviour of Gryffin and Dragonfly on constrained continuous surfaces. The first row shows the minimum Euclidean distance between any two parameter points selected by the each optimization strategy. For each continuous constrained surface, Dragonfly allows for recommendation of parameter points which are significantly closer to past observations than does Gryffin (Adam) or Gryffin (Genetic). The second and third rows shows the location of Gryffin (Adam) and Dragonfly samples (grey crosses) in the vicinity of the surface minima (pink star).
Process-constrained optimization of o-xylenyl C60 adducts synthesis
Details of the Bayesian neural network experiment emulator
To emulate the process-constrained synthesis of C adducts, we trained a Bayesian neural network (BNN) to return stochastic outcomes based on a set of controllable parameters. The trained emulator takes a vector containing the experimental conditions (, , and ) and predicts the mole fractions of the products, the un- ([X]), singly- ([X]), doubly- ([X]), and triply-functionalized ([X]) C. The BNN consisted of 3 densely-connected variational layers with reparameterized Monte Carlo estimators[5] and was implemented in PyTorch.[6] Each hidden layer had 64 nodes and featured a ReLU non-linearity, while the output layer had 4 nodes, one for each of the aforementioned C adducts. The output layer used the softmax activation function, which normalizes the outputs to a probability distribution where . Network weights and biases followed Gaussian distributions whose priors
were set to have zero mean and unit standard deviation, i.e. , . The network was trained using variational Bayesian inference. The ELBO loss was minimized using the Adam optimizer3, and resulting gradients were used to adjust the weights and biases of the network’s parameter distributions during training. Figure S4 shows parity plots of our model’s predictions against the true adduct mole fractions, where 500 experimental measurements were used for training and 100 for testing. The BNN displayed excellent interpolation performance across the parameter space for each adduct type, with Pearson correlation coefficients on the test sets between 0.93 and 0.96.

Figure S4. Parity plots for each mole fraction predicted by our Bayesian neural network emulator, averaged over 50 network parameter samples. Horizontal axes plot the true mole fraction, and vertical axes plot the predicted mole fraction. The dashed diagonal line indicates perfect agreement. The Pearson correlation coefficient and root-mean-square error is given for the training set (in parentheses) and test set for each mole fraction target. Train (test) set points are shown in blue (orange).
Estimating the experimental cost
The overall goal of the process-constrained optimization of -xylenyl adducts synthesis is to adjust reaction conditions such that the combined yield of first- and second-order adducts is maximized and reaches at least 90%, while the cost of reagents is minimized. In order to estimate the cost of the experiments, we considered the listed price of sultine and by the chemical supplier Sigma-Aldrich. The cost of dibromo--xylene cost on Sigma Aldrich was $191 for 100 g. The cost of was $422 for 5g. In the experiments by Walker et al.[7], the concentration of sultine was 1.4 mg/mL, while the concentration of was 2.0 mg/mL. The amount of used in the experiments will therefore have much greater influence on overall experiment cost than sultine. Our optimization experiments target the adjustment of volume flow rates of each of these chemicals. Thus, we seek a measure of per-unit-time operation cost to be minimized. Converting to per-litre costs, we have 2.674 $/L for sultine, and 168.8 $/L for . Finally, from the flow rates used in the experiment, and (with units of L/min), we obtain an estimate of per-minute operation cost of the flow-reactor from Walker et al.[7] with units of $/min as
Figure S5 shows the mean and 95% confidence interval for parameter values corresponding to the best observed objective values achieved by each optimization strategy. We report the flow rate in terms of mass per unit time (mass flow rate) to account for the difference in concentrations of each reagent and compare the rates on an equal footing. To improve upon our secondary cost objective, each strategy decreases the parameter, as it’s value dominates the cost in Eq. (3). Decrease in is however accompanied by a decrease in to preserve the high () mol fractions of the and adducts. For most optimization runs, the temperature of the best performing reactions varies between 116 and 130 °C.

Figure S5. Mean and 95% confidence interval for parameter values corresponding to the best objective values found by each optimization strategy at each iteration of the optimization campaign. and sultine flow rates are both shown with units of g/min.
Figure S6 shows distributions of values for the best reaction conditions achieved by each optimization strategy in units of g/min. For each strategy, we note that this distribution favours positive values, meaning that, in the majority of the best achieved reaction conditions, the mass flow rate of was greater than that of sultine. Crucially, the Gryffin strategies, which exhibited the best optimization performance on this application, achieved narrower distributions around than other strategies.

Figure S6. Kernel density estimates show the distribution of for the best reactions conditions achieved by each optimization strategy in units of . Each distribution is comprised of 100 such values, one for each independently seeded optimization. Positive values indicate that the best achieved reaction conditions had .
Design of redox-active materials for flow batteries with synthetic accessibility constraints
Computation of reduction potential tolerance
To set the reduction potential () upon which we would like to improve, and which is used as an absolute tolerance in Chimera[8], we computed for the base scaffold molecule H-AcBzC6[9]. We computed with the same computational protocol used by Agarwal et al.[9]. The DFT calculation was performed using Gaussian 16[10] at the wb97xd/6-31+G-(d,p)[11, 12] level of theory. Optimized neutral and anionic geometries were subject to frequency calculations to compute the free energies. The SMD continuum model[13] was used with acetonitrile as the solvent. The reduction potential was calculated using Eq. (1) in Agarwal et al.[9],
where , is the number of electrons added to the neutral molecules (), is Faraday’s constant in eV, and 1.24 is a constant subtracted to convert the Gibbs free energy change to reduction potential (with Li/Li+ reference electrode). The for H-AcBzC6 was computed to be 2.038372 V. Of the 1408 functional derivatives subject to computation by Agarwal et al.[9], only 243 had better (lower) .
Prediction of the synthetic accessibility of redoxmer candidate molecules
As a constraint on the redoxmer candidates space, we enforce a retrosynthetic accessibility threshold below which the candidate is considered infeasible. The goal was to have an indication of synthetic accessibility that could be used to constrain the search space to candidates that likely to be synthesizable in practice.
Figure S7 shows the distributions of different synthetic accessibility scores for the set of 1408 redoxmer candidates considered in this application. Specifically, it includes the [14] predicted by an XGBoost classifier (XGB) and a neural network (NN), the fragment-based synthetic accessibility score [15], and the synthetic Bayesian classifier ()[16]. The is a recently reported synthetic accessibility score that tries to capture the probability of AiZynthFinder being able to identify a synthetic route for the molecule being evaluated.[14] AiZynthFinder is a retrosynthetic planning tool that can generate synthetic routes for organic molecules.[17] Hence, an of 1 indicates a synthetic path to the desired molecule is likely to exist, while a score of 0 indicates that finding a synthetic path is likely to be challenging and potentially impossible. For the purpose of our constrained optimization experiments, we decided to use the based on a NN model given its reported performance[14] and intuitive interpretation.

Figure S7. Histograms showing the distributions of four synthetic accessibility scores computed for the 1408 redoxmer candidates.
Generation of descriptors for benzothiadiazole scaffold substituents
In this example application of constrained Bayesian optimization, we employed the Dynamic version of Gryffin for combinatorial optimization,[18] which can take advantage of physicochemical descriptors in the search for optimal molecules. Specifically, we provided Gryffin with a total of seven simple descriptors associated with each of the four substituent groups considered ( in Figure 5a). The physicochemical descriptors were computed with the Mordred Python package.[19] As summarized in Table S2, the following descriptors were considered: the number of hetero atoms (nHetero), molecular weight (MW), topological polar surface area (TopoPSA), number of heavy atoms (nHeavyAtom), atomic polarizability (apol), fraction of sp hybridized carbons (FCSP3), and geometric diameter (Diameter). All seven descriptors were used for substituent groups , but only four of them are used for . We eliminate apol, FCSP3 and Diameter from consideration because they each have equal value for both substituent options, and therefore are not informative. Table S2 summarizes the Pearson correlation of each descriptor with each objective value over the entire set of 1408 molecules. N/A entries show the cases where the descriptor is omitted for the substituent. In addition, Table S2 reports the Pearson correlations between the descriptors for all four R-groups (, , , and ) and each optimization objective (, , and ). Table S3 reports instead the pairwise correlation between each descriptor, averaged over all R-groups.
| Mordred name | ||||||||||||
| nHetero | 0.17 | 0.13 | 0.12 | 0.19 | 0.22 | 0.27 | 0.26 | 0.35 | 0.62 | 0.24 | 0.22 | -0.12 |
| MW | 0.17 | 0.06 | 0.05 | 0.15 | 0.22 | 0.21 | 0.20 | 0.19 | 0.62 | 0.23 | 0.21 | -0.13 |
| TopoPSA | -0.17 | -0.12 | -0.11 | -0.14 | -0.22 | 0.13 | 0.11 | 0.30 | -0.62 | 0.00 | 0.01 | -0.22 |
| nHeavyAtom | 0.17 | 0.09 | 0.07 | 0.20 | 0.22 | 0.22 | 0.21 | 0.22 | 0.62 | 0.22 | 0.20 | -0.21 |
| apol | -0.17 | -0.25 | -0.31 | -0.14 | -0.22 | -0.26 | -0.27 | -0.16 | -0.62 | -0.06 | -0.04 | -0.41 |
| FCSP3 | N/A | -0.11 | -0.06 | -0.04 | N/A | -0.31 | -0.32 | -0.36 | N/A | 0.13 | 0.14 | 0.02 |
| Diameter | N/A | 0.02 | -0.04 | 0.17 | N/A | 0.16 | 0.16 | 0.23 | N/A | 0.14 | 0.12 | -0.29 |
Table S2. Mordred descriptors used to describe R-groups for the battery application optimization. The right most three columns show the Pearson correlation between each descriptor and each optimization objective for the 1408 redoxmer candidates considered. The correlations for each of the four R groups are comma separated, i.e. , , , . The largest correlation for each objective and R-group is bolded. N/A entries indicate that this descriptor was not considered for this particular R group. For the group, we do not consider apol, FCSP3 and Diameter since their values are the same for both options and therefore provide no additional information.
| nHetero | MW | TopoPSA | nHeavyAtom | apol | FCSP3 | Diameter | |
| nHetero | 1.00 | 0.92 | 0.01 | 0.91 | 0.2 | 0.61 | |
| MW | 0.92 | 1.00 | 0.93 | 0.24 | 0.29 | 0.71 | |
| TopoPSA | 0.01 | 1.00 | 0.03 | ||||
| nHeavyAtom | 0.91 | 0.93 | 1.00 | 0.32 | 0.35 | 0.86 | |
| apol | 0.24 | 0.03 | 0.32 | 1.00 | 0.47 | 0.62 | |
| FCSP3 | 0.2 | 0.29 | 0.35 | 0.47 | 1.00 | 0.32 | |
| Diameter | 0.61 | 0.71 | 0.86 | 0.62 | 0.32 | 1.00 |
Table S3. Pairwise Pearson correlations between Mordred descriptors used to describe the R-groups of the redoxmer candidates.
Additional optimization experiments
In addition to Gryffin optimizations taking advantage of physicochemical descriptors (Dynamic Gryffin), we also carried out optimizations without this additional information using Naive Gryffin. Figure S8 shows the optimization performance of all strategies tested, including the latter. The results show how the use of descriptors provide an edge to Gryffin to achieve superior performance to all other strategies. Regardless, Naive Gryffin still outperforms model-free optimization strategies Random and Genetic. All these optimizations were constrained to molecules with high synthetic accessibility scores, as described above.
Figure S8. Results of the constrained optimization experiments for the design of redox-active flow battery materials. Grey shaded regions indicate objective values failing to achieve the desired objectives. Traces depict the objective values corresponding to the best achieved merit at each iteration, where error bars represent 95% confidence intervals.
References
References
- [1]Diederik P. Kingma and Jimmy Ba. Adam: A Method for Stochastic Optimization. arXiv:1412.6980 [cs], January 2017.arxiv.org/abs/1412.6980
- [2]Félix-Antoine Fortin, François-Michel De Rainville, Marc-André Gardner, Marc Parizeau, and Christian Gagné. DEAP: Evolutionary algorithms made easy. Journal of Machine Learning Research, 13:2171–2175, 2012.
- [3]François-Michel De Rainville, Félix-Antoine Fortin, Marc-André Gardner, Marc Parizeau, and Christian Gagné. Deep: A python framework for evolutionary algorithms. In Proceedings of the 14th annual conference companion on Genetic and evolutionary computation, pages 85–92, 2012.DOI
- [5]Charles Blundell, Julien Cornebise, Koray Kavukcuoglu, and Daan Wierstra. Weight uncertainty in neural networks, 2015.arxiv.org/abs/1505.05424
- [6]Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. Pytorch: An imperative style, high-performance deep learning library. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems 32, pages 8024–8035. Curran Associates, Inc., 2019.arxiv.org/abs/1912.01703
- [7]Barnaby E. Walker, James H. Bannock, Adrian M. Nightingale, and John C. deMello. Tuning reaction products by constrained optimisation. Reaction Chemistry & Engineering, 2(5):785–798, 2017.
- [8]Florian Häse, Loïc M. Roch, and Alán Aspuru-Guzik. Chimera: enabling hierarchy based multi-objective optimization for self-driving laboratories. Chemical Science, 9(39):7642–7655, 2018.DOI
- [9]Garvit Agarwal, Hieu A. Doan, Lily A. Robertson, Lu Zhang, and Rajeev S. Assary. Discovery of Energy Storage Molecular Materials Using Quantum Chemistry-Guided Multiobjective Bayesian Optimization. Chemistry of Materials, 33(20):8133–8144, October 2021.DOI
- [10]M. J. Frisch, G. W. Trucks, H. B. Schlegel, G. E. Scuseria, M. A. Robb, J. R. Cheeseman, G. Scalmani, V. Barone, G. A. Peterson, H. Nakatsuji, X. Li, M. Caricato, A. V. Marenich, J. Bloino, B. G. Janesko, R. Gomperts, B. Mennucci, H. P. Hratchian, J. V. Ortiz, A. F. Izmaylov, J. L. Sonnenberg, D. Williams-Young, F. Ding, F. Lipparini, F. Egidi, J. Goings, B. Peng, A. Petrone, T. Henderson, D. R. Nansinghe, V. G. Zakrzewski, J. Gao, N. Rega, G. Zheng, W. Liang, M. Hada, M. Ehara, K. Toyota, R. Fukuda, J. Hasegawa, M. Ishida, T. Nakajima, Y. Honda, O. Kitao, H. Nakai, T. Vreven, K. Throssell, J. A. Montgomery, Jr., J. E. Peralta, F. Ogliaro, M. J. Bearpark, J. J. Heyd, E. N. Brothers, K. N. Kudin, V. N. Staroverov, T. A. Keith, R. Kobayashi, J. Normand, K. Raghavachari, A. P. Rendell, J. C. Burant, S. S. Iyengar, J. Tomasi, M. Cossi, J. M. Millam, M. Klene, C. Adamo, R. Cammi, J. W. Ochterski, R. L. Martin, K. Morokuma, O. Farkas, J. B. Foresman, and D. J. Fox. Gaussian˜16 Revision C.01, 2016.
- [11]Jeng-Da Chai and Martin Head-Gordon. Long-range corrected hybrid density functionals with damped atom–atom dispersion corrections. Physical Chemistry Chemical Physics, 10(44):6615–6620, November 2008.DOI
- [12]Vitaly A. Rassolov, Mark A. Ratner, John A. Pople, Paul C. Redfern, and Larry A. Curtiss. 6-31G* basis set for third-row atoms. Journal of Computational Chemistry, 22(9):976–984, 2001.DOI
- [13]Aleksandr V. Marenich, Christopher J. Cramer, and Donald G. Truhlar. Universal Solvation Model Based on Solute Electron Density and on a Continuum Model of the Solvent Defined by the Bulk Dielectric Constant and Atomic Surface Tensions. The Journal of Physical Chemistry B, 113(18):6378–6396, 2009.DOI
- [14]Amol Thakkar, Veronika Chadimová, Esben Jannik Bjerrum, Ola Engkvist, and Jean-Louis Reymond. Retrosynthetic accessibility score (RAScore) – rapid machine learned synthesizability classification from AI driven retrosynthetic planning. Chemical Science, 12(9):3339–3349, March 2021.DOI
- [15]Peter Ertl and Ansgar Schuffenhauer. Estimation of synthetic accessibility score of drug-like molecules based on molecular complexity and fragment contributions. Journal of Cheminformatics, 1(1):8, June 2009.DOI
- [16]Milan Voršilák, Michal Kolář, Ivan Čmelo, and Daniel Svozil. Syba: Bayesian estimation of synthetic accessibility of organic compounds. Journal of Cheminformatics, 12(1):35, 2021.
- [17]Samuel Genheden, Amol Thakkar, Veronika Chadimová, Jean-Louis Reymond, Ola Engkvist, and Esben J Bjerrum. AiZynthFinder: a fast, robust and flexible open-source software for retrosynthetic planning. Journal of Cheminformatics, 12(1):70, November 2020.
- [18]Florian Häse, Matteo Aldeghi, Riley J. Hickman, Loïc M. Roch, and Alán Aspuru-Guzik. Gryffin: An algorithm for Bayesian optimization of categorical variables informed by expert knowledge. Applied Physics Reviews, 8(3):031406, September 2021.DOI
- [19]Hirotomo Moriwaki, Yu-Shi Tian, Norihito Kawashita, and Tatsuya Takagi. Mordred: a molecular descriptor calculator. Journal of Cheminformatics, 10(1):4, February 2018.
