Simultaneous self-optimisation of yield and purity through successive combination of inline FT-IR spectroscopy and online mass spectrometry in flow reactions

Self-optimisation constitutes a very helpful tool for chemical process development, both in lab and in industrial applications. However, research on the application of model-free autonomous optimisation strategies (based on experimental investigation) for complex reactions of high industrial significance, which involve considerable intermediate and by-product formation, is still in an early stage. This article describes the development of an enhanced autonomous microfluidic reactor platform for organolithium and epoxide reactions that incorporates a successive combination of inline FT-IR spectrometer and online mass spectrometer. Experimental data is collected in real-time and used as feedback for the optimisation algorithms (modified Simplex algorithm and Design of Experiments) without time delay. An efficient approach to handle intricate optimisation problems is presented, where the inline FT-IR measurements are used to monitor the reaction’s main components, whereas the mass spectrometer’s high sensitivity permits insights into the formation of by-products. To demonstrate the platform’s flexibility, optimal reaction conditions of two organic syntheses are identified. Both pose several challenges, as complex reaction mechanisms are involved, leading to a large number of variable parameters, and a considerable amount of by-products is generated under non-ideal process conditions. Through multidimensional real-time optimisation, the platform supersedes labor- and cost-intensive work-up procedures, while diminishing waste generation, too. Thus, it renders production processes more efficient and contributes to their overall sustainability.


Introduction
When industrial production processes are not conducted under ideal conditions, labor-and cost-intensive work-up procedures become necessary to fulfill product quality requirements. Through applying a precise process control that already intervenes at an early stage, manufacturing processes can be rendered more efficient and more sustainable, while simultaneously diminishing waste generation.
While the extant literature has applied inline FT-IR spectroscopy [20,21,50,51] as well as online mass spectrometry [24] in self-optimisation settings only for rather simple reactions and merely in isolation, this work extends the prior ones by presenting an enhanced selfoptimising platform that integrates a successive combination of inline FT-IR spectrometer and online mass spectrometer. This self-optimising platform enables modelfree autonomous optimisation without the need for human intervention and is utilized to experimentally identify optimal reaction conditions of organic syntheses that involve complex reaction mechanisms. For this purpose, inline FT-IR measurements are used to monitor the reaction's main components, whereas the high sensitivity of a mass spectrometer provides insights into the formation of byproducts. Unlike prior works (e.g., [23,28,[52][53][54]), no chromatographic separation is conducted before MS analysis, thus accelerating the analysis process drastically.
A novel approach is developed for solving intricate multidimensional optimisation problems, aiming at maximising product yield and purity. A modified Simplex algorithm as well as Design of Experiments are applied to identify ideal reaction conditions, while at the same time delivering an in-depth process understanding.
The high flexibility of the chosen set-up is demonstrated by means of optimisation of two different reaction types that are of great industrial significance, namely an organometallic reaction with n-butyllithium [55][56][57] and an epoxide synthesis [58]. Both studied reactions serve as starting points for a multitude of further synthesis steps. Thus, a broad spectrum of chemical reactions can be covered, acting as basic building blocks for organic-chemical compounds of industrial relevance [59][60][61][62][63][64][65].
The starting material n-butyllithium 2 was chosen from Sigma Aldrich, Germany, with a concentration of 1.6 mol L −1 in n-hexane. 1 Initial concentrations of the CH-acidic compound 1 and the electrophilic compound 4 amounted to 0.8 mol L −1 .
The reaction was carried out in tetrahydrofuran THF (anhydrous max. 0.005% H 2 O, Merck, Germany). Initial concentrations of dibromomethane 7 and acetophenone 8 amounted to 0.8 mol L −1 . Methyllithium lithium bromide complex solution was chosen from Sigma Aldrich, Germany, with a concentration of 1.5 mol L −1 in diethyl ether a .

Microreactor experiments
In case of the organometallic synthesis with n-butyllithium, a plate microreactor was directly connected to a capillary microreactor, allowing to maintain two independent temperature levels (Fig. 1a). The deprotonation step (reaction of the CH-acidic compound 1 with n-butyllithium 2) was carried out in the plate microreactor, which had been designed and manufactured by mechanical precision milling of stainless steel (Fig. 1b). It consisted of three stainless steel plates layered one on top of each other, where channels for mixing and residence time were milled into the middle reactor plate (each channel had a quadratic cross-section). To avoid bypass flow, the plates were evenly pressed onto each other (ensuring equal pressure between the plates) using numerous screws. Bore holes that were located on the lateral surface of the middle reactor plate were utilized as inlet and outlet connections for the reactants. Channels for precooling (0.5 mm × 0.5 mm), mixing (0.5 mm × 0.5 mm), and reaction were arranged in an arrow-shaped geometry. The reaction channel was divided into two sections: at the entrance, a 0.5 mm × 0.5 mm channel enabled enhanced heat transfer; with increasing conversion, an increased channel size (1 mm × 1 mm) was employed, enabling high reactant conversion at longer residence times. The entrance region of the reaction channel had a length of 1.1 m, the region with increased channel size had a length of 9.11 m, resulting in a total reactor volume of 7.37 mL.
As the kinetics of the deprotonation step had already been studied in detail [55][56][57], deprotonation of the CH-acidic compound 1 was performed at a constant residence time of 8 min and a temperature of −35°C, ensuring full conversion of the nbutyllithium 2. In order to avoid clogging, the CH-acidic compound 1 was provided in marginal excess; the stoichiometric ratio of n-butyllithium: CH-acidic compound amounted to 0.8. Temperature control was achieved through heat carrier channels (3 mm × 10 mm) that were milled on the bottom of the middle reactor plate, where two Pt100 resistance thermometers could directly be inserted into the inflowing and outflowing thermal fluid via bore holes located at the lateral surface of the middle plate. A thermostat (Unistat Tango Nuevo, Huber, Germany) allowed for adjusting the temperature of the heating/cooling fluid.
The nucleophilic addition was carried out in a coiled 1/16 in. stainless steel capillary microreactor. Precooling of the electrophilic compound 4 was conducted in a capillary with an inner diameter of 0.5 mm. The precooling capillary was directly connected to the outlet of the plate reactor via a stainless-steel T-mixer (inner diameter 0.5 mm), followed by a reaction channel that had an inner diameter of 0.5 mm and a total volume of 0.59 mL. The chosen microreactor setup permitted residence times between 0.2 and 1 min. Temperature control of precooling, mixing, and reaction was achieved using a bath thermostat (Ministat, Huber, Germany).
Regarding epoxide synthesis, the microreactor setup consisted of coiled 1/16 in. PFA tubing 2 (Fig. 2). Reactants were precooled and mixed in T-mixers (0.5 mm inner bore hole). The reaction mixture then passed two modular reactor pieces that were connected to each other. In the first capillary, which had a total volume of 0.5 mL (inner diameter 0.5 mm), residence time remained constant at 0.5 min. Temperature was varied between −35°C and − 10°C (bath thermostat Huber Tango Nuevo). In the second capillary, which had a total volume of 2 mL (inner diameter 0.75 mm), the reaction mixture was warmed to 20°C (1 min residence time, bath thermostat Huber Ministat). Thus, cyclization of the bromomethyl alkoxide intermediate took place. A back-pressure regulator (3 bar) ensured light overpressure within the whole microreactor.
Mixing of reactants occurred through one out of three different cases. In the first case, dibromomethane 7 and acetophenone 8 had been premixed manually (feed stream 1) 2 When investigating epoxide synthesis, the microreactor setup used PFA tubing (instead of stainless-steel tubing) to avoid pitting corrosion caused by bromide ions. and then combined with methyllithium (feed stream 2; Fig.  2a). In the second case, dibromomethane 7 and acetophenone 8 (Fig. 2b) entered through two separate feed streams and, once they had been mixed, were subsequently combined with methyllithium (feed stream 3), thus allowing to variably adjust the stoichiometric ratio of 7 and 8. In the third case, dibromomethane 7 and methyllithium ( Fig. 2c) entered through two separate feed streams and, once they had been mixed, were subsequently combined with acetophenone 8. Dosage of all starting materials within 1 mL glass syringes was ensured by continuously working syringe pumps (SyrDos2, HiTec Zang GmbH, Germany). Temperature and flow rates were controlled by a laboratory automation system (LabManager, HiTec Zang GmbH, Germany).

Inline FT-IR and online MS measurements
Both described syntheses (organometallic reaction with nbutyllithium; epoxide synthesis) were continuously monitored at the reactor outlet. The analysis of the respective product stream was conducted through a successive combination of an inline FT-IR spectrometer and an online mass spectrometer  by-product formation (as MS possesses significantly higher sensitivity). Unlike prior works (e.g., [23,28,[52][53][54]), chromatographic separation had not been conducted before MS The use of an inline FT-IR spectrometer (Bruker ALPHA, United States) allowed for real-time reaction tracking with time delay <1 s, circumventing the need to quench the reaction. The reactor outlet was directly connected to the spectrometer's flow cell through a very short capillary of 3 cm with an inner diameter of 0.5 mm [55]. The measuring cell of the FT-IR spectrometer with a volume of 40 μL enabled extremely fast measurement times, shorter than 2 ms (flow rates ≥0.31 mL min −1 ). The employed FT-IR spectrometer has an optical wavelength resolution of 4 cm −1 . Infrared spectra (500-1700 cm −1 ) were collected through single reflection ATR (diamond crystal).
Characteristic IR bands allowed for calculating product yield based on previously determined calibration curves. The reaction product of the organometallic synthesis with nbutyllithium 6 was identified by means of a characteristic IR band at 1241 cm −1 to 1230 cm −1 , whereas epoxide 10 was identified by means of a characteristic IR band at 711 cm −1 to 696 cm −1 . Analytical IR spectra and details on the integration method are provided in supporting information A.2.
As the reactant concentrations (amounting to roughly 0.25 mol L −1 ) were suitable for inline FT-IR analysis, no dilution step was required beforehand. Following the inline FT-IR analysis, however, continuous quenching of the reaction mixture took place (compact dual piston pump AZURA P4.1S, Knauer, Germany). A subsequent split and dilution step (refer to supporting information A.3 for more details) allowed to adjust reactant concentrations to render them suitable for analysis via online mass spectrometry, as the online mass spectrometer's high sensitivity requires reactant concentrations of around 0.02 mol L −1 to not overload the spectrometer. Afterwards, aliquots of the reaction mixture were periodically introduced to the mass spectrometer using a 6/2 port sample valve (Analytical HPLC Continuous-Flow Injector, VICI, United States). With the 6/2 port valve in load position, the diluted reaction mixture filled a 5 μL loop fitted across two of the valve ports and was thereafter automatically injected into the mass spectrometer, switching the valve to its inject position (a 1/16 in. stainless-steel tubing, 0.5 mm i.d., connected the reactor outlet with the valve and the mass spectrometer). With the 6/2 port valve in inject position, another high-pressure pump (Agilent Technologies, United States) flushed the loop with a continuous methanol stream (300 μL min −1 , hypergrade for LC-MS, Sigma Aldrich, Germany) and thus passed the sample into the mass spectrometer for analysis. The spectrometer used was an Advion Expression CMS operating in positive atmospheric pressure chemical ionisation mode (APCI). A detailed description of the online MS setup is provided in supporting information A.3.
Overall, by combining these two techniques (FT-IR spectroscopy and online MS), the experimental set-up aimed at leveraging methodological synergies. Specifically, while FT-IR spectroscopy constitutes a fast, broadly applicable method that reduces barriers to implementation, it is less suitable for monitoring by-products unless they exceed the parts per million (ppm) level [10,37,66].
Conversely, online MS is particularly well-suited for the characterization and quantification of analytes up to trace levels, even in complex mixtures [40,42,43,47]. However, it may only provide relative (instead of absolute) numbers due to ionization suppression or enhancement effects [67][68][69][70][71] as the components may affect each other's ionization efficiencies. For this reason, an additional internal standard (product intensity) was used to compensate for these biases (further details regarding the exact procedure are provided in the following chapter).
Compared to traditional HPLC, or even UPLC measurements [72], the chosen analytical techniques do not incur a time-delay of several minutes between the initial measurement and the computation of the corresponding analytical result. As a result, unstable or reactive intermediates and products can be identified almost immediately, due to the involved real-time reaction monitoring leading to a time-delay of 1 min at most [10,37,40]. Hence, there is a high methodological fit between FT-IR spectroscopy, online MS, and the objective of efficient process development, particularly in terms of continuous processes. Yet, the absence of chromatographic separation adds an additional level of complexity to the interpretation of the resulting data [40].
To conclude, the experimental set-up applies FT-IR spectroscopy and online MS in a highly complementary manner. FT-IR spectroscopy (instead of online MS) delivers absolute values in order to avoid frequently emerging biases, whereas online MS provides the required sensitivity to examine byproducts at the ppm level.

Self-optimisation
This work relies on a completely automated self-optimising platform [73], which integrates a microreactor with automated devices (pumps and thermostats) and a successive combination of real-time reaction monitoring through inline FT-IR spectroscopy and online mass spectrometry. Real-time optimisation is steered by a fully automated experimental sequence coded in MATLAB, which assumes control over optimisation strategies and the calculation of the objective function. Simultaneously, MATLAB transfers the set points for pumps and thermostats to the automation system. The platform is compatible with industrial production conditions (oriented on NAMUR standards), ensuring a high level of process safety. Integrated safety features, such as pressure and temperature monitoring, comply with industrial standards. More details on the experimental self-optimising workflow are provided in supporting information A.4.
Analytical results of inline FT-IR measurements are transferred to MATLAB through an OPC interface (realtime communication with time delay <1 s). Thus, product yield can directly be calculated incorporating the respective calibration curve.
Regarding online MS measurements, however, the transfer of analytical results proceeds through extraction of CDF-files that are gained as output from the mass spectrometer, containing an accumulated scan time, m/z-values (mass-to-chargeratio), and their respective intensities. As a result, each involved reactant that can be analyzed via APCI, can be identified by its characteristic m/z value, with the peak's intensity indicating the reactant's quantity (Fig. 4).
Especially in case of the organometallic synthesis with n-butyllithium, pure substances of all reactants expected to be involved in the complex reaction mechanism including by-product formation were available, hence, MS calibration curves could be determined for each individual component, see supporting information A.5. However, the actual reaction mixture leaving the reactor constitutes a complex matrix including solvent, main product, byproducts, and not yet consumed starting materials. Ionization suppression or enhancement effects [67][68][69][70][71] may no longer be ruled out, as the components may affect each other's ionization efficiencies.
In order to circumvent such elusive effects, following the extraction of CDF-files containing all m/z values, intensities of all involved by-products are calculated when product intensity reaches its peak. The sum of all those by-product intensities is then determined, and the ratio of product and sum of byproducts is used as input for the objective function (Eq. 1). As a result, the determined MS ratio contains the product's mass intensity as internal standard and moreover compensates for concentration fluctuations that result from quenching the reaction with a constant mass flux. Individual calibration curves are thus not required to calculate the objective function, but are useful to evaluate whether given components are suitable for MS analysis in general.
To combine the estimated product yield from FT-IR analysis with information about undesired by-product formation, the FT-IR signal is multiplied with the calculated MS ratio (Eq. 2). Aiming at maximising product yield while simultaneously minimising by-product formation, the resulting objective function can easily be implemented in the described MATLAB code. 3 A detailed description of the pretests that had been conducted to scrutinize the applicability of the chosen evaluation method regarding MS files is provided in supporting information A.6.
In this work, two optimisation strategies, modified Simplex algorithm and Design of Experiments (DoE), are applied, as their performances had already been documented and compared in detail [73].
Simplex optimisation proceeds through iteratively replacing a randomly chosen initial simplex. Specifically, the start simplex was set to random values located on each axis, with the last remaining corner point always being randomly chosen within the reaction space. Hence, optimal reaction conditions are identified as soon as the simplexes converge to a local optimum, where the value of the objective function does not vary anymore. The maximum number of experiments (per optimisation cycle) was set to 30.
When applying DoE, a Central Composite Design (CCD) was chosen. During each optimisation, two experimental runs were executed. The first run screened the entire experimental space. Based on the first run's experimentally obtained data points, a surface response model was calculated. The mathematical optimum of this surface response model was subsequently used as central point for the second DoE run. To refine the search for a global optimum, the size of the second DoE run amounted to 20% of the size of the first DoE run.

Organometallic synthesis
In order to evaluate the effectiveness of the presented selfoptimising platform incorporating a successive combination of real-time reaction monitoring through inline FT-IR 3 The derived autonomous platform constitutes a modular and flexible system, enabling multi-variate and multi-objective optimisations in real-time. Hence, other objective functions (besides multiplying the FT-IR signal with the calculated MS ratio, see Eq. 2) can swiftly be integrated. For instance, an objective function consisting of differently weighted parts (e.g., weighting the costs for separating non-converted starting materials against the costs for work-up procedures required to remove undesired by-products), or a jump function characterizing by-product formation, could also be investigated, depending on the issue being addressed.

Fig. 4
Exemplary online MS analysis of organometallic reaction with n-butyllithium. Experimental parameters: a stoichiometric ratio [3,4] amounting to 1.0; reaction temperature − 10°C, b stoichiometric ratio [3,4] amounting to 1.0; reaction temperature − 30°C spectroscopy and online mass spectrometry, two different optimisation studies were compared: In the first study, selfoptimisation was only based on inline FT-IR measurements, thus aiming at maximisation of main product yield. In the second study, the estimated product yield from FT-IR analysis was combined with information from MS analysis aiming at maximising product yield and purity. The organometallic synthesis with n-butyllithium was used as proof of concept, as kinetics and mechanism had already been studied in detail [55][56][57]74]. Pure substances of all involved compounds were available meaning that calibration curves, and thus reference values, had already been known in advance.

Product yield maximisation
Regarding the optimisation procedure based exclusively on FT-IR measurements, a modified Simplex algorithm and Design of Experiments were implemented as optimisation strategies. The second step of the organometallic synthesis with n-butyllithium, namely the nucleophilic addition, was optimised, aiming at maximum product yield. Two optimisation parameters were examined: the stoichiometric ratio of lithiated intermediate 3: electrophilic compound 4 as well as reaction temperature. The stoichiometric ratio was varied in the range between 0.5 and 2.5, while temperature was varied between −35°C and − 10°C. Note that, as residence time and stoichiometric ratio are intertwined as far as the reaction at hand is concerned, these two variables may not be varied independently from each other. Figure 5 depicts the experimental results of Simplex optimisation as coloured dots with the colours indicating the corresponding values of product yield, and further displays the progress of the objective function over the course of the iterations.
Three repetitions of the same optimisation procedure were conducted, differing only with regard to their start simplexes.
As a result, an optimal stoichiometric ratio close to 1.0 was identified, whereas the optimal temperature could not be determined exactly, but only be located within a certain range between −23°C and − 15°C. After three repetitions, the relative standard deviation amounted to 4.1% (stoichiometric ratio) respectively 22% (temperature).
In terms of DoE, the surface response models obtained by the first and second run while optimising stoichiometric ratio and temperature, are provided in Fig. 6. Experimental data points, from which the respective surface response model was built as best fit, are displayed as red dots.
While the visualisation in Fig. 6 clearly indicates an optimal stoichiometric ratio near 1.0, the ideal reaction temperature cannot be determined exactly. Instead, the resulting surface response models merely point to a broad temperature range. The second DoE run does not improve upon the result of the first one.
To assess optimisation accuracy, the average deviation of the experimental data points from the associated surface response model was determined. It amounted to 15% for the first DoE run and to 7% for the second DoE run. The relative standard deviations of calculated optimal product yield after six repetitions amounted to 4.2% respectively 3.5%. Table 1 summarizes the obtained results for both optimisation strategies (Simplex and DoE). For each strategy, the optimal reaction conditions and the required number of experiments are presented. Note that, in case of DoE optimisation, the results of the second DoE run are provided.
The results of DoE optimisation are comparable to those of Simplex optimisation. The optimal product yield is reached at a stoichiometric ratio of 1.0, which is associated with a residence time of 0.3 min. Note that, for residence times smaller than 0.3 min, full conversion of starting materials cannot be accomplished (leading to reduced product yield). However, the optimal reaction temperature is difficult to quantify, when only product yield is examined, as temperature optimisation is expected to predominantly affect by-product formation, with the amount of created by-products in the experiment remaining below FT-IR's sensitivity threshold.

Product yield maximisation with simultaneous minimisation of by-product formation
To expand upon the results of self-optimisation based exclusively on inline FT-IR measurements, a successive combination of real-time reaction monitoring through inline FT-IR spectroscopy and online mass spectrometry was implemented within the self-optimising platform. As mass spectrometry constitutes an analytical technology that possesses significantly higher sensitivity than FT-IR spectroscopy, and as reaction temperature may exert considerable influence on the formation of by-products that are present in the reaction mixture to a much lesser extent compared to the main product, such a combination of both measurement techniques was expected to provide additional insights.
The kinetics [55][56][57] and mechanism of by-product formation [74] of the presented organometallic synthesis had previously been studied in detail. Thus, it has been known in advance that four characteristic by-products can be formed. All four by-products were available as pure substances, from which MS calibration curves could be determined (supporting information A.5). The ratio of MS product intensity and the sum of MS intensities of all four by-products was used as input for the objective function together with the main product's FT-IR signal, Eq. 2. Again, a modified Simplex algorithm and Design of Experiments were applied as optimisation strategies. Nucleophilic addition was optimised aiming at maximising product yield while simultaneously minimising by-product formation. The Simplex optimisation with successive combination of real-time reaction monitoring through inline FT-IR spectroscopy with online mass spectrometry identified an optimal stoichiometric ratio close to 1.0, which is in line with the result obtained by the prior optimisation solely based on FT-IR measurements, and an optimal reaction temperature of −30°, whereas the prior optimisation could not determine optimal  reaction temperature accurately. After three repetitions, the relative standard deviation of the stoichiometric ratio amounted to 3.9%, and the one of temperature amounted to 3.0%. Figure 8 provides the corresponding results of DoE optimisation, based on the combination of FT-IR and MS signals. The surface response models obtained by the first and second DoE run, while optimising stoichiometric ratio and temperature, are displayed with experimental data points being represented as red dots. Moreover, individual surface response models resulting from solely evaluating the FT-IR respectively MS signals were calculated and are provided in supporting information B.2.
The surface response models illustrated in Fig. 8 clearly indicate an optimal stoichiometric ratio near 1.0 and an optimal reaction temperature of −30°C, comparable to the results of Simplex optimisation, when the latter is based on a combination of FT-IR and MS measurements. The average deviation of experimental data points from the associated surface response model amounted to 10% in case of the first DoE run, and to 5% in case of the second DoE run. The relative standard deviations of the calculated values of the objective function after six repetitions amounted to 10.1% and 9.8% for the first and second run, respectively. Table 2 summarizes the performance of both optimisation strategies (Simplex and DoE) in terms of maximising product yield while simultaneously minimising by-product formation.

Synthesis of terminal epoxide
In order to evaluate the platform's versatility in terms of reaction types, an epoxide synthesis was also investigated. In contrast to the reaction examined before, this time less information regarding reaction mechanism and kinetics had been available a priori. Thus, DoE was applied as optimisation strategy instead of the Simplex algorithm to obtain greater understanding of the underlying processes. 4 The epoxide synthesis proceeded through in situ generated (bromomethyl)lithium, which had been generated by lithiumhalogen exchange of dibromomethane, and which constitutes a highly unstable lithiated intermediate. Even though microreactors have been proven to be suited for handling such temperature-sensitive syntheses [58,[75][76][77][78][79] due to enabling efficient mixing and fast heat transfer, several undesired side reactions cannot be ruled out entirely. This includes (1) nucleophilic addition of the alkyllithium reagent to the carbonyl group of acetophenone, (2) formation of polymers from a coupling of bromomethyl lithium with dibromomethane or (3) a premature quench of the reaction mixture before the cyclization step could occur [58,80,81]. Thus, the applied self-optimisation procedure once again aimed at maximising of main product yield, while simultaneously minimising byproduct formation. More details on potential side-reactions are provided in supporting information C.1.
In contrast to the organometallic reaction with nbutyllithium, pure substances of by-products were not available in terms of epoxide synthesis. Thus, pre-tests under variation of reaction temperature were conducted to identify characteristic by-products of epoxide synthesis. A detailed description of pre-tests as well as MS spectra are provided in supporting information C.2. As a result, the ratio of MS product intensity and the sum of MS intensities of six characteristic 4 DoE allowed to screen the entire experimental space and to build surface response models, thus providing further insights into the reaction mechanism (and where to find the global optimum). Conversely, applying the modified Simplex algorithm for such a comparatively unknown reaction would have exposed the study to the risk of the algorithm getting stuck at a local (rather than global) optimum. Due to the lack of a priori information on the reaction, no adequate assessment could have taken place to determine whether a given optimum is a global or local one. Three different dosing options were investigated, differing in their respective type of reactants mixing based on two or three reactant feeds. In all three cases, residence time in the first part of the reactor was kept constant at 0.5 min. In the following cyclization step, the reaction mixture was then held at 20°C for 1 min.

Epoxide synthesis proceeding through two feed streams
Initially, the epoxide synthesis proceeded through combination of a manually-premixed solution of dibromomethane 7 and acetophenone 8 (1.1 eq. dibromomethane) with the methyllithium, resulting in two feed streams (Fig. 2a). Thus, two parameters were optimised: stoichiometric ratio of methyllithium: premixed starting materials in the range between 0.1 and 1.1, and reaction temperature in the range between −35°C and − 10°C.
In Fig. 9, the resulting surface response models obtained by the first and second DoE run are illustrated with manual premixing of dibromomethane 7 and acetophenone 8. Results are based on the combination of FT-IR and MS signals. Experimental data points are represented as red dots.
The optimal stoichiometric ratio of methyllithium: premixed starting materials and optimal reaction temperature were shown to be close to 0.9 respectively −35°C (Fig. 9). 5 Individual surface response models resulting from an evaluation of FT-IR respectively MS signals are provided in supporting information C.3.

Epoxide synthesis proceeding through three feed streams
Second, the experimental setup was enhanced to handle three feed streams: dibromomethane 7 and acetophenone 8 entered through two separate feed streams and, once they had been mixed, were subsequently combined with methyllithium (feed stream 3, see Fig. 2b). Thus, three parameters were optimised: stoichiometric ratio of acetophenone 8: dibromomethane 7 in the range between 0.1 and 1.5, stoichiometric ratio of methyllithium: premixed starting materials in the range between 0.6 and 1.1, and reaction temperature in the range between −35°C and − 10°C.
In the third case, dibromomethane 7 and methyllithium entered through two separate feed streams and, once they had been mixed, were subsequently combined with acetophenone 8 (Fig. 2c). Again, three parameters were optimised, albeit now, stoichiometric ratio of methyllithium: dibromomethane 7 in the range between 0.1 and 1.1, stoichiometric ratio of lithiated intermediate: acetophenone 8 in the range between 0.1 and 1.1, and reaction temperature in the range between −35°C and − 10°C.
For both cases including three feed streams, Fig. 10 represents the results of DoE optimisation as experimental data points, whose colour scheme represents the objective function combined from FT-IR and MS signals (see Eq. 2) dependent on the respective variable parameters. The corresponding surface response models derived for the optimisation of three variable parameters can be found in supporting information C.3.
Investigating the second synthesis route variable premixing of dibromomethane 7 and acetophenone 8, DoE optimisation resulted in an optimal stoichiometric ratio of acetophenone: dibromomethane amounting to 0.9. Thus, under optimised conditions, dibromomethane 7 is provided in slight excess. This finding is in accordance with studies described in the extant literature [58]. Again, the best compromise between the highest possible main product yield and the lowest level 5 Note that, there is a minor deviation between, on the one hand, the results of the DoE optimisation and, on the other hand, the findings described in the extant literature, where a one-dimensional optimisation of reagent amount and concentration led to 1.5 equiv. of methyllithium under ideal conditions [58]. However, the applied optimisation strategies cannot be compared directly, as the setup described in this work allows for multidimensional self-optimisation based on calculations of optimisation algorithms, whereas the extant work applies a one-by-one optimisation based on an evaluation of HPLC yields. Moreover, in the current work, the formation of by-products was considered within the objective function, thus resulting in an intricate optimisation problem where product yield is maximised with simultaneously reducing the amount of undesired by-products. Fig. 8 Optimisation of organometallic synthesis using DoE. Results are based on inline FT-IR and online MS measurements. a First DoE run for screening of whole experimental space. b Second DoE run to refine optimisation of by-product formation, was found at a stoichiometric ratio of 0.9 (methyllithium: starting materials) and a reaction temperature of −35°C.
Whereas the second synthesis route simply constituted an extension to three feed streams compared to the first route, a completely different reaction control was applied in the third case. Herein, external quenching [77,82] was conducted, instead of "Barbier"-like internal quenching [83][84][85]. Given the instability of lithium carbenoids, which are likely to suffer from immediate thermal decomposition, the generation of carbenoid species followed by external trapping with electrophiles has been less researched compared to internal quenching [81]. The enhanced heat transfer in microreactors permits the handling of such thermolabile carbenoids [31,58,[76][77][78][79]86]. The optimisation studies conducted in this work identified optimal conditions at a slight shortage of methyllithium (stoichiometric ratio of methyllithium: dibromomethane 7 amounting to 0.9) and slight excess of acetophenone (stoichiometric ratio of lithiated intermediate: acetophenone 8 amounting to 0.9). A reaction temperature of −35°C once again proved to be ideal for minimisation of by-product formation. Table 3 summarizes the obtained results of DoE optimisation for epoxide synthesis (all three investigated dosing options are discussed). For every case, optimal reaction conditions are displayed, which were calculated based on the respective surface response model of the second DoE run. Moreover, the average deviation of the experimental data points from the associated surface response model was determined, allowing to assess each optimisation's accuracy.
Comparing the results of DoE optimisation for all three investigated dosing options, it becomes apparent that the objective function assumes a significantly higher value in its optimum, when applying external quenching. This indicates a noticeably smaller proportion of undesired byproducts compared to reaction control through internal quenching as maximum main product yield is similar across all three investigated cases, see supporting information C.3. However, while the examination of both internal quenching routes resulted in surface response models from which optimal reaction conditions could be predicted in a reliable and replicable manner as indicated by comparatively low average deviations of the experimental data points from the associated surface response models, a sufficiently precise representation of experimental data resulting from the external quenching route through surface response models is much harder to achieve. This is due to the fact that, during DoE optimisation, experimental plans need to cover a   [82,[87][88][89], at temperatures above −35°C, they are likely to decompose before a reaction with acetophenone can occur. To overcome this challenge, an additional Simplex optimisation was conducted for the external quenching route based on the findings of the first DoE run (start simplex was located around its optimum), thus enabling investigation of smaller temperature steps compared to DoE optimisation. Figure 11 displays the results of this Simplex optimisation and further presents the progress of the objective function over the course of its iterations. The experimental results are illustrated as coloured dots, with the colours indicating the corresponding values of the objective function (combination of main product's FT-IR signal and MS ratio). Three parameters were optimised: stoichiometric ratio of methyllithium: dibromomethane 7 in the range between 0.8 and 1.0, stoichiometric ratio of lithiated intermediate: acetophenone 8 in the range between 0.9 and 1.1, and reaction temperature in the  The ideal conditions identified through Simplex optimisation are comparable to those identified by DoE optimisation. Again, the optimal stoichiometric ratio of methyllithium: dibromomethane 7 and the optimal stoichiometric ratio of lithiated intermediate: acetophenone 8 were both shown to be close to 0.9 with a slight shortage of methyllithium respectively slight excess of acetophenone. Additionally, a minimum amount of by-products is generated at a reaction temperature of −35°C. Examining Fig. 11, it becomes apparent that the objective function reaches particularly high values when reaction temperature is kept at a low level. This is in accordance with the assumption that external quenching requires reaction temperatures near −35°C (but at least lower than −33°C), as otherwise thermal decomposition of the lithium carbenoid species occurs, preventing its reaction with acetophenone.

Discussion
When optimisation aims at maximising product yield while simultaneously minimising by-product formation, the examination of multi-stage organic syntheses that involve complex reaction mechanisms leads to intricate multidimensional optimisation problems. Examples include the organic syntheses investigated in this work: Both the organometallic synthesis with n-butyllithium (deprotonation followed by nucleophilic addition) and epoxide synthesis (reaction and subsequent cyclization) constitute consecutive reactions. A considerable amount of by-products is generated if either of these syntheses is not conducted under ideal process conditions, diminishing process efficiency, i.e. leading to decreased product yield and necessitating work-up procedures.
Such intricate optimisation problems may be solved through the versatile self-optimisation approach developed in this work, which was capable of successfully solving the presented problems within a single working day and without any human intervention. Due to its modular and flexible nature, the set-up moreover accelerates process development while also diminishing the obstacles that would otherwise hamper the transfer from lab to pilot scale.
The developed approach incorporates a successive combination of an inline FT-IR spectrometer and an online mass spectrometer. There, inline FT-IR spectroscopy is utilized to monitor main product yield, whereas the mass spectrometer's high sensitivity provides insights into the formation of by-products.
Both techniques entail individual benefits and drawbacks: Inline FT-IR measurements permit the calculation of product yield based on calibration curves. However, given the lower sensitivity of FT-IR spectroscopy compared to mass spectrometric analysis, by-products cannot directly be monitored when they remain on or below a parts per million (ppm) level. Conversely, online mass spectrometry illuminates by-product formation, but may only provide relative (instead of absolute) numbers due to ionization suppression or enhancement effects [67][68][69][70][71], as the components may affect each other's ionization efficiencies.
Overall, by applying both techniques in a manner where they nullify each other's drawbacks, the presented platform leverages methodological synergies. It enables the multidimensional optimisation of all involved process parameters. Additionally, this work provides further evidence that, while FT-IR spectroscopy by itself already constitutes a powerful tool for self-optimisation, performance can be improved further by a complementary application of online mass spectrometry. Together, they provide comprehensive insights into complex reaction mechanisms.
Yet, when conducting multi-stage syntheses, it has to be considered that process parameters can be intertwined and, in such cases, may not be varied independently from each other. The examined optimisation algorithms in this work can only deal with such circumstances as far as certain restrictions are applied, otherwise the number of experiments required to solve the respective optimisation problem would skyrocket. For instance, in this work, constant process parameters were applied for the deprotonation step of the organometallic synthesis with n-butyllithium (first step of the synthesis, followed by nucleophilic addition) to reduce the number of variable parameters. In terms of epoxide synthesis, the residence times of both synthesis steps (reaction and cyclization) were held constant and the three examined dosing schemes were investigated independently from each other.
To conclude, despite their limitations, both optimisation strategies applied in this work, the modified Simplex algorithm as well as Design of Experiments, successfully identified optimal reaction conditions, while at the same time granting an in-depth process understanding. A detailed discussion of by-product formation is provided in supporting information B.3 and C.4. 6

Conclusion
Through its use of multidimensional optimisation of reaction parameters, the self-optimising system derived in this work autonomously guides chemical processes towards ideal reaction conditions, whilst reducing the need for human intervention. Several benefits are provided: The successive combination of FT-IR spectrometer and mass spectrometer permits investigating intricate optimisation problems, aiming at maximising product yield while simultaneously minimising by-product formation. Experimental data, which is collected in real-time, can be used as immediate feedback to decide on the next experimental conditions, as the use of inline FT-IR spectroscopy and successive online mass spectrometry without former chromatographic separation means that no waiting times between measurement and evaluation thereof occur. Thus, both measurement techniques' unique advantages are leveraged.
Furthermore, going beyond real-time reaction monitoring and the observation of intermediates and by-products, the platform derived in this work fully exploits the potential of online analytics by autonomously solving optimisation problems through a model-free experimental investigation. Applying a modified Simplex algorithm and Design of Experiments, optimal reaction conditions of organic syntheses that involve complex reaction mechanisms and a large number of variable parameters can be identified, thus obtaining in-depth process understanding. The screening of the entire experimental space through DoE and subsequent Simplex optimisation constitutes a reliable approach that is particularly useful when a priori information on the reaction mechanism is not available.
Two different reaction types, organolithium and epoxide synthesis, were examined in this work, outlining the platform's broad range of applicability. All studied optimisation problems were successfully solved within a single working day. Thus, researchers and industry alike may consider its implementation as efficient, reliable and versatile self-optimisation tool.
Funding Open Access funding enabled and organized by Projekt DEAL. This work was funded by the German Federal Ministry of Education and Research (BMBF), programme FH Impuls -Partnership for Innovation M 2 Aind, project SM 2 all (grant No. 13FH8I01IA).

Declaration
Conflicts of interest On behalf of all authors, the corresponding author states that there is no conflict of interest. Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.