@@ -47,6 +47,9 @@ def receive(self, command_list): # pylint: disable=unused-argument
4747 """No-op"""
4848
4949
50+ _N_ENGINES_THRESHOLD = 100
51+
52+
5053class MainEngine (BasicEngine ): # pylint: disable=too-many-instance-attributes
5154 """
5255 The MainEngine class provides all functionality of the main compiler engine.
@@ -61,10 +64,13 @@ class MainEngine(BasicEngine): # pylint: disable=too-many-instance-attributes
6164 dirty_qubits (Set): Containing all dirty qubit ids
6265 backend (BasicEngine): Access the back-end.
6366 mapper (BasicMapperEngine): Access to the mapper if there is one.
64-
67+ n_engines (int): Current number of compiler engines in the engine list
68+ n_engines_max (int): Maximum number of compiler engines allowed in the engine list. Defaults to 100.
6569 """
6670
67- def __init__ (self , backend = None , engine_list = None , verbose = False ):
71+ def __init__ ( # pylint: disable=too-many-statements,too-many-branches
72+ self , backend = None , engine_list = None , verbose = False
73+ ):
6874 """
6975 Initialize the main compiler engine and all compiler engines.
7076
@@ -118,6 +124,7 @@ def __init__(self, backend=None, engine_list=None, verbose=False):
118124 self .dirty_qubits = set ()
119125 self .verbose = verbose
120126 self .main_engine = self
127+ self .n_engines_max = _N_ENGINES_THRESHOLD
121128
122129 if backend is None :
123130 backend = Simulator ()
@@ -174,6 +181,10 @@ def __init__(self, backend=None, engine_list=None, verbose=False):
174181 " twice.\n "
175182 )
176183
184+ self .n_engines = len (engine_list )
185+ if self .n_engines > self .n_engines_max :
186+ raise ValueError ('Too many compiler engines added to the MainEngine!' )
187+
177188 self ._qubit_idx = int (0 )
178189 for i in range (len (engine_list ) - 1 ):
179190 engine_list [i ].next_engine = engine_list [i + 1 ]
0 commit comments