Skip to content

Commit

Permalink
Merge pull request #12 from KMU-quantum-classroom/develop
Browse files Browse the repository at this point in the history
Develop feature/0.4.0 catchup
  • Loading branch information
fmowl10 authored Oct 15, 2023
2 parents ac9016e + ef6c1e4 commit a69fc12
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions qiskit_classroom/converter_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 13 additions & 4 deletions qiskit_classroom/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 "",
]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit a69fc12

Please sign in to comment.