3
$\begingroup$

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()}")
$\endgroup$

2 Answers 2

1
$\begingroup$

The solution is in the link you mentioned in your question:

the easiest way to fix this is to use the scheduling method kwarg on transpile() to run the full set of scheduling passes which will adjust the scheduled circuit based on the timing constraints.

So, instead of passing your circuit(s) to Estimator directly, pass the transpiled circuit(s):

transpiled_circuits = transpile(circuits, backend, scheduling_method="alap")
job = estimator.run(transpiled_circuits, observables)

To overcome the mismatch between number of backend qubits and number of observable qubits, you can pad the observable with Is:

padding_str = (backend.configuration().n_qubits - 2) * 'I'
observable = SparsePauliOp("ZX" + padding_str)
$\endgroup$
3
  • $\begingroup$ Thank you for your comment, unfortunately I tried this already (This is what I meant by "Calling the Estimator with a manually transpiled circuit also does not work.") When using the transpile comment exactly as you suggested, it produces 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). Transpilation maps the circuit on all 27 qubits of the processor. $\endgroup$
    – SBackes
    Dec 13, 2022 at 7:15
  • $\begingroup$ It looks like a bug. Anyway, I added a suggestion to the answer to show how to overcome this issue. $\endgroup$ Dec 13, 2022 at 8:44
  • $\begingroup$ Thanks again for the quick answer. Padding with identity operators solved this problem, but then the "Delays must be a multiple of 16 samples" Error persists. I updated my original post. $\endgroup$
    – SBackes
    Dec 14, 2022 at 4:56
0
$\begingroup$

I have run into this error before Job has failed: Delays must be a multiple of 16 samples. Error code: 8043 when using dynamical decoupling padding. I solved this error by retrieving the pulse_alignment parameter from the backend metadata (this is an integer, usually 1 or 16 I think). Then, I was able to pass the to the Pad Dyanimical Decoupling call. As you pointed out, this seems to be a Runtime error where they do not allow the user to specify this pulse_alignment parameter.

As far as I can tell there is no way to fix this; I would open a Github issue and or post on the IBMQ Slack.

By the way, there is actually a way to temporarily fix this error (I think). optimization_level=0 will turn off dynamical decoupling and then the error should not appear.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.