|
1 | 1 | """File regrouping all features for translating QASM code to Amazon Braket objects."""
|
2 | 2 |
|
3 | 3 | import io
|
4 |
| -import warnings |
| 4 | + |
| 5 | +# import warnings |
5 | 6 | from logging import StreamHandler, getLogger
|
6 | 7 |
|
7 | 8 | from braket.circuits import Circuit
|
8 | 9 | from braket.ir.openqasm import Program
|
9 | 10 | from typeguard import typechecked
|
10 | 11 |
|
11 | 12 | from mpqp.qasm.open_qasm_2_and_3 import open_qasm_hard_includes
|
12 |
| -from mpqp.tools.errors import UnsupportedBraketFeaturesWarning |
| 13 | + |
| 14 | +# from mpqp.tools.errors import UnsupportedBraketFeaturesWarning |
13 | 15 |
|
14 | 16 |
|
15 | 17 | @typechecked
|
@@ -57,28 +59,32 @@ def qasm3_to_braket_Circuit(qasm3_str: str) -> Circuit:
|
57 | 59 | # we remove any include of stdgates.inc and replace it with custom include
|
58 | 60 | qasm3_str = qasm3_str.replace("stdgates.inc", "braket_custom_include.inc")
|
59 | 61 |
|
60 |
| - try: |
61 |
| - after_stdgates_included = open_qasm_hard_includes(qasm3_str, set()) |
62 |
| - except Exception as e: |
63 |
| - warning_message = ( |
64 |
| - f"An error occurred while processing the OpenQASM code with Braket: {e}" |
65 |
| - ) |
66 |
| - warnings.warn(warning_message, UnsupportedBraketFeaturesWarning) |
67 |
| - return None |
68 |
| - |
69 |
| - # NOTE: gphase is already used in Braket and thus cannot be redefined as a native gate in OpenQASM. |
70 |
| - # We used ggphase instead |
71 |
| - if "U(" in after_stdgates_included or "gphase(" in after_stdgates_included: |
72 |
| - # Issue a warning only if not already issued |
73 |
| - warning_message = "This program uses OpenQASM language features that may not be supported on QPUs or on-demand simulators." |
74 |
| - warnings.warn(warning_message, UnsupportedBraketFeaturesWarning) |
| 62 | + after_stdgates_included = open_qasm_hard_includes(qasm3_str, set()) |
| 63 | + # try: |
| 64 | + # except Exception as e: |
| 65 | + # warning_message = ( |
| 66 | + # f"An error occurred while processing the OpenQASM code with Braket: {e}" |
| 67 | + # ) |
| 68 | + # warnings.warn(warning_message, UnsupportedBraketFeaturesWarning) |
| 69 | + # return None |
| 70 | + |
| 71 | + # # NOTE: gphase is already used in Braket and thus cannot be redefined as a native gate in OpenQASM. |
| 72 | + # # We used ggphase instead |
| 73 | + # if "U(" in after_stdgates_included or "gphase(" in after_stdgates_included: |
| 74 | + # # Issue a warning only if not already issued |
| 75 | + # warning_message = "This program uses OpenQASM language features that may not be supported on QPUs or on-demand simulators." |
| 76 | + # warnings.warn(warning_message, UnsupportedBraketFeaturesWarning) |
75 | 77 |
|
76 | 78 | # capture the Braket logger
|
77 | 79 | braket_logger = getLogger()
|
78 | 80 |
|
| 81 | + # TODO: catch the logged warning |
79 | 82 | logger_output_stream = io.StringIO()
|
80 | 83 | stream_handler = StreamHandler(logger_output_stream)
|
81 | 84 | braket_logger.addHandler(stream_handler)
|
| 85 | + # if message == warning_message: |
| 86 | + # warnings.warn(warning_message, UnsupportedBraketFeaturesWarning) |
| 87 | + stream_handler.addFilter(...) |
82 | 88 |
|
83 | 89 | circuit = Circuit.from_ir(after_stdgates_included)
|
84 | 90 |
|
|
0 commit comments