diff --git a/qiskit_classroom/converter_presenter.py b/qiskit_classroom/converter_presenter.py index 7767d3c..5e4256d 100644 --- a/qiskit_classroom/converter_presenter.py +++ b/qiskit_classroom/converter_presenter.py @@ -136,8 +136,8 @@ async def on_convert_button_clicked(self) -> None: result = await self.model.convert_and_draw( shows_result=self.view.get_shows_result() ) - except RuntimeError: - self.view.show_alert_message("conversion processe error") + except RuntimeError as exc: + self.view.show_alert_message("conversion processe error\n" + exc.__str__()) except TimeoutExpired: self.view.show_alert_message("conversion process timeout error") except FileNotFoundError: diff --git a/qiskit_classroom/worker.py b/qiskit_classroom/worker.py index 37c9070..5cb71ca 100644 --- a/qiskit_classroom/worker.py +++ b/qiskit_classroom/worker.py @@ -54,6 +54,7 @@ def add_new_line(strings: list[str]) -> str: class ConverterWorker: """worker for convert expression and visualize expression""" + # pylint: disable=too-many-arguments def __init__( self, from_expression: QuantumExpression, @@ -79,7 +80,11 @@ def generate_random_file_name() -> str: # pragma: no cover Returns: str: generated file name """ - return "".join(random.choice(string.ascii_letters) for _ in range(10)) + ".py" + return ( + "/tmp/" + + "".join(random.choice(string.ascii_letters) for _ in range(10)) + + ".py" + ) @staticmethod def write_converting_code(file_path: str, code: str) -> bool: # pragma: no cover @@ -170,9 +175,13 @@ def generate_visualization_code(self) -> str: if self.to_expression is QuantumExpression.MATRIX: return add_new_line( [ - "for gate, name in zip(reversed(result['gate']), reversed(result['name'])):", - """\tprint(f'{gate.strip()}_' + '{' + "\\\\otimes ".join(name[1]) + '}')""", - "print(f\"={result['result']}_{{result}}\")" + ( + "for gate, name in zip(reversed(result['gate'])," + + "reversed(result['name'])):" + ), + "\totimes=' \\\\otimes '", + """\tprint('\\stackrel{' + otimes.join(name[1]) +'}' + f'{{{gate}}}')""", + "print(f\"= \\stackrel{{result}}{{{result['result']}}}\")" if self.shows_result else "", ] diff --git a/requirements.txt b/requirements.txt index 939d4d4..5294a22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ qiskit==0.44.1 PySide6==6.5.1.1 qasync==0.24.0 -qiskit-classroom-converter==0.3.0 +qiskit-classroom-converter==0.4.0 matplotlib==3.7.2 pylatexenc==2.10 \ No newline at end of file diff --git a/tests/test_worker.py b/tests/test_worker.py index 3e4e3d4..878adf3 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -42,8 +42,9 @@ "converter = ConversionService(conversion_type='QC_TO_MATRIX'," + " option={'print': 'raw'})\n" + f"result = converter.convert(input_value={VALUE_NAME})", - "for gate, name in zip(reversed(result['gate']), reversed(result['name'])):\n" - + "\tprint(f'{gate.strip()}_' + '{' + \"\\\\otimes \".join(name[1]) + '}')\n", + "for gate, name in zip(reversed(result['gate']),reversed(result['name'])):\n" + + "\totimes=' \\\\otimes '\n" + + "\tprint('\\stackrel{' + otimes.join(name[1]) +'}' + f'{{{gate}}}')\n", ] MATRIX_TO_QC_EXPECTED = [