Step 1. Setup: import Haiqu and initialize your session
We begin by importing the Haiqu SDK and some utility functions, along with Qiskit and Matplotlib.Step 2. Bulding the first algorithm prototype
Let’s begin by putting together the first attempt at the quantum circuit implementing our data loading + QFT task, for the moment only using standard Qiskit tools (with which the Haiqu SDK is perfectly integrated). We choose the number of qubits to encode the sinusoidal signal, and generate a random mixture of sinusoids to use as input data.Step 3. Testing the prototype on an ideal simulator
Now that we’ve built our full circuit prototype, we can execute it using Haiqu. You can run circuits on real QPU hardware, hardware noise simulators, or ideal (noiseless) simulators. If possible, it is always a good practice to start by running on a noiseless simulator, to verify the expected frequency output.Step 4. Testing the prototype on a noisy simulator
So far, so good. But we’d like to run our algorithm on a quantum computer, which is inevitably noisy. Before executing on real QPU (which is costly!), let us test our prototype using a noisy simulator. This helps to estimate how well the circuit might perform under realistic conditions. Here, we use thefake_sherbrooke backend — a simulated model of an actual device — to evaluate our circuit’s robustness to noise.
Step 5. Analyzing the prototype circuit with Haiqu tools
In order to improve the algorithm we first need to understand what the main culprit of the poor circuit performance in the presence of noise is. We can use Haiqu’s analysis tools to inspect the circuit:Step 6. Building a reduced circuit with Haiqu’s vector loading
Since our original circuit is too large — and signal encoding, i.e. preapring the input state for QFT, is a major contributor to its size — we can switch to using Haiqu’s vector loading, which generates a much more compact circuit to represent the same input state. This significantly reduces the number of gates while preserving high fidelity, as we shall see.Step 7. Verifying the performance of the optimized circuit on a noisy simulator
Let’s now run the new, optimized circuit (reduced using vector loading) on the same noisy simulator with the same number of shots and compare the results.Step 8. Setting up the physical QPU backend
Now that we’ve obtained satisfactory results on the noisy simulator, we can try running the same circuit on a real quantum processor (QPU) to see how it performs in practice. Here, we configure the backend using Haiqu’s support for IBM Quantum, specifying the target device and API credentials. For better privacy, it is possible to generate a temporary token for IBM Quantum locally so that you don’t haveneed to provide the permanent API key. For this use theget_ibmq_temporary_token function from Haiqu SDK. Note, that temporary token function is only available for jobs launched via IBM Quantum. Should you want to run your workloads via IBM Cloud, make sure to create an API key via the IBM Cloud Access(IAM) manager.
Step 9. Executing on a physical QPU: the first attempt
Let us submit our circuit for execution on a real QPU. To actually execute the circuit on the device, please uncomment the code block below. For convenience, we’ve included pre-run results fromibm_sherbrooke, so you can proceed directly to visualization and analysis.
Step 10. Executing on real QPU: using Haiqu’s error mitigation
To enable Haiqu’s error mitigation, simply add theuse_mitigation=True option to your haiqu.run() call.
As before, we loaded precomputed results to make visualization faster, but if you’d like to execute the circuit on the device yourself, simply uncomment the code block below.
Next steps: where to go from here
The workflow we have just completed is just a glimpse of the full set of available tools. To learn more and explore other core features of the Haiqu SDK check the detailed notebooks listed below.- 🧪 Experiment Tracking
- 📈 Circuit Analytics
- ⚙️ Circuit Execution
Run examples folder, arranged by increasing complexity. Specific examples relating to data loading are contained in the Data Loading examples folder.