
Submit a single expectation-value PUB to IBM Quantum hardware
Source:R/quantum_ibmq.R
quantum_ibmq_submit.RdSynchronous, blocking submission of one
(circuit, observable, parameter_values) "primitive unified block"
(PUB) to the IBM Quantum Runtime EstimatorV2. The circuit is
transpiled to the Instruction-Set-Architecture of the target
backend before submission (preset pass manager, level 1). The
function blocks until the job finishes or timeout_sec elapses,
whichever comes first, and returns an edaphos_quantum_ibmq_job
object wrapping the expectation value, standard error, metadata
and the opaque IBM Quantum job id.
Usage
quantum_ibmq_submit(
hamiltonian,
circuit = "efficient_su2",
parameters,
backend_name = NULL,
shots = 4096L,
mitigation = c("none", "m3", "zne"),
ansatz_reps = 2L,
timeout_sec = 600
)Arguments
- hamiltonian
An
edaphos_quantum_hamiltonian.- circuit
A
qiskit.circuit.QuantumCircuitPython handle or a character string that names one of the pre-built ansatzes: currently"efficient_su2"(the default). When a handle is passed it must already havehamiltonian$n_qubitsqubits.- parameters
Numeric vector of ansatz parameters.
- backend_name
Character — IBM Quantum backend name. When
NULL, the least-busy operational backend is chosen.- shots
Integer — number of circuit shots. Default
4096.- mitigation
Character —
"none"(default),"m3","zne". See the Details ofquantum_vqe_fit().- ansatz_reps
Integer — repetition count when
circuitis a name shorthand. Default2.- timeout_sec
Numeric — seconds to wait for the job to finish before raising an error. Default
600(10 minutes).
Value
An edaphos_quantum_ibmq_job list with:
- job_id
IBM Quantum job identifier (character).
- backend
Name of the backend the job ran on.
- expectation
Scalar expectation value \(\langle \psi(\theta) \mid H \mid \psi(\theta) \rangle\).
- std_error
Standard error of the expectation value, as reported by the EstimatorV2 primitive.
- shots, mitigation
Execution configuration echo.
- metadata
Raw metadata dictionary returned by the primitive (a named list).
Details
This is the low-level escape hatch intended for users who want to
assemble their own hybrid loops outside of quantum_vqe_fit();
in particular, it is the primitive consumed by a future
quantum_krr_fit(..., backend = "ibmq") release for quantum-
kernel matrix elements.
Examples
if (FALSE) { # \dontrun{
ham <- quantum_hamiltonian_h2() # 2 qubits, 5 Pauli terms
# `parameters` must match the ansatz length exactly: there is no
# recycling, and nothing on the R side checks it. EfficientSU2
# carries n_qubits * 2 * (reps + 1) angles, so 2 * 2 * 3 = 12 at
# the default `ansatz_reps = 2`. Compute it, do not guess it.
theta <- rep(0.1, 12)
job <- quantum_ibmq_submit(ham, parameters = theta,
shots = 4096L, mitigation = "m3")
job
# One PUB is ONE expectation value at ONE parameter point -- this
# is not an optimisation. The noiseless value at this theta is
# -1.029329 while the ground state is -1.857275, so theta = 0.1
# sits 0.83 Hartree above the minimum. A hardware number near
# -1.03 therefore means the device worked, NOT that the chemistry
# converged; quantum_vqe_fit(backend = "ibmq") does the latter.
ref <- quantum_vqe_fit(ham, backend = "aer_statevector",
initial_point = theta)$history[1L]
c(hardware = job$expectation, noiseless = ref,
ground_state = quantum_vqe_exact(ham))
# `std_error` is shot noise ONLY -- the EstimatorV2 standard
# error, of order 1/sqrt(shots) (0.0156 at 4096 shots).
# Quadrupling `shots` halves it and does nothing whatsoever to
# the coherent gate error, which is the bias `mitigation`
# attacks. A tight std_error next to an untreated bias is the
# classic way to over-trust a hardware run.
c(std_error = job$std_error, shot_floor = 1 / sqrt(job$shots))
# So compare mitigation levels rather than trusting one run, and
# pin `backend_name` while doing it: the default picks the
# least-busy device afresh each call, which would confound the
# comparison with a change of processor. Two queue slots.
raw <- quantum_ibmq_submit(ham, parameters = theta, shots = 4096L,
backend_name = job$backend,
mitigation = "none")
c(none = raw$expectation, m3 = job$expectation, noiseless = ref)
# `mitigation` is match.arg()'d here, so it is case sensitive
# even though the internal level map is not: "zne" works, "ZNE"
# errors.
# Supplying your own circuit ignores `ansatz_reps` and is
# unchecked: a handle whose width differs from ham$n_qubits gets
# past the transpiler and dies later inside apply_layout() with
# "Number of qargs does not match (3 != 2)". Match the width to
# hamiltonian$n_qubits yourself.
names(job$metadata) # primitive's own report
} # }