Skip to content

Commit

Permalink
remove backend v1 test + reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGupta2012 committed Sep 23, 2024
1 parent a3622f0 commit ec75ada
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 172 deletions.
8 changes: 2 additions & 6 deletions src/qiskit_trebugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,13 @@ def debug(
raise DebuggerError("Invalid view type supplied!")

if not isinstance(circuit, QuantumCircuit):
raise DebuggerError(
"Debugger currently supports single QuantumCircuit only!"
)
raise DebuggerError("Debugger currently supports single QuantumCircuit only!")
if backend is None:
backend = Aer.get_backend("qasm_simulator")

if view_type == "cli":
if not cls._is_regular_interpreter():
raise DebuggerError(
"Can not invoke CLI view in IPython or Juptyer Environment!"
)
raise DebuggerError("Can not invoke CLI view in IPython or Juptyer Environment!")
cls.view = CLIView()
else:
cls.view = TimelineView()
Expand Down
8 changes: 2 additions & 6 deletions src/qiskit_trebugger/model/data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def __init__(self, transpilation_sequence) -> None:
def callback(**kwargs):
pass_ = kwargs["pass_"]

pass_type = (
PassType.ANALYSIS if pass_.is_analysis_pass else PassType.TRANSFORMATION
)
pass_type = PassType.ANALYSIS if pass_.is_analysis_pass else PassType.TRANSFORMATION

transpilation_step = TranspilationStep(pass_.name(), pass_type)
transpilation_step.docs = pass_.__doc__
Expand All @@ -42,9 +40,7 @@ def callback(**kwargs):
_added_props.append(key)
elif (self._properties[key] is None) and (value is not None):
_updated_props.append(key)
elif hasattr(value, "__len__") and (
len(value) != len(self._properties[key])
):
elif hasattr(value, "__len__") and (len(value) != len(self._properties[key])):
_updated_props.append(key)

if len(_added_props) > 0 or len(_updated_props) > 0:
Expand Down
4 changes: 1 addition & 3 deletions src/qiskit_trebugger/model/logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ def __init__(self, *args, **kwargs):

def emit(self, record):
log_entry = LogEntry(record.levelname, record.msg, record.args)
self.transpilation_sequence.add_log_entry(
self.loggers_map[record.name], log_entry
)
self.transpilation_sequence.add_log_entry(self.loggers_map[record.name], log_entry)
4 changes: 1 addition & 3 deletions src/qiskit_trebugger/model/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def __init__(self, name, prop_type, value, state) -> None:
self.prop_type = prop_type
self.state = state

if prop_type in (list, defaultdict) and (
len(value) > self.LARGE_VALUE_THRESHOLD
):
if prop_type in (list, defaultdict) and (len(value) > self.LARGE_VALUE_THRESHOLD):
print(len(value))
self.value = "LARGE_VALUE"
else:
Expand Down
16 changes: 4 additions & 12 deletions src/qiskit_trebugger/views/cli/cli_pass_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def _add_title(self):
Args:
None
"""
pass_name = f"{self.transpiler_pass.index}. {self.transpiler_pass.name}"[
: self.width - 1
]
pass_name = f"{self.transpiler_pass.index}. {self.transpiler_pass.name}"[: self.width - 1]
title_offset = self._get_center(self.width - 4, len(pass_name))
self.pad.addstr(
self._start_row,
Expand All @@ -79,9 +77,7 @@ def _add_information(self):
self._start_row += 2
pass_type = self.transpiler_pass.pass_type.value
pass_runtime = self.transpiler_pass.duration
info_string = f"Type : {pass_type} | Runtime (ms) : {pass_runtime}"[
: self.width - 1
]
info_string = f"Type : {pass_type} | Runtime (ms) : {pass_runtime}"[: self.width - 1]

self._display_header(info_string)

Expand Down Expand Up @@ -345,9 +341,7 @@ def _add_documentation(self):
self._start_row += 1
pass_docs = self.transpiler_pass.get_docs()

pass_docs = (
" " + pass_docs if pass_docs and pass_docs.count("\n") > 0 else ""
)
pass_docs = " " + pass_docs if pass_docs and pass_docs.count("\n") > 0 else ""
pass_docs = [[pass_docs], [self.transpiler_pass.run_method_docs]]

docs_table = tabulate.tabulate(
Expand Down Expand Up @@ -380,9 +374,7 @@ def _add_circuit(self):
circ_string = [[self.circuit.draw(output="text", fold=100)]]
else:
circ_string = [
[
f"Circuit depth {self.transpiler_pass.circuit_stats.depth} too large to display"
]
[f"Circuit depth {self.transpiler_pass.circuit_stats.depth} too large to display"]
]
circ_table = tabulate.tabulate(
tabular_data=circ_string,
Expand Down
51 changes: 14 additions & 37 deletions src/qiskit_trebugger/views/cli/cli_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def _init_color(self):

curses.init_pair(1, COLORS.TITLE["front"], COLORS.TITLE["back"])
curses.init_pair(2, COLORS.STATUS["front"], COLORS.STATUS["back"])
curses.init_pair(
3, COLORS.BASE_PASSES_TITLE["front"], COLORS.BASE_PASSES_TITLE["back"]
)
curses.init_pair(3, COLORS.BASE_PASSES_TITLE["front"], COLORS.BASE_PASSES_TITLE["back"])
curses.init_pair(4, COLORS.CHANGING_PASS["front"], COLORS.CHANGING_PASS["back"])

self._colors["title"] = curses.color_pair(1)
Expand Down Expand Up @@ -193,9 +191,7 @@ def _handle_keystroke(self, key):
self._view_params["curr_row"] = 0

elif key in [ord("h"), ord("H")]:
self._view_params["overview_visible"] = not self._view_params[
"overview_visible"
]
self._view_params["overview_visible"] = not self._view_params["overview_visible"]
self._view_params["overview_change"] = True
self._view_params["curr_col"] = 0
self._view_params["curr_row"] = 0
Expand Down Expand Up @@ -299,13 +295,9 @@ def _build_overview_win(self, rows, cols):
else:
total_passes["A"] += 1

total_pass_str = f"Total Passes : {total_passes['A'] + total_passes['T']}"[
: cols - 1
]
total_pass_str = f"Total Passes : {total_passes['A'] + total_passes['T']}"[: cols - 1]
pass_categories_str = (
f"Transformation : {total_passes['T']} | Analysis : {total_passes['A']}"[
: cols - 1
]
f"Transformation : {total_passes['T']} | Analysis : {total_passes['A']}"[: cols - 1]
)

start_x = 5
Expand All @@ -314,11 +306,9 @@ def _build_overview_win(self, rows, cols):
overview_win.addstr(7, start_x, pass_categories_str)

# runtime
runtime_str = (
f"Runtime : {round(self.transpilation_sequence.total_runtime,2)} ms"[
: cols - 1
]
)
runtime_str = f"Runtime : {round(self.transpilation_sequence.total_runtime,2)} ms"[
: cols - 1
]
overview_win.addstr(9, start_x, runtime_str, curses.A_BOLD)

# circuit stats
Expand Down Expand Up @@ -351,9 +341,7 @@ def _build_overview_win(self, rows, cols):

# overview header
overview_str = "TRANSPILATION OVERVIEW"[: cols - 1]
start_x_overview = start_x + self._get_center(
max_line_length, len(overview_str)
)
start_x_overview = start_x + self._get_center(max_line_length, len(overview_str))
overview_win.hline(0, start_x, "_", min(cols, max_line_length))
overview_win.addstr(2, start_x_overview, overview_str, curses.A_BOLD)
overview_win.hline(3, start_x, "_", min(cols, max_line_length))
Expand Down Expand Up @@ -431,9 +419,7 @@ def _get_statusbar_win(self, rows, cols, status_type="normal"):
if status_type == "index":
textbox = Textbox(statusbar_window)
textbox.edit()
str_value = (
textbox.gather().split(":")[1].strip()
) # get the value of the entered text
str_value = textbox.gather().split(":")[1].strip() # get the value of the entered text

try:
num = int(str_value)
Expand Down Expand Up @@ -472,8 +458,7 @@ def _refresh_base_windows(self, resized, height, width):
self._title.noutrefresh()

overview_toggle = (
self._view_params["overview_visible"]
and self._view_params["overview_change"]
self._view_params["overview_visible"] and self._view_params["overview_change"]
)
if resized or overview_toggle:
try:
Expand All @@ -497,15 +482,11 @@ def _get_pass_circuit(self, step):
# Due to a bug in DAGCircuit.__eq__, we can not use ``step.dag != None``

found_transform = False
while (
not isinstance(self.transpilation_sequence.steps[idx].dag, DAGCircuit)
and idx > 0
):
while not isinstance(self.transpilation_sequence.steps[idx].dag, DAGCircuit) and idx > 0:
idx = idx - 1
if idx >= 0:
found_transform = (
self.transpilation_sequence.steps[idx].pass_type
== PassType.TRANSFORMATION
self.transpilation_sequence.steps[idx].pass_type == PassType.TRANSFORMATION
)

if not found_transform:
Expand All @@ -515,9 +496,7 @@ def _get_pass_circuit(self, step):

def _get_pass_property_set(self, step):
if step.property_set_index is not None:
return self.transpilation_sequence.steps[
step.property_set_index
].property_set
return self.transpilation_sequence.steps[step.property_set_index].property_set

return {}

Expand Down Expand Up @@ -791,9 +770,7 @@ def display(self, stdscr):
height, width = stdscr.getmaxyx()

# Check for clearing
panel_initiated = (
self._view_params["last_height"] + self._view_params["last_width"] > 0
)
panel_initiated = self._view_params["last_height"] + self._view_params["last_width"] > 0
panel_resized = (
self._view_params["last_width"] != width
or self._view_params["last_height"] != height
Expand Down
Loading

0 comments on commit ec75ada

Please sign in to comment.