Qiskit loader#
Introduction#
The Qiskit loader lets a solver access the IBM Quantum backend selected for a QCentroid job without hardcoding IBM credentials or backend names in the source code.
Use this loader when your solver builds circuits with Qiskit and submits them with qiskit-ibm-runtime.
Import#
from QCentroidLoaders import QiskitLoader
Get the selected backend#
Call QiskitLoader.get_target() when your solver is ready to submit the circuit:
backend = QiskitLoader.get_target()
In the platform runtime, this backend is resolved from the provider and backend selected by the user when launching the job.
When running locally without platform initialization, QiskitLoader.get_target() returns a local Qiskit simulator. It uses qiskit_aer.AerSimulator when qiskit-aer is installed, and falls back to qiskit.providers.basic_provider.BasicSimulator otherwise.
Example solver#
from typing import Any
import logging
from qiskit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager
from qiskit_ibm_runtime import SamplerV2
from QCentroidLoaders import QiskitLoader
logger = logging.getLogger("qcentroid-user-log")
logging.basicConfig()
logger.setLevel(logging.INFO)
def run(
input_data: dict[str, Any],
solver_params: dict[str, Any],
extra_arguments: dict[str, Any],
) -> dict[str, Any]:
logger.info("Creating circuit...")
qc = QuantumCircuit(1, 1)
qc.x(0)
qc.measure_all()
backend = QiskitLoader.get_target()
logger.info(f"Using backend: {backend}")
optimization_level = solver_params.get("optimization_level", 1)
shots = solver_params.get("shots", 1024)
pm = generate_preset_pass_manager(
optimization_level=optimization_level,
backend=backend,
)
isa_circuit = pm.run(qc)
sampler = SamplerV2(backend)
logger.info("Sending job to IBM Quantum...")
job = sampler.run([isa_circuit], shots=shots)
logger.info("Obtaining job result...")
result = job.result()[0]
counts = result.data.meas.get_counts()
logger.info(f"Result from backend: {counts}")
return {
"status": "ok",
"provider": "qiskit",
"backend": str(backend),
"result": counts,
}
Platform execution#
When this solver runs in QCentroid:
- The user selects the solver and the IBM Quantum backend in the dashboard or API.
- The platform injects the provider access token into the runtime environment.
QiskitLoader.get_target()returns the configured backend.- The solver submits the circuit and returns the result to QCentroid.
Local execution#
For local development, install the local loader package from the public QCentroid loaders repository when it is available:
pip install git+<loaders-repository-url>
Then configure your IBM Quantum credentials as described in that repository if you want to run against a remote IBM Quantum backend locally. If you do not initialize the loader with a remote backend, the loader returns a local simulator.
Best practices#
- Keep
shotsand transpilation options configurable throughsolver_paramswhen users need control over cost or precision. - Log the backend name and submission stage, but never log access tokens.
- Validate circuits locally or on a simulator before running on paid hardware.