Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.11k stars 2.35k forks source link

TranspilerError: 'Maximum iteration reached. max_iteration=1000' #9177

Closed patdenim closed 1 year ago

patdenim commented 1 year ago

Environment

What is happening?

This error happens when specifying seed_transpiler=0 during tranpilation of this Quantum Volume Circuit in Optimization level 3 Does not occur with optim level 2 or if adding aninitial_layout Occurs on 27 qubit backend Ehningen, mumbai, cairo, hanoi, ...etc ... Does not occur for 7 qubit systems (perth, mairobi...lagos..etc...)

How can we reproduce the issue?

transpile(circuit,
          backend_properties=backend_properties,
          coupling_map=CouplingMap(coupling_map),
          optimization_level=3,
          basis_gates=basis_gates,
          seed_transpiler=0,
          # initial_layout=[0,1,2,3],
          callback=callback_func 
         )

Circuit qasm string :

OPENQASM 2.0;
include "qelib1.inc";
qreg q[4];
creg measure[4];
rz(-2.5802401) q[0];
sx q[0];
rz(-2.0869703) q[0];
sx q[0];
rz(1.6404775) q[0];
rz(0.81085724) q[1];
sx q[1];
rz(-1.8376071) q[1];
sx q[1];
rz(-1.3097961) q[1];
cx q[1],q[0];
rz(0.67667501) q[0];
sx q[1];
rz(-2.7764038) q[1];
cx q[1],q[0];
rz(0.30962129) q[0];
sx q[1];
cx q[1],q[0];
rz(2.7770127) q[0];
sx q[0];
rz(-1.2031312) q[0];
sx q[0];
rz(-3.0338786) q[0];
rz(2.4776278) q[1];
sx q[1];
rz(-0.6905397) q[1];
sx q[1];
rz(2.0746922) q[1];
rz(-0.6156589) q[2];
sx q[2];
rz(-1.8610293) q[2];
sx q[2];
rz(-3.0344268) q[2];
rz(2.0113839) q[3];
sx q[3];
rz(-1.8378009) q[3];
sx q[3];
rz(-0.13322642) q[3];
cx q[3],q[2];
rz(1.016714) q[2];
sx q[3];
rz(-2.8928939) q[3];
cx q[3],q[2];
rz(0.60297329) q[2];
sx q[3];
cx q[3],q[2];
rz(-2.1374885) q[2];
sx q[2];
rz(-1.936627) q[2];
sx q[2];
rz(1.7758116) q[2];
cx q[2],q[0];
rz(-0.98539769) q[0];
sx q[2];
rz(-2.9594221) q[2];
cx q[2],q[0];
rz(0.17455528) q[0];
sx q[2];
cx q[2],q[0];
rz(-0.16450158) q[0];
sx q[0];
rz(-2.2954507) q[0];
sx q[0];
rz(-2.5644551) q[0];
rz(1.1609963) q[2];
sx q[2];
rz(-2.1767678) q[2];
sx q[2];
rz(2.5697281) q[2];
rz(-1.0296487) q[3];
sx q[3];
rz(-0.47555166) q[3];
sx q[3];
rz(1.9085924) q[3];
cx q[3],q[1];
rz(-0.61370581) q[1];
sx q[3];
rz(-2.8624277) q[3];
cx q[3],q[1];
rz(0.43911451) q[1];
sx q[3];
cx q[3],q[1];
rz(2.9516727) q[1];
sx q[1];
rz(-0.78588443) q[1];
sx q[1];
rz(-1.3890123) q[1];
cx q[1],q[0];
rz(-1.0649292) q[0];
sx q[1];
rz(-2.7754283) q[1];
cx q[1],q[0];
rz(0.46170102) q[0];
sx q[1];
cx q[1],q[0];
rz(-0.48364484) q[0];
sx q[0];
rz(-1.1779429) q[0];
sx q[0];
rz(1.8106294) q[0];
rz(-1.057089) q[1];
sx q[1];
rz(-0.48037255) q[1];
sx q[1];
rz(-2.3612646) q[1];
rz(-1.7485439) q[3];
sx q[3];
rz(-1.6016858) q[3];
sx q[3];
rz(-2.3028793) q[3];
cx q[3],q[2];
rz(1.093317) q[2];
sx q[3];
rz(-3.0564183) q[3];
cx q[3],q[2];
rz(0.11619561) q[2];
sx q[3];
cx q[3],q[2];
rz(0.17571848) q[2];
sx q[2];
rz(-1.735554) q[2];
sx q[2];
rz(-1.5351265) q[2];
rz(-2.5350841) q[3];
sx q[3];
rz(-0.81386815) q[3];
sx q[3];
rz(-3.0831125) q[3];
barrier q[0],q[1],q[2],q[3];
measure q[0] -> measure[0];
measure q[1] -> measure[1];
measure q[2] -> measure[2];
measure q[3] -> measure[3];

What should happen?

Should transpile !

Any suggestions?

No response

jakelishman commented 1 year ago

Please can you give us a complete reproducer, including the setup of your variables, and the full traceback of the error you saw?

patdenim commented 1 year ago

Hi @jakelishman,
Sorry, Here is how to reproduce using the circuit.qpy file i uploaded as .txt here below. I just noticed today that if using a MAC Os environment, then the transpilation works well. That seems to fail only when using Windows OS to execute the notebook. The circuit used is coming from a client who's trying to test the Quantum Volume, and i suspect that this circuit is coming from Ignis (qiskit.ignis.verification.qv_circuits). That might have its importance.
circuit.qpy.txt

from time import time
from qiskit.transpiler import CouplingMap
from qiskit.providers.models import BackendProperties
from qiskit.circuit import qpy_serialization
with open('circuit.qpy', 'rb') as fd:
    new_qc = qpy_serialization.load(fd)[0]

coupling_map=backend.configuration().coupling_map
backend_properties=backend.properties()
basis_gates=backend.configuration().basis_gates

transpile(new_qc,
          backend_properties=backend_properties,
          coupling_map=CouplingMap(coupling_map),
          optimization_level=3,
          basis_gates=basis_gates,
          seed_transpiler=0
          )
jakelishman commented 1 year ago

Thanks for the file! Which backend is in use here?

patdenim commented 1 year ago

I used 'ibm_hanoi' Got same error using 'Hanoi', 'Mumbai' .... and some other 27 qubits systems The client reported the original error on Ehningen What surprised me today is that seems related to the OS from where you execute the transpilation as i don't get the error when using a MAC OS to run the notebook...

patdenim commented 1 year ago

Jake, i got another scenario using runtime Sampler where the transpilation fails with `"Maximum iteration reached. max_iteration=1000"

The scenario is based on creating a QuantumVolume(7,7,0) circuit of 7x7, unroll it using a basic set of gates ["id","rz","cx","sx","x"],and seed_transpiler=0, then execute that circuit using the Sampler with optimization_level=3and transpiler_seed=0. I've attached the full notebook reproducing the problem using the backend Wellington ` Test-transpile-level0+Runtime-level3-seed0.zip

jakelishman commented 1 year ago

Sorry for the slow reply! @mtreinish is looking into this for a handful of reasons, so I'll pass this over to him (and also, I'm about to go on holiday for about a month...)

epelofske-LANL commented 1 year ago

I think this is the same error mentioned in https://github.com/Qiskit/qiskit-terra/issues/6996, https://github.com/Qiskit/qiskit-terra/issues/5832, https://github.com/Qiskit/qiskit-terra/issues/5627. My work around is to try multiple seeds until the transpilation succeeds without throwing an error.

epelofske-LANL commented 1 year ago

I am still encountering this error ('Maximum iteration reached. max_iteration=1000') for Quantum Volume circuits. Qiskit version qiskit==0.42.0 and qiskit-terra==0.23.2.