Hybrid quantum algorithms are prominent in the quantum computing world, and extensive research has focused on hybrid schemes to harness the power of quantum computers. Notable examples include QAOA, VQE, QNN, and more. At their core, hybrid algorithms involve an iterative process alternating between classical and quantum computation, where the latter is manifested in the form of sampling quantum circuits, yielding measured state counts.
At Classiq, we provide a method for designing, debugging and executing hybrid algorithms that is both straightforward and efficient. Our Python SDK features the 𝘌𝘹𝘦𝘤𝘶𝘵𝘪𝘰𝘯𝘚𝘦𝘴𝘴𝘪𝘰𝘯 class, which enables the execution (both on simulators and real hardware) of a complex hybrid algorithm on a single quantum program, typically parametrized. This approach facilitates the iterative process and allows multiple calls to execution primitives at a minimal overhead, as the execution session preserves relevant context across iterations. For instance, the quantum program is being transpiled to the target hardware just once.
The execution primitives currently include 𝘴𝘢𝘮𝘱𝘭𝘦, the fundamental building block of quantum computation, and 𝘦𝘴𝘵𝘪𝘮𝘢𝘵𝘦, which calculates the expectation value of a specific Hamiltonian. The 𝘦𝘴𝘵𝘪𝘮𝘢𝘵𝘦 primitive is itself a hybrid algorithm which can be implemented by a series of samples, but is included as a primitive due to its vast applicability. Additionally, on statevector simulators, the expectation value can be computed exactly without sampling, improving both execution speed and accuracy. Each primitive also has a 𝘣𝘢𝘵𝘤𝘩_ variant that allows processing multiple sets of parameters in a single job, and a 𝘴𝘶𝘣𝘮𝘪𝘵_ variant that returns the job object immediately without waiting for results.
Now, let’s implement something interesting! In the following little example, a parametric quantum model prepares a state with probability 1/8 for all states except the states |010> and |110>, whose probabilities are controlled via an execution parameter. The method 𝘌𝘹𝘦𝘤𝘶𝘵𝘪𝘰𝘯𝘚𝘦𝘴𝘴𝘪𝘰𝘯.𝘴𝘢𝘮𝘱𝘭𝘦() is used to sample the distribution for different rotation parameter values.