qiskit_trebugger.model.transpilation_sequence
Implements the module for the transpilation sequence of a quantum circuit.
1"""Implements the module for the transpilation sequence of a quantum circuit. 2""" 3 4 5class TranspilationSequence: 6 """Class to implement the transpilation sequence.""" 7 8 def __init__(self, on_step_callback) -> None: 9 self._original_circuit = None 10 self._general_info = {} 11 12 self.on_step_callback = on_step_callback 13 self.steps = [] 14 self.total_runtime = 0 15 self._collected_logs = {} 16 17 @property 18 def original_circuit(self): 19 """Returns the original circuit object""" 20 return self._original_circuit 21 22 @original_circuit.setter 23 def original_circuit(self, circuit): 24 self._original_circuit = circuit 25 26 @property 27 def general_info(self): 28 """Returns the general_info dictionary""" 29 return self._general_info 30 31 @general_info.setter 32 def general_info(self, info): 33 self._general_info = info 34 35 def add_step(self, step): 36 """Adds a transpilation step to the sequence 37 38 Args: 39 step (TranspilationStep): a transpilation step 40 """ 41 if step.name in self._collected_logs: 42 step.logs = self._collected_logs[step.name] 43 self._collected_logs.pop(step.name, None) 44 45 step.index = len(self.steps) 46 self.steps.append(step) 47 self.total_runtime += round(step.duration, 2) 48 49 # property set index: 50 idx = step.index 51 while len(self.steps[idx].property_set) == 0: 52 idx = idx - 1 53 if idx < 0: 54 idx = 0 55 break 56 self.steps[-1].property_set_index = idx 57 58 # Notify: 59 self.on_step_callback(self.steps[-1]) 60 61 def add_log_entry(self, pass_name, log_entry): 62 """Adds log entry to the transpilation pass 63 64 Args: 65 pass_name (str): name of the pass 66 log_entry (LogEntry): Log entry to be appended 67 """ 68 if not pass_name in self._collected_logs: 69 self._collected_logs[pass_name] = [] 70 71 self._collected_logs[pass_name].append(log_entry)
class
TranspilationSequence:
6class TranspilationSequence: 7 """Class to implement the transpilation sequence.""" 8 9 def __init__(self, on_step_callback) -> None: 10 self._original_circuit = None 11 self._general_info = {} 12 13 self.on_step_callback = on_step_callback 14 self.steps = [] 15 self.total_runtime = 0 16 self._collected_logs = {} 17 18 @property 19 def original_circuit(self): 20 """Returns the original circuit object""" 21 return self._original_circuit 22 23 @original_circuit.setter 24 def original_circuit(self, circuit): 25 self._original_circuit = circuit 26 27 @property 28 def general_info(self): 29 """Returns the general_info dictionary""" 30 return self._general_info 31 32 @general_info.setter 33 def general_info(self, info): 34 self._general_info = info 35 36 def add_step(self, step): 37 """Adds a transpilation step to the sequence 38 39 Args: 40 step (TranspilationStep): a transpilation step 41 """ 42 if step.name in self._collected_logs: 43 step.logs = self._collected_logs[step.name] 44 self._collected_logs.pop(step.name, None) 45 46 step.index = len(self.steps) 47 self.steps.append(step) 48 self.total_runtime += round(step.duration, 2) 49 50 # property set index: 51 idx = step.index 52 while len(self.steps[idx].property_set) == 0: 53 idx = idx - 1 54 if idx < 0: 55 idx = 0 56 break 57 self.steps[-1].property_set_index = idx 58 59 # Notify: 60 self.on_step_callback(self.steps[-1]) 61 62 def add_log_entry(self, pass_name, log_entry): 63 """Adds log entry to the transpilation pass 64 65 Args: 66 pass_name (str): name of the pass 67 log_entry (LogEntry): Log entry to be appended 68 """ 69 if not pass_name in self._collected_logs: 70 self._collected_logs[pass_name] = [] 71 72 self._collected_logs[pass_name].append(log_entry)
Class to implement the transpilation sequence.
def
add_step(self, step):
36 def add_step(self, step): 37 """Adds a transpilation step to the sequence 38 39 Args: 40 step (TranspilationStep): a transpilation step 41 """ 42 if step.name in self._collected_logs: 43 step.logs = self._collected_logs[step.name] 44 self._collected_logs.pop(step.name, None) 45 46 step.index = len(self.steps) 47 self.steps.append(step) 48 self.total_runtime += round(step.duration, 2) 49 50 # property set index: 51 idx = step.index 52 while len(self.steps[idx].property_set) == 0: 53 idx = idx - 1 54 if idx < 0: 55 idx = 0 56 break 57 self.steps[-1].property_set_index = idx 58 59 # Notify: 60 self.on_step_callback(self.steps[-1])
Adds a transpilation step to the sequence
Args: step (TranspilationStep): a transpilation step
def
add_log_entry(self, pass_name, log_entry):
62 def add_log_entry(self, pass_name, log_entry): 63 """Adds log entry to the transpilation pass 64 65 Args: 66 pass_name (str): name of the pass 67 log_entry (LogEntry): Log entry to be appended 68 """ 69 if not pass_name in self._collected_logs: 70 self._collected_logs[pass_name] = [] 71 72 self._collected_logs[pass_name].append(log_entry)
Adds log entry to the transpilation pass
Args: pass_name (str): name of the pass log_entry (LogEntry): Log entry to be appended