Extended Quantum Computing Patterns
Classical-Quantum Interface
Aliases: –
Tags:
© IARIA, 2023
Intent
How can a quantum algorithm implementation be used by developers without quantum computing knowledge?
Context
Using a quantum algorithm implementation often requires in depth quantum computing knowledge. For example, the Grover search algorithm requires that the user provides a quantum circuit for the missing oracle [Grover 1996]. Other algorithms, like QAOA, require choosing an ansatz, which also requires quantum computing knowledge [Cerezo et al. 2021][Weigold et al. 2021]. However, software developers who want to integrate a quantum algorithm implementation into an application have a deep understanding of the problem domain rather than deep knowledge of quantum computing.
Forces
To integrate a quantum algorithm implementation into an application, a compatible interface is required. A Hybrid Module already provides an interface enabling its integration into applications, however, using this interface may still require considerable quantum computing knowledge. For example, it may require the problem instance to be provided in the form of a behavior input to the quantum part of an algorithm, or it may have parameters that otherwise influence the quantum part, e.g., by enabling certain error mitigation methods. The effects of the changes, e.g., on resource requirements or runtime, are difficult to estimate without knowledge of quantum computers. Thus, to facilitate the integration of quantum algorithms by problem-domain experts without quantum computing knowledge, such an interface is not sufficient.
Solution
Use a Classical-Quantum Interface that hides the quantum implementation details. Inputs can be provided to the interface in formats specific to the problem domain. These problem domain-specific inputs are internally converted into inputs in the formats required by the implementation of the quantum part.
The documentation of interface inputs that affect the quantum part requires special consideration, since understanding their impact on algorithm execution is important information when integrating the quantum algorithm implementation. Thus, the impact of these inputs on the algorithm should be documented in a comprehensible and easily understandable manner by the interface developer. For example, a parameter that increases the accuracy of the result, but also increases the number of gates in the generated circuits, which can result in increased errors with current quantum computers, could be documented as follows:
“Increasing this parameter can increase the accuracy of the result. However, it also increases the probability of computation errors accumulating, which can negate any improvement in accuracy.“
The sketch shows the interaction of a classical program with a quantum algorithm implemented as a Hybrid Module through a ClassicalL-Quantum Interface. It transforms the problem domain-specific input of the classical program into the inputs required by the quantum algorithm. This interface can also be integrated directly into the Hybrid Module.
Result
The quantum algorithm implementation can be utilized using a Classical-Quantum Interface. Problem domain experts can make use of this quantum algorithm implementation through the Classical-Quantum Interface created for their domain. The knowledge required to utilize the algorithm implementation is presented in the interface documentation, and the format of input parameters is familiar to problem-domain experts.
Examples
–
Related Patterns
The Classical-Quantum Interface enables the integration of quantum algorithm implementations into applications. It can be used as an interface for a quantum algorithm implemented as a Hybrid Module. This interface provides a bridge between the different programming paradigms separated by the Quantum-Classic Split. It is a special kind of Facade [Gamma et al. 1994] for quantum algorithms that not only hides the complexity of the algorithm, but also translates between the quantum computing domain and the problem domain.
[Gamma et al. 1994] E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns: Elements of Reusable Object-oriented Software. Addison-Wesley, 1994.
Known Uses
Domain-specific libraries for quantum computing are among the first having implemented this pattern. Examples for already implemented Classical-Quantum Interfaces can be found in the chemistry domain in Qiskit Nature, Amazon Braket, and Q#. They offer transformation modules that map the electronic structure of molecules to qubits. Furthermore, Qiskit provides a finance module enabling portfolio optimization by implementing a transformer that takes a generic optimization problem as input and outputs a cost operator that can be used in a quantum algorithm. As many classical problems can be formulated as such an optimization problem, this can be used as a Classical-Quantum Interface for different problem domains.