Extended Quantum Computing Patterns
Quantum Module
Aliases: –
Tags:
© IARIA, 2023
Intent
How can the implementation of the quantum part of a quantum algorithm be packaged for reuse independent of concrete input values?
Context
Each quantum algorithm is a hybrid algorithm, i.e., parts of the algorithm require quantum computers and other parts require classical computers for their execution. For the execution of the quantum part, a quantum circuit implementing the required operations is needed. However, quantum circuits are problem-specific and, thus, depend on various inputs, e.g., the problem instance or initial values for parameterized quantum gates, which are then optimized by a classical optimizer. Therefore, the implementation of the quantum part of a quantum algorithm must be input-agnostic in order to be reusable.
Forces
Quantum circuits to be processed by a quantum computer must already contain all appropriately encoded input values. A static implementation of a quantum circuit that does not allow the quantum circuit to be changed based on some input values cannot be reused to solve different problems. Thus, a reusable implementation of the quantum part of a quantum algorithm needs to be able to adapt the quantum circuit to different input values. The input values that need to be encoded in a quantum circuit are, first, the problem to be solved, e.g., an implementation of Shor’s algorithm [Shor 1997] would require as input the number to be factored into primes, and second, parameters used for optimization or machine learning, e.g., for QAOA [Weigold et al. 2021].
Moreover, implementing the quantum part of a quantum algorithm requires in depth knowledge of quantum computing and the underlying mathematical concepts. Thus, quantum computing experts are required in the development teams. However, other parts of the algorithm that only require classical computation, e.g., classical optimizers, may not require quantum computing knowledge at all and can be implemented by different teams without a quantum computing expert.
Solution
Separate the implementation of the quantum part of the quantum algorithm into one or more quantum modules. These modules contain the code that generates quantum circuits based on input values provided to the module. Quantum modules can also be used to reduce the number of code duplicates by implementing common parts of a quantum circuit as a reusable Quantum Module.
The solution sketch depicts that a quantum module receives input values and uses generative code to construct quantum circuits depending on these input values. This ensures the reusability of the quantum module, as the implementation can create quantum circuits for different problem sizes as well as parameters.
Result
A quantum algorithm implementation is partitioned into (i) quantum modules containing the implementations of the quantum part, and (ii) additional classical code required for the control flow and other classical computations of the quantum algorithm. The quantum modules are independent of the concrete input values, which increases their reusability for different quantum algorithm implementations.
The separation of code that generates quantum circuits into quantum modules can thus also be reflected in the organizational structure of the development teams. Only the teams working on the quantum modules need quantum computing experts, while other teams mainly need experts in classical software engineering.
Examples
–
Related Patterns
A Quantum Module generating specific quantum circuits for a quantum algorithm can be used inside a Hybrid Module that contains the implementation of the overall quantum algorithm with its quantum and classical parts. Quantum circuits generated by a Quantum Module can be integrated into a Quantum Module Template to create a complete quantum circuit, if the Quantum Module only generates a part of a quantum circuit. The boundary of a Quantum Module is directly corresponding to the Quantum-Classic Split. The Quantum-Classic Split pattern states, that there is necessarily a separation – a split – between code executed on classical computers and code executed on quantum computers. Thus, the Quantum Module pattern is related to this pattern.
Known Uses
Quantum Modules can already be found in several libraries for building quantum circuits. In Amazon Braket, the Grover algorithm [Grover 1996] is offered as a module with functions to build the oracle and execute the Grover search. Another example of a Quantum Module for creating oracles is the PhaseOracle in Qiskit. Generic parts used in multiple quantum algorithms, such as the quantum fourier transformation used in Shor’s algorithm [Shor 1997] are available in Amazon Braket and Qiskit. The quantum phase estimation, which is also part of Shor’s algorithm can be constructed in Qiskit with the PhaseEstimation module.