I'm trying to use the Estimator and Sampler functions from the recent Qiskit version: https://qiskit.org/documentation/partners/qiskit_ibm_runtime/tutorials/how-to-getting-started-with-estimator.html https://qiskit.org/documentation/partners/qiskit_ibm_runtime/tutorials/how-to-getting-started-with-sampler.html
My environment:
{'qiskit-terra': '0.22.2', 'qiskit-aer': '0.11.1', 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.19.2', 'qiskit': '0.39.2', 'qiskit-nature': '0.5.0', 'qiskit-finance': '0.3.4', 'qiskit-optimization': '0.4.0', 'qiskit-machine-learning': '0.5.0'}
When running the example from the Tutorial on ibm_kawasaki, the job fails with the error message:
Job has failed: Delays must be a multiple of 16 samples. Error code: 8043
Calling "backend.configuration().timing_constraints" indeed yields on Kawasaki:
{'acquire_alignment': 16, 'granularity': 16, 'min_length': 64, 'pulse_alignment': 16}
On other clusters (ibm_cairo) the pulse_alignment is 1, and the code finishes successfully.
There is a timing_constraints option that can be set when transpiling the circuit, but when calling the Estimator, there is no parameter or option that can be set for this. During a transpilation call these restrictions seem to be automatically taken from the backend information, but calling the Estimator with a non-transpiled circuit does not seem to do this. Calling the Estimator with a manually transpiled circuit also does not work.
A similar issue has been discussed in the past here: https://github.com/Qiskit/qiskit-terra/issues/7317
But I did not find any way of setting the timing_constraints with the Sampler or Estimator primitive. Does anyone know how to make them work on clusters with pulse_alignment 16 ?
Edit: Transpiling the circuit with
transpiled_circuits = transpile(psi1, backend=backend, scheduling_method="alap")
inflates the circuit to the total number of qubits on the machine, which then throws the error
File /opt/conda/lib/python3.8/site-packages/qiskit/primitives/base/base_estimator.py:283 in _cross_validate_circuits_observables raise ValueError(
ValueError: The number of qubits of the 0-th circuit (27) does not match the number of qubits of the 0-th observable (4)
I circumvented this by padding the observables with identity operations as suggested, but then the
Job has failed: Delays must be a multiple of 16 samples. Error code: 8043
persists. This is the code that produces said error:
service = QiskitRuntimeService()
backend = service.backend("ibm_kawasaki")
options = Options(optimization_level=3)
options.execution.shots = 1024
padding_str = (backend.configuration().n_qubits - 4) * 'I'
psi1 = RealAmplitudes(num_qubits=4, reps=2, entanglement=[[0,1],[2,3],[0,2],[1,3]], skip_final_rotation_layer=True)
H1 = SparsePauliOp.from_list([("IIII"+padding_str, 1), ("IIII"+padding_str, -2), ("ZIZI"+padding_str, 0)])
theta1 = [0, 1, 1, 2, 3, 5, 1, 1]
with Session(service=service, backend=backend) as session:
estimator = Estimator(session=session, options=options)
transpiled_circuits = transpile(psi1, backend=backend, scheduling_method="alap")
job = estimator.run(circuits=[transpiled_circuits], observables=[H1], parameter_values=[theta1])
print(f"Job result is {job.result()}")