Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/0.4.0 catchup #11

Merged
merged 4 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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