A method of generating computer-readable code executable by a controller of a scientific instrument, a controller of a scientific instrument, and a computer program
Generative large language models generate and iteratively refine code from natural language instructions, addressing the complexity and user expertise challenges in scientific instrument controllers, enhancing flexibility and user-friendliness.
Patent Information
- Authority / Receiving Office
- GB · GB
- Patent Type
- Applications
- Current Assignee / Owner
- THERMO FISHER SCI BREMEN
- Filing Date
- 2024-11-15
- Publication Date
- 2026-06-17
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Field of the invention
[0001] The present disclosure relates to methods of controlling scientific instruments. In particular, the disclosure provides methods of developing code for controlling scientific instruments based on instructions received in a natural language.
[0002] The skilled person in this field is familiar with large language models, analytical chemistry, spectroscopy and software design. Background
[0003] Scientific instruments, such as mass spectrometers, have a broad range of different applications in different technical fields. As a result, tools and acquisition workflows for controlling the instrument to obtain and analyse sample data are required to meet a variety of different needs. Customization of these tools and workflows is therefore highly desirable. However, increased customisation of the software for controlling the instrument may result in increased complexity that may in turn make the controller of the instrument less user-friendly for some users (e.g., those that have more straightforward requirements). An example of a typical conflict of interest arises when an instrument is intended for use by both routine labs and cutting-edge research labs. These labs have very different requirements with respect to, for example, flexibility of data processing and evaluation.
[0004] In prior art instrument controllers, the different needs of different users are addressed by providing different “modes” of operation in the controller. For example, the controller may operate in a “simplified evaluation” mode and an “advanced evaluation” mode. However, such modes require complex software to be developed for the controller that are resource-intensive to develop and are prone to performance issues. From this example, it may be concluded that accommodation of every user’s requirements might be impractical or impossible, when a user’s specific requirement is not aligned with the needs of the majority of the other users.
[0005] Additionally, the time taken to implement functionality required by users may be exceed what users would find acceptable in some circumstances. Generally, users would submit their feature requests to the software developers responsible for the controller and each request would be prioritized, planned, tested, and evaluated.
[0006] Moreover, it may be preferable not to modify the core controller software, as this may lead to instability in the core software for all users. Instead, it may be preferable to design experiments and custom acquisition procedures for users to acquire experimental data using the core software in a flexible manner.
[0007] One solution providing additional flexibility that has been adopted in the past, is to enable the controller software to accept custom scripts, which may be custom written by the software developers responsible for the controller, at the request of users. This allows for custom functionality to be added, without modifying the core software. For this to work, the instrument control software provides some APIs that can be used by a scripting engine provided within the framework of the instrument controller. This requires that the user modifying the workflow is able to adeptly write the scripts in the required scripting language and that the controller software is able to accommodate the requirements of the scripting language. Moreover, to successfully write a script that uses the APIs, the user must first gain a significant understanding of knowledge about the internal implementations and workflows of the framework. This is a significant challenge even for the software developers responsible for the controller and it is unlikely to be practical for end users to write their own scripts.
[0008] The present disclosure aims to address the drawbacks of the present approach. Summary
[0009] Against this background, the present disclosure proposes to use generative large language models to generate code to solve an analytical problem provided by a user of the instrument. This approach allows the user to create custom workflows quickly and without detailed knowledge of programming or the internal workings of the instrument control software / APIs.
[0010] A method of generating computer-readable code executable by a controller of a scientific instrument is provided. The method comprises receiving instructions in a natural language. The method further comprises processing the instructions using a large language model to generate computer-readable code executable by the controller of the scientific instrument to: control the scientific instrument to obtain data from analysis of a sample; and / or process the data obtained from analysis of the sample by the scientific instrument.
[0011] The proposed methods therefore provide an interfacing tool between user requests (e.g., for data evaluation, enhancement, visualization and acquisition) and the production code environment of the controller. This arrangement may be very flexible and advantageous.
[0012] The use of large language models to generate computer code is known in the art. So-called “Program-Aided-Language models” or PAL convert natural language prompts into computer programs. The methods proposed in this disclosure use Program-Aided-Language models differently to prior art methods. The application of Program-Aided-Language models for highly complex tasks and usage in complex environments such as instrument control software, as presented in this disclosure, has never been achieved before.
[0013] A large language model is an Artificial Intelligence code generator configured to generate computer code in response to a prompt, where the prompt comprises the instructions in a natural language.
[0014] The large language model may be pre-trained to generate computer-readable code.
[0015] The large language model may be pre-trained (fine-tuned) using on one or more of: analytical chemistry methods using the scientific instrument (i.e., the specific scientific instrument that the controller is configured to control); Software Development Kit (SDK) documentation to identify functions for controlling the instrument (e.g., tuning, data acquisition, status checks); and communication protocols and available methods for starting / stopping measurements, setting parameters, and reading data.
[0016] A natural language is a language spoken, written and understood by humans, as opposed to machine code written in a computer programming language.
[0017] The computer-readable code may be provided to the controller of the scientific instrument.
[0018] The method may further comprise controlling the scientific instrument by executing the computer-readable code.
[0019] The code may be provided in a suitable programming language for providing to instrument control software running on the controller. The computer-readable code may be written by the large language model in a human-readable programming language (e.g., python or C#).
[0020] It is preferable to generate code using the large language model and then execute the code using a suitable interpreter (e.g., a Python interpreter). This approach generally leads to more accurate results than generating machine code directly by the large language model to solve the problem presented. Moreover, the code generated is more testable and debuggable than machine code.
[0021] Alternatively, the computer-readable code may be written by the large language model in machine code for direct execution by the controller.
[0022] The method may further comprise generating (e.g., by the large language model, as part of the output that includes the code) one or more tests to confirm whether the computer-readable code is well-formed to control the scientific instrument to obtain data from analysis of a sample and / or process the data obtained from analysis of the sample by the scientific instrument.
[0023] The method may further comprise performing the one or more tests on the computer-readable code in a test environment and obtaining test results.
[0024] Performing the one or more tests may comprise simulating execution of the computer-readable code by the controller of the scientific instrument.
[0025] If the test results indicate that the computer-readable code is not well-formed to control the scientific instrument and / or process the data in accordance with the instructions when executed, the method may further comprise: x) modifying the computer-readable code, based on the test results.
[0026] The computer-readable code may be modified based on the test results and further (optionally) based on any error messages generated during performance of the tests.
[0027] Modifying the computer-readable code, based on the test results, may comprise processing the computer-readable code and the test results using the large language model or a second large language model to generate modified computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions.
[0028] In other words, modifying the computer-readable code based on the test results may be performed by loop iterations of the code, its tests and its error messages into the initial LLM. Alternatively (and preferably) modifying the computer-readable code based on the test results may be performed by sending the code, its tests and the relative error messages to a second LLM that specializes in writing code.
[0029] Accordingly, the second large language model may be trained to write code in a particular programming language. For example, the second LLM may be fine-tuned to write python code.
[0030] The proposed methods may use one large language model to generate the code and a different large language model to generate modified computer-readable code, based on the original instructions, original code and the test results. This method may be referred to as ‘downhill’ error handling, as the errors are processed by a different model. This process may be repeated over several iterations. In this way, so-called “adversarial prompting” (in which the different models are competing to generate the best computer-readable code) may be employed to generate the computer-readable code.
[0031] The method may further comprise: y) repeating the one or more tests on the modified computer-readable code in the test environment and obtaining repeat test results. The method may further comprise repeating steps x) and y) until the test results indicate that the computer-readable code is well-formed to control the scientific instrument and / or process the data in accordance with the instructions when executed.
[0032] In this way, recursive internal checking is performed to iteratively confirm that the code is suitable for carrying out the instructions.
[0033] In some examples, the code generation has stochastic aspects. In other words, the same prompt may yield different code if input to the model on different occasions. However, the code will subsequently be tested and modified iteratively, to ensure that it fulfils the instructions. Therefore, the output of the code should be deterministic. In other words, the same prompt on different occasions will generate code that, when executed by the controller, causes the controller to obtain / process data from the scientific instrument in the same way.
[0034] The method may further comprise determining that the instructions are insufficient to generate computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions when executed by the controller of the scientific instrument (i.e., more information is required). The method may further comprise requesting and receiving additional instructions in the natural language for controlling the scientific instrument and / or processing the data (an additional prompt). The method may further comprise processing the instructions and the additional instructions using the large language model to generate modified computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions and the additional instructions.
[0035] As described above, the first large language model may be pre-trained using analytical chemistry methods, SDK documentation and / or communication protocols and available methods. If the user is not able to answer additional questions (for example, “Should the calibrations be done fitting a linear or a quadratic function?”), then the analytical chemistry knowledge of the LLM may be used to answer the question.
[0036] The LLM may be fine-tuned for analytical chemistry and chemometric techniques and may therefore have the ability to ask relevant questions to improve / fix the code. If the user cannot answer them then the LLM would use its chemistry knowledge to make an educated guess.
[0037] The method may further comprise: y) repeating the one or more tests on the modified computer-readable code in the test environment and obtaining repeat test results. The method may further comprise repeating steps x) and y) zero or more times. The method may further comprise determining, based on one or more of the instructions, the computer-readable code, the modified computer-readable code, the test results and the repeat test results, that the instructions are insufficient to generate computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions when executed by a controller of the scientific instrument (i.e., more information is required). The method may further comprise requesting and receiving additional instructions in the natural language for controlling the scientific instrument and / or processing the data (an additional prompt). The method may further comprise processing the additional instructions using the large language model to generate modified computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions and / or the additional instructions.
[0038] The method may reach a certain point where the system determines that more information is required and may then ask the user for an additional or different prompt, and generate modified instructions based on the additional or different prompt.
[0039] The method may further comprise determining that the test results indicate that the computer-readable code is not well-formed due to an error in the one or more tests. The method may further comprise generating (by the large language model, as part of the output) one or more updated tests to confirm whether the computer-readable code is well-formed to control the scientific instrument and / or process the data in accordance with the instructions (based on the instructions, the computer-readable code and the test results). The method may further comprise performing the one or more updated tests on the computer-readable code in a test environment and obtaining updated test results.
[0040] The instructions may comprise one or more examples of: a potential scenario encountered by the controller of the scientific instrument during analysis of a sample and / or processing of the data; and a corresponding explanation of how the controller of the scientific instrument should behave in the scenario.
[0041] The one or more tests may be based on the one or more examples.
[0042] The computer-readable code may comprise a plurality of commands (which may also be referred to as “operations”). Each command may comprise zero or more parameters.
[0043] The commands and / or parameters may come from SDK documentation used to fine tune the LLM.
[0044] A first subset of the plurality of commands may invoke software functions defined in a library associated with a programming language of the computer-readable code (e.g., built-in functions of the programming language or modules imported into the execution environment).
[0045] The computer-readable code may comprise one or more function definitions. A second subset of the plurality of commands may invoke the one or more functions defined in the computer-readable code.
[0046] In some examples, existing functions may be used as inputs to train the large language model.
[0047] There are multiple different embodiments of the proposed methods. In a first embodiment, the large language model produces code that uses existing software functions. In a second embodiment, the large language model produces code that may include software functions. Existing functions may be used as inputs to train the large language model.
[0048] The large language model may comprise additional specialized models (such as vision, audio, or data models) to complete tasks that beyond the core text-based capabilities of the large language model (such as generating code). When a prompt requires a specific type of analysis, like image interpretation, sound processing, or data analysis, the large language model may generate a sub-task tailored for the appropriate model. The specialized model may process the input (e.g., an image, sound, or dataset) and return results to the large language model. The large language model may then integrate these results with its language processing to produce a final, cohesive response. This integration enables the large language model to handle complex, multi-modal tasks by incorporating the strengths of different models.
[0049] The method may further comprise displaying the data and / or processed data in a human-readable format (such as a graphical representation) via a display associated with the controller of the scientific instrument.
[0050] An additional multimodal model (for example, a Vision-language model such as PaLM-E or LLaMa-2 with vision) may receive the generated plots as inputs and may be used to perform one or more of the following tasks: Image Captioning and Descriptions: Generating captions, explaining content, and answering questions about images. Visual Question Answering (VQA): Responding to questions based on specific elements within an image. Code and Diagram Interpretation: Understanding diagrams, code screenshots, or charts, which is valuable for code debugging and engineering tasks.
[0051] The method may further comprise analysing syntax of the computer-readable code and determining that the computer-readable code is well-structured (i.e. contains no syntax errors).
[0052] The step of analysing syntax may be performed by a LLM that specialises in writing code.
[0053] If the code is not well-structured, the method may further comprise providing details of errors in the syntax of the computer-readable code to the large language model and generating updated computer-readable code.
[0054] The method may further comprise obtaining second instructions from a storage medium. The second instructions may comprise a prompt to induce the large language model to generate computer-readable code that is modular and testable. The computer-readable code may be generated based on the instructions and the second instructions.
[0055] In other words, there may be another (non-editable) prompt to the large language model that causes the large language model to generate code that is highly modular and testable. The second instructions may be provided in the natural language.
[0056] The method may further comprise obtaining one or more examples of computer-readable code for controlling the scientific instrument and / or processing the data.
[0057] The computer-readable code may be generated based on the instructions and the one or more examples (and optionally the second instructions, where these are obtained).
[0058] The large language model may be trained using the one or more examples (and corresponding instructions, in accordance with which the controller controls the scientific instrument and / or processes the data).
[0059] In other words, the examples may be provided to the large language model in the prompt and / or may be used for training the model.
[0060] The instructions may be received from a human user.
[0061] Alternatively, the method may further comprise receiving an initial set of instructions from a human user and processing the initial set of instructions using a prompt-generating large language model to generate the instructions in the natural language.
[0062] In other words, the prompt itself may be generated by prompt engineering using a prompt-generating large language model (this process may be referred to as metaprompting).
[0063] In some examples, a detailed prompt may be broken down into many smaller task requests, with some examples of execution and examples of what not to do.
[0064] The method may further comprise processing the instructions using a large language model to generate one or more questions that are presented to a human user in the natural language. The method may further comprise receiving additional instructions in the natural language in response to the one or more questions (an additional prompt). The computer-readable code may be generated based on the instructions and the additional instructions (and optionally the second instructions, where these are available).
[0065] In other words, the method may use chain of thought reasoning to check back with the user after the initial prompt, to ensure that the model has correctly interpreted the instructions. The model may also check back with the user to provide a plan for delivering a solution to the instructions, before generating the code.
[0066] The instructions may be received as a text input or an audio input. In other words, the user may type or speak the instructions.
[0067] Audio instructions may be converted to text using speech-to-text model.
[0068] A controller of a scientific instrument is also provided. The controller may be configured to perform any of the methods described above.
[0069] In some examples, the large language model is integrated with the controller. In other examples, the code may be generated by a large language model running separately from the controller. In some examples, the method may be performed by a server, such as a cloud server. Nevertheless, the user may interface with the server via the controller. For example, the user may provide the instructions to the controller, which may forward the instructions to a server for processing by the large language model, which may return the code to the controller for execution. The server may also obtain additional user prompts via the controller.
[0070] A computer program comprising instructions that, when executed by a processor, cause the processor to perform any of the methods described above is also provided. Brief description of the drawings
[0071] The invention is described with reference to the following non-limiting examples.
[0072] Fig. 1 illustrates a flowchart of a method according to specific examples.
[0073] Fig. 2 illustrates a graph generated as a result of running code according to a specific example.
[0074] Fig. 3 illustrates a flowchart of another method according to specific examples. Detailed description
[0075] Large language models may be used to perform tasks based on instructions provided in a natural language, and a few examples of how to perform the task in different scenarios. The large langue model may apply chain-of-thought reasoning to understand the instructions by decomposing the instructions into discreet steps and then providing a solution for each step. Nevertheless, large language models do not reliably solve the problem first time. Therefore, a way of testing the solution, diagnosing the issues and providing an updated solution is required. An approach for doing so is to generate computer programs for solving each step that are written in code that is both human-readable and computer-readable (e.g., Python). Execution of the code is performed by an interpreter, rather than directly by the large language model. The code provided by the large language model may contain errors, as explained above. However, the code may be subject to iterations of testing and modification so that these errors may be debugged and any problems fixed. This approach may be referred to as a Program-Aided-Language model (PAL model).
[0076] The general idea of Program-Aided-Language models is to: receive a user prompt (a set of instructions for performing a task), use a large language model to decompose the natural language problem into executable steps, generate computer code implementing the steps, and execute the code by a code interpreter and yield a result.
[0077] There may be a range of different large language models that can be used and different models may be more suited to different tasks. The code interpreter is generally fixed and specific to the programming language in which the code is written.
[0078] The proposed methods relate to control of scientific instruments and manipulation of data obtained by analysing samples with the scientific instruments. These methods use a PAL model to interpret natural language instructions from a user and produce code that may be used by a controller of the scientific instrument to execute the instructions. This is a considerably more complex problem than solving abstract problems (e.g., mathematical problems) using a PAL approach.
[0079] In order to generate suitable code for execution by a controller of a scientific instrument, the large language models may be trained using the source code of the instrument control software and firmware (e.g., camera firmware, mother board firmware, and the like). Moreover, in order to solve the specific problems that arise during manipulation of data from analysis of samples by the scientific instrument, the large language models may also be trained using additional software (including third-party plug in software and firmware, instrument control software, and research software for performing tailored mathematical and signal / image processing operations), documentation for the additional software, application notes, internal documents describing the workflows, and the like.
[0080] In order to provide a solution to the instructions, a pretrained large language model (such as Llama3 from Meta or Mistral models) may be used. The pretrained large language model may be trained to interpret instructions in the natural language (human language e.g., English, French, German, etc.) and output code in the required programming languages (e.g., C#, Python, etc.). The large language model may also be fine-tuned to learn the information that is specific to the controller of the scientific instrument in question. In this way, the proposed methods may be implemented using known large language models and PAL models and using these to generate computer-readable code for execution by a controller of a scientific instrument.
[0081] For simplicity, it may be assumed that the large language model can generate code in different programming languages (e.g., C#, Python, etc.). In practice, however, the large language model may be trained to use a specific language, depending on the scenario (see below).
[0082] In the following description of three examples, the proposed methods and workflow are described at a high level.
[0083] The first example illustrates how a simple process is enacted in accordance with the proposed methods and includes the following steps:
[0084] Step 1: A user writes or says what they want to accomplish (e.g., “find out if there are samples where the same repetition failed for all wavelengths and change acquisition to immediately repeat that sample acquisition”, or “give me a plot that shows all overlapping measured intensities for the run that failed”).
[0085] Step 2: The large language model understands the requests (the “prompt”) and has learned the complete corpus that makes up the controller software code.
[0086] Step 3: The large language model generates the code (e.g., python code) that will be provided to the controller for execution. This may be achieved using a scripting interface of the controller or by compiling the code to a package (e.g., a dynamic-link library, “dll”) that make use of a third-party plugin API of the controller (e.g., the “3rd Party PluginAPI” of the “Qtegra” software by Thermo Fisher Scientific).
[0087] Step 4: The code is transferred to the controller and executed.
[0088] Step 5: The user sees the output of the execution of the code via a display of the controller.
[0089] In a second example in accordance with the proposed methods, steps 1 and 2 from the first example are unchanged and the method further includes the following steps:
[0090] Step 3: The large language model generates a second prompt based on the user request and sends the second prompt to a second model to generate the code (e.g., python code). The generated code is suitable for execution within a suitable execution environment.
[0091] Step 4: The results are calculated directly inside a suitable execution environment (e.g., a python environment), including any required plotting and visualisation functions. The results are sent to the controller (or a third party software) for export and display to the user.
[0092] The first two embodiments are illustrated with reference to Fig. 1, which illustrates a flowchart of a method according to specific examples. At step 100, a user writes a natural language prompt on text interface to the large language model. Where the prompt comprises instructions.
[0093] At step 101, one of two possible options is selected, either option 102, or option 103.
[0094] At step 102, the large language model elaborates the instructions and outputs code to execute the prompt.
[0095] Alternatively, at step 103, the large language model elaborates the instructions and outputs a meta-prompt, which is passed to the trained large language model to generate suitable code to execute the prompt.
[0096] In either case, at step 104, the code is copied into a scripting platform for execution.
[0097] At step 105, the scripting platform runs the script, thereby executing the initial user prompt.
[0098] A third example in accordance with the proposed methods is provided to handle a complex request that requires the use of a multimodal approach (e.g., text plus images). Steps 1 and 2 from the first example are unchanged and the method further includes the following steps:
[0099] Step 3: The large language model generates a second prompt based on the user request and sends the second prompt to a sequence of models that are used to solve the request of the costumer.
[0100] Step 4: The generated sequential code using multiple models will be executed (e.g., in python).
[0101] Step 5: The customer will see the output of execution of the code via a display of the controller.
[0102] In the following description, the proposed methods and workflow are described in more detail. For the first scenario, instrument control software is used in conjunction with the code generated by the large language model. In a second scenario, the code generated by the large language model may be used to completely replace the controller software solution with a minimal framework. Scenario 1
[0103] As described above, some instrument control software packages provide the ability to run user defined scripts. In order to prepare suitable scripts, a user needs to be familiar with programming in the required language (e.g., C#) and with internal structures of the instrument control software. To allow users to generate scripts without the need for this detailed knowledge and understanding, the proposed methods may train the large language model with the internal structures of the instrument control software (in addition to already being trained to use the programming language)
[0104] An example workflow according to a specific example of the proposed method for a user (such as an R&D Scientist) to generate a script is enumerated in the following steps:
[0105] Step 1: The user opens a small application providing an interface to the large language model and describe (write) what the user wants to accomplish. For example, the user may want to perform some specific measurements with custom acquisition time and compute the statistics of that measurement.
[0106] Step 2: The large language model understands the requests and has learned the complete corpus that makes up the code of the controller.
[0107] Step 3: The large language model produces C# code that includes the required style and structures of scripts.
[0108] Step 4: The script is provided to the controller (e.g., into a scripting editor of the controller), which also provides syntax checking and, when no errors have been detected, runs the script.
[0109] In some examples, the large language model provides the code to the user, who then copies it to the scripting editor of the controller. This may enable advanced users to check the code manually before running it. Alternatively, the large language model may provide the code directly to the controller. Advantageously, manual user interaction would then not be required, other that providing the initial instructions (“prompt”). This may be preferable for users that are not familiar with the internal workflows of the controller. Scenario 2
[0110] The proposed methods may be used to extend the capabilities of the instrument control software by adding the possibility to run user-generated scripts, as an extension of the software package. To enable this, the framework of the controller may be extended as follows: based on APIs already included in the controller software, the option to run scripts (e.g., Python scripts) may be added to the software by using an approach suitable for the specific programming language used for the controller software. For example, in case of “Qtegra” controller software by Thermo Fisher Scientific, which is written in C#, IronPython may be used to execute Python scripts. With this, the workflow would be as follows:
[0111] Step 1: The user writes or says what they want to accomplish (e.g. “find out if there are samples where the same repetition failed for all wavelengths and change acquisition to immediately warn the user that something is wrong in the sample introduction system, possibly giving hints on how to fix it / trouble shoot it, repeat that sample acquisition”, or “give me a plot that shows all overlapping measured intensities for the run that failed”).
[0112] Step 2: The large language model understands the requests and has learned the complete corpus that makes up the controller software code.
[0113] Step 3: The large language model generates the code (e.g., python code) that uses internal interfaces or APIs that the instrument control software provides. An example would be to create a control command in Python that triggers an acquisition of a full frame or changes hardware parameters to a desired state.
[0114] Step 4: The code is automatically extracted and stored in a separate script (e.g., a Python script). This script is executed (e.g., using IronPython) and generates results. Recursive internal checkinci
[0115] Large language models sometimes generate code that contains errors. For example, it is possible for large language models to experience “hallucination” (e.g., the model may generate code that does not achieve the desired output or uses functions that do not exist). Other known large language model issues may also arise when generating code based on instructions, especially is the user is not familiar with large language model prompt engineering. In particular, errors are more likely if a user provides “zero-shot” prompting (where no examples are provided) or “one-shot” prompting (where only one example is given on how to execute the prompt).
[0116] Moreover, the code produced by a large language model may also contain syntax errors, such as missing symbols like or “}”, wrong arguments for methods (especially when parameter names are very short) or hallucinates complete methods and packages.
[0117] Finally, there could be logic errors in the code so that the code does not correctly execute or solve the task provided in the instructions.
[0118] Preferably, the problems described above may be dealt with automatically, rather than raising error messages that are caused by these problems to the user. Therefore, several strategies are provided to handle such errors.
[0119] In a first strategy, the large language model receives an additional set of instructions (not changeable by the user) that prompts the large language model to use the chain-of-thought method and to only generate code that is highly modular and testable. The additional instructions are provided to the large language model alongside the instructions from the user.
[0120] In a second strategy, the large language model is instructed to always create unit tests for the code it generates. The unit tests are run in a separate environment and the output (pass, fail, or some kind of error) is returned to the large language model. Based on the results, the large language model changes / extends the code to address failed tests or coding errors and only returns code that passes all the tests.
[0121] In a third strategy, another way to implement a self-checking workflow is to allow for an internal cycle of few-shot-prompting, where historic coding examples (from the existing customer facing software) are provided.
[0122] In a fourth strategy, methods may employ ‘downhill’ error handling, using adversarial prompting between different large language models. For example, if the user prompt yields a certain code output which, when executed, causes an error message. This error message may be provided to another (or multiple) large language model agent that understands the error and tries a new approach. This process may be repeated until no error message is generated (or the agent requests more information to the user if it is unable to produce code that passes all the tests).
[0123] In a fifth strategy, the quality of the prompt may be improved so that less errors are encountered. This may be achieved with so-called “metaprompting”. Metaprompting interprets the natural language query (with a first large language model, which may be referred to as a “prompt-generating large language model”) and outputs a second prompt, engineered to best prompt the large language model responsible for generating the code. For example, a more detailed prompt broken down into a lot more smaller task requests, with some examples of execution and examples of what not to do.
[0124] Finally, in a sixth strategy for a more interactive approach, chain of thought reasoning could be used to check back with the user after the initial prompt if the large language model has correctly understood the instructions and whether a strategy developed by the large language model for delivering a solution is approved by the user.
[0125] Also, a combination of all the approaches above can be used for recursive internal checking. Data preprocessing &training
[0126] As mentioned above, the large language model may be trained / fine-tuned to include the complete corpus of the controller code (i.e., methods, functions and variable names etc). As a result, the large language model may generate code that seamlessly uses the built-in methods, functions and variables of the controller software. In addition, the large language model may also be trained / fine-tuned with Camera Firmware code and board firmware (e.g. for Inductively coupled plasma optical emission spectroscopy).
[0127] Due to the complexity of the controller software and some of the programming languages in which some software is written (e.g., C#). Alternative programming languages (e.g., Python) may be used in the examples described in this disclosure to provide a practical implementation of the methods. Nevertheless, use of these programming languages (e.g., Python) are only intended as specific examples and the invention is not limited to the programming languages described in these specific examples. The large language model may be trained / configured to output code in any suitable programming language, depending on what is most suitable for the application (and for the controller).
[0128] In the agentic design of this large language model, different fine-tuning material can be used for different agents. For example, if the agent prompt is “you are an expert analytical chemist, aware of all standard operating procedures in this CLT”, the fine-tuning data may consist of all standard operating procedure documents of that lab and the fundamentals of analytical chemistry and the agent is both an expert programmer for the specific controller (e.g., Qtegra) and an expert lab manager for the laboratory the user works in. If the prompt is “you are an expert auditing officer for ISO 6001 in an environmental laboratory” the fine-tuning material may be the ISO6001 regulation plus the practical implementations on QA QC of such regulation in the specific laboratory that is being audited.
[0129] The Program Aided Language model (PAL) may use a pretrained large language model to read (or listen to) natural language questions (asked by the user). For example, the user may provide instructions such as, “I want to exclude intensities that are outside of the linearity range based on my latest calibration”. The Program Aided Language model may then generate programs (e.g., the python code provided below) as the intermediate reasoning steps. The actual computation of the generated code may be off-loaded to the controller runtime or to a third-party runtime. import pandas as pd import numpy as np from sklearn.linear_model import LinearRegression import matplotlib.pyplot as pit # Define the function for the calibration curve def calibration_curve(x, y): model = LinearRegression() .fit (x, y) return model # Apply the function to customer data x = calibration_data['concentration']. values . reshape(-1, 1) y = calibration_data['intensity']•values model = calibration_curve(x, y) # Calculate limit of detection (LOD) LOD = 3 * np.std(calibration_data['intensity'][calibration_data['concentratio n'] == 0]) # Find the linearity range linearity_range = calibration_data[(calibration_data['intensity'] >= LOD) &(calibration_data['intensity'] <calibration_data['intensity'] . max())] # Generate synthetic unknown sample data unknown_samples = pd.DataFrame({'concentration': [50, 150], 'intensity': [500, 1500]}) # Evaluate unknown samples def evaluate_sample(sample, model, linearity_range) : predicted_concentration = model. predict(np. array ([sample['intensity']]) . reshape(-1, 1)) if predicted_concentration < linearity_range['concentration'] .min () or predicted_concentration >linearity_range['concentration'] .max () : dilution_factor = predicted_concentration / linearity_range['concentration'] .max () raise ValueError(f"Sample is too concentrated for your calibration! Please dilute by {dilution_factor}") else : return predicted_concentration # Apply the function to our unknown samples for i, sample in unknown_samples.iterrows(): try: print(evaluate_sample(sample, model, linearity_range)) except ValueError as e: print(e) # Plot the calibration curve and unknown samples pit. scatter (calibration_data['concentration'], calibration_data['intensity']) pit. plot(calibration_data['concentration'], model. predict(x) , color='blue') pit. scatter(unknown_samples['concentration'], unknown_samples['intensity'], color='red') pit.xlabel('Concentration') pit.ylabel('Intensity') pit. show ()
[0130] The code is generated by the large language model. However, the actual execution of the generated code is off-loaded to the runtime of the controller, which takes the calibration data and the new acquisition data, runs the code and displays the result according to the generated plotting functions. One example of a plot generated by the above code is illustrated in Fig. 2. The processed data may be output in a variety of forms, in addition to plotted graphs. The processed data may be output via a display in communication with the controller.
[0131] The code may also cause the controller to output instructions to the user for progressing the workflow. For example, the controller may display the following message: Sample 2 is too concentrated! Please dilute by 1.6 times and re-acquire
[0132] In contrast to prior art solutions, which simply allow custom scripts to be executed by the controller (but the scripts would need to be custom made on a users’ behalf as it is highly unlikely the user would have the expertise to prepare their own), the proposed methods make it possible for users to create new software features, without knowing how to code or having intimate knowledge of the inner workings of the controller and instrument. The proposed methods use a large language model to perform the logical reasoning required to convert a simple English text request and the code to execute it.
[0133] Fig. 3 illustrates a flow diagram of a method according to some examples. At step 301, a customer request is provided to the large language model. At step 302, the request is processed by a speech or text interpreter to provide written instructions in a natural language. At step 303, the written instructions are provided to a large language model. Optionally, the large language model may request and receive additional instructions from the user (e.g., to confirm chain of thought reasoning). At step 304, the large language model generates code. At step 305, the customer-facing software on the controller executes the code generated by the large language model. At step 306, a display associated with the controller displays the desired output. At step 307, further input may be obtained from the user for display / evaluation preferences (i.e., inputs to the code executed on the controller, rather than instructions to the large langue model for generating the code).
[0134] Advantageously, users may be able to quickly and easily implement new solutions to practical problems, where those solutions were not previously possible using the existing controller software. The solutions may be implemented as new software features by executing code generated by a large language model, which prepares the code based on instructions provided by the user in a natural language. The user may therefore only have to express in plain language the problem they want to solve, and the large language model may first generate the logical reasoning to code a program, then provide the program to the controller for execution to obtain / display / export / report the data obtained from analysis of a sample with the scientific instrument.
[0135] Users (scientists operating the scientific instrument) may have more control over the algorithms that are executed by the controller of the instrument, without having to wait for implementation of requested features in the production code environment of the controller. This may also result in an improvement in flexibility and transparency of the functions used in the code executed by the controller, which may facilitate better debugging of the code if errors occur.
[0136] The proposed methods may also be used to program new acquisition workflows (e.g. time resolved), to program plug-ins for custom autosamplers and other third-party appliances.
[0137] The proposed methods could further be used to consolidate and document the existing code, by training the large language model using the existing production code of the controller (the controller software corpus).
[0138] Fig. 4 illustrates a flowchart of an example method of generating computer-readable code executable by a controller of a scientific instrument. The method comprises: at step 401, receiving instructions in a natural language. at step 402, processing the instructions using a large language model to generate computer-readable code executable by the controller of the scientific instrument to: control the scientific instrument to obtain data from analysis of a sample; and / or process the data obtained from analysis of the sample by the scientific instrument.
[0139] Although specific embodiments have now been described, the skilled person will understand that various modifications and variations are possible. For example, whilst the disclosure is described in relation to existing scientific instruments and control systems, it will be understood that changes to the instruments and systems (and / or nomenclature) are possible, but the present disclosure may still be applicable in this case. All of the features disclosed herein may be combined in any combination, even if that combination has not been explicitly detailed, except combinations where at least some of such features and / or steps are mutually exclusive. In particular, the preferred features of the invention are applicable to all aspects of the invention and may be used in any combination. Likewise, features described in non-essential combinations may be used separately (not in combination).
[0140] The examples may be carried out on any suitable data processing device, such as a personal computer, laptop, mobile telephone, server, virtual machine, and the like. The above description of the systems and methods has been simplified for purposes of discussion, and is intended to provide a specific example to illustrate the invention. Different types of systems and methods may be used, as will be appreciated by the skilled person. It will be appreciated that the boundaries between logic blocks are merely illustrative and that alternative embodiments may merge logic blocks or elements, or may impose an alternate decomposition of functionality upon various logic blocks or elements.
[0141] It will be appreciated that the above-mentioned functionality may be implemented as one or more corresponding modules as hardware and / or software. For example, the above-mentioned functionality may be implemented as one or more software components for execution by a processor of the system. Alternatively, the above-mentioned functionality may be implemented as hardware, such as on one or more FPGAs, and / or one or more ASICs, and / or one or more DSPs, and / or other hardware arrangements. Method steps implemented in flowcharts contained herein, or as described above, may each be implemented by corresponding respective modules. Moreover, multiple method steps implemented in flowcharts contained herein, or as described above, may be implemented together by a single module.
[0142] Examples may be implemented by computer software or a “computer program.” A storage medium and a transmission medium carrying the computer software are also provided. The computer software may comprise one or more instructions, or code, that, when executed by a computer, causes the methods described to be performed. Computer software may be a sequence of instructions designed for execution on a computer system, and may include a subroutine, a function, a procedure, a module, an object method, an object implementation, an executable application, an applet, a servlet, source code, object code, a shared library, a dynamic linked library, and / or other sequences of instructions designed for execution on a computer system. The storage medium may be a magnetic disc (such as a hard drive or a floppy disc), an optical disc (such as a CD-ROM, a DVD-ROM, or a Blu-ray disc), or a memory (such as a ROM, a RAM, EEPROM, EPROM, Flash memory or a portable / removable memory device), etc. The transmission medium may be a communications signal, a data broadcast, a communications link between two or more computers, etc.
[0143] The computer program may be configured to control a network entity and / or mobile device to perform any method according to the disclosure. A network entity of a telecommunications network (e.g., a cellular network) may also be provided, configured to operate in accordance with certain methods disclosed herein. For example, the network entity may include a processor and at least one communication interface, particularly comprising one or both of a transmitter and receiver. A mobile device (e.g., UE) may also be provided, configured to operate in accordance with certain methods disclosed herein. The mobile device may likewise include a processor and at least one communication interface, particularly comprising one or both of a transmitter and receiver.
[0144] Each feature disclosed in this specification, unless stated otherwise, may be replaced by alternative features serving the same, equivalent, or similar purpose. Thus, unless stated otherwise, each feature disclosed is one example only of a generic series of equivalent or similar features.
[0145] It will be understood that, although the terms “first”, “second”, etc. may be used herein to describe various elements, these elements should not be limited by these terms. These terms are only used to distinguish one element from another. For example, a first element could be termed a second element, and, similarly, a second element could be termed a first element, without departing from the scope of the present invention. As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0146] As used herein, including in the claims, unless the context indicates otherwise, singular forms of the terms herein are to be construed as including the plural form and vice versa. For instance, unless the context indicates otherwise, a singular reference herein including in the claims, such as "a" or "an" (such as a mobile device, a network entity, a step, a parameter, or a message) means "one or more” (for instance one or more mobile devices, one or more network entities, one or more steps, one or more parameters, or one or more messages). Throughout the description and claims of this disclosure, the words "comprise", "including", "having" and "contain" and variations of the words, for example "comprising" and "comprises" or similar, mean "including", and are not intended to (and do not) exclude other components.
[0147] The use of any and all examples, or exemplary language ("for instance", "such as", "for example" and like language) provided herein, is intended merely to better illustrate the invention, and does not indicate a limitation on the scope of the invention unless otherwise claimed. No language in the specification should be construed as indicating any nonclaimed element as essential to the practice of the invention.
[0148] Any steps described in this specification may be performed in any order or simultaneously unless stated or the context requires otherwise. Moreover, where a step is described as being performed after a step, this does not preclude intervening steps being performed.
[0149] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. It will be further understood that terms used herein should be interpreted as having a meaning that is consistent with their meaning in the context of this specification and the relevant art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
[0150] Like numbers refer to like elements throughout. Thus, the same or similar numbers may be described with reference to other drawings even if they are neither mentioned nor described in the corresponding drawing. Also, elements that are not denoted by reference numbers may be described with reference to other drawings.
[0151] A method of manufacturing and / or operating any of the devices disclosed herein is also provided. The method may comprise steps of providing each of the features disclosed and / or configuring or using the respective feature for its stated function.
[0152] In the drawings and specification, there have been disclosed typical embodiments of the invention and, although specific terms are employed, they are used in a generic and descriptive sense only and not for purposes of limitation, the scope of the invention being set forth in the following claims.
Claims
1. A method of generating computer-readable code executable by a controller of a scientific instrument, the method comprising:receiving instructions in a natural language; andprocessing the instructions using a large language model to generate computer-readable code executable by the controller of the scientific instrument to:control the scientific instrument to obtain data from analysis of a sample.
2. The method of claim 1, wherein execution of the computer-readable code further causes the controller of the scientific instrument to:process the data obtained from analysis of the sample by the scientific instrument.
3. The method of claim 1 or claim 2, further comprising:controlling the scientific instrument by executing the computer-readable code.
4. The method of any preceding claim, further comprising:generating one or more tests to confirm whether the computer-readable code is well-formed to control the scientific instrument to obtain data from analysis of a sample and / or process the data obtained from analysis of the sample by the scientific instrument.
5. The method of any preceding claim further comprising:performing the one or more tests on the computer-readable code in a test environment and obtaining test results.
6. The method of claim 5, wherein, if the test results indicate that the computer-readable code is not well-formed to control the scientific instrument and / or process the data in accordance with the instructions when executed, the method further comprises:x) modifying the computer-readable code, based on the test results.
7. The method of claim 6, wherein modifying the computer-readable code, based on the test results, comprises:processing the computer-readable code and the test results using the large language model or a second large language model to generate modified computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions.
8. The method of claim 6 or claim 7, further comprising:y) repeating the one or more tests on the modified computer-readable code in the test environment and obtaining repeat test results; andrepeating steps x) and y) until the test results indicate that the computer-readable code is well-formed to control the scientific instrument and / or process the data in accordance with the instructions when executed.
9. The method of claim 6 or claim 7, further comprising:y) repeating the one or more tests on the modified computer-readable code in the test environment and obtaining repeat test results;repeating steps x) and y) zero or more times; anddetermining, based on one or more of the instructions, the computer-readable code, the modified computer-readable code, the test results and the repeat test results, that the instructions are insufficient to generate computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions when executed by a controller of the scientific instrument;requesting and receiving additional instructions in the natural language for controlling the scientific instrument and / or processing the data; andprocessing the additional instructions using the large language model to generate modified computer-readable code to control the scientific instrument and / or process the data in accordance with the instructions and / or the additional instructions.
10. The method of any of claims 6 to 9, further comprising:determining that the test results indicate that the computer-readable code is not well-formed due to an error in the one or more tests;generating one or more updated tests to confirm whether the computer-readable code is well-formed to control the scientific instrument and / or process the data in accordance with the instructions;performing the one or more updated tests on the computer-readable code in a test environment and obtaining updated test results.
11. The method of any preceding claim, wherein the instructions comprise one or more examples of:a potential scenario encountered by the controller of the scientific instrument during analysis of a sample and / or processing of the data; anda corresponding explanation of how the controller of the scientific instrument should behave in the scenario.
12. The method of any preceding claim, wherein the computer-readable code comprises a plurality of commands and wherein each command comprises zero or more parameters.
13. The method of claim 12, wherein a first subset of the plurality of commands invoke software functions defined in a library associated with a programming language of the computer-readable code.
14. The method of claim 12 or claim 13, wherein the computer-readable code comprises one or more function definitions, wherein a second subset of the plurality of commands invoke the one or more functions defined in the computer-readable code.
15. The method of any preceding claim, further comprising:displaying the data and / or processed data in a human-readable format via a display associated with the controller of the scientific instrument.
16. The method of any preceding claim, further comprising:analysing syntax of the computer-readable code and determining that the computer-readable code is well-structured.
17. The method of any preceding claim, further comprising:obtaining second instructions from a storage medium, wherein the second instructions comprise a prompt to induce the large language model to generate computer-readable code that is modular and testable,wherein the computer-readable code is generated based on the instructions and the second instructions.
18. The method of any preceding claim, further comprising:obtaining one or more examples of computer-readable code for controlling the scientific instrument and / or processing the data,wherein the computer-readable code is generated based on the instructions and the one or more examples, and / orwherein the large language model is trained using the one or more examples.
19. The method of any preceding claim, wherein the instructions are received from a human user.
20. The method of any of claims 1 to 18, further comprising:receiving an initial set of instructions from a human user; andprocessing the initial set of instructions using a prompt-generating large language model to generate the instructions in the natural language.
21. The method of any preceding claim, further comprising:processing the instructions using a large language model to generate one or more questions that are presented to a human user in the natural language;receiving additional instructions in the natural language in response to the one or more questions; andwherein the computer-readable code is generated based on the instructions and the additional instructions.
22. The method of any preceding claim, wherein the instructions are received as a text input or an audio input.
23. A controller of a scientific instrument, wherein the controller is configured to perform the method of any preceding claim.
24. A computer program comprising instructions that, when executed by a processor, cause the processor to perform the method of any of claims 1 to 22.