Skip to content

Commit df0869b

Browse files
Merge pull request #27 from ColibrITD-SAS/revert-26-feat-capture-braket-hardprint
Revert "Catch hard print in Braket conversion"
2 parents 85bde38 + f3c61ee commit df0869b

File tree

3 files changed

+20
-56
lines changed

3 files changed

+20
-56
lines changed

mpqp/qasm/open_qasm_2_and_3.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from enum import Enum
66

77
from warnings import warn
8+
from textwrap import dedent
89
from anytree import Node, PreOrderIter
910
from typeguard import typechecked
1011

11-
from mpqp.tools.errors import InstructionParsingError, OpenQASMTranslationWarning
12+
from mpqp.tools.errors import InstructionParsingError
1213

1314

1415
class Instr(Enum):
@@ -233,13 +234,13 @@ def add_std_lib():
233234
instructions_code += instr + ";\n"
234235
elif instr_name.lower() == "u":
235236
warn(
236-
(
237-
"\nThere is a phase e^(i(a+c)/2) difference between U(a,b,c) gate in 2.0 and 3.0.\n"
238-
"We handled that for you by adding the extra phase at the right place.\n"
239-
"Be careful if you want to create a control gate from this "
240-
"circuit/gate, the phase can become non-global."
241-
),
242-
OpenQASMTranslationWarning,
237+
dedent(
238+
"""OpenQASMTranslationWarning:
239+
There is a phase e^(i(a+c)/2) difference between U(a,b,c) gate in 2.0 and 3.0.
240+
We handled that for you by adding the extra phase at the right place.
241+
Be careful if you want to create a control gate from this circuit/gate, the
242+
phase can become non-global."""
243+
)
243244
)
244245
header_code += add_std_lib()
245246
instructions_code += "u3" + instr[1:] + ";\n"

mpqp/qasm/qasm_to_braket.py

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
"""File regrouping all features for translating QASM code to Amazon Braket objects."""
22

3-
import warnings
4-
from logging import Logger, getLogger
5-
6-
from braket.circuits import Circuit
73
from braket.ir.openqasm import Program
4+
from braket.circuits import Circuit
85
from typeguard import typechecked
96

107
from mpqp.qasm.open_qasm_2_and_3 import open_qasm_hard_includes
11-
from mpqp.tools.errors import UnsupportedBraketFeaturesWarning
128

139

1410
@typechecked
@@ -59,25 +55,6 @@ def qasm3_to_braket_Circuit(qasm3_str: str) -> Circuit:
5955
after_stdgates_included = open_qasm_hard_includes(qasm3_str, set())
6056
# NOTE : gphase is a already used in Braket and thus cannot be redefined as a native gate in OpenQASM.
6157
# We used ggphase instead
62-
warning_message = (
63-
"This program uses OpenQASM language features that may not be "
64-
"supported on QPUs or on-demand simulators."
65-
)
66-
67-
# handle the logger output
68-
# capture their logger
69-
braket_logger = getLogger()
70-
# add logger handler
7158

72-
logger_out = []
7359
circuit = Circuit.from_ir(after_stdgates_included)
74-
75-
if warning_message in logger_out:
76-
warnings.warn("\n" + warning_message, UnsupportedBraketFeaturesWarning)
77-
del logger_out[logger_out.index(warning_message)]
78-
# remove logger handler
79-
80-
for line in logger_out:
81-
braket_logger.warning(line)
82-
8360
return circuit

mpqp/tools/errors.py

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,32 @@
11
class InstructionParsingError(ValueError):
2-
"""Raised when an QASM instruction encountered by the parser is malformed."""
2+
"""Raised when an QASM instruction encountered by the parser is malformed"""
33

44

55
class NumberQubitsError(ValueError):
6-
"""Raised when the number of qubits defining an instruction, a gate, or a
7-
measurement, is not coherent with the related objects (circuit, matrix,
8-
observable, etc...)."""
6+
"""Raised when the number of qubits defining an instruction, a gate, or a measurement, is not coherent with the
7+
related objets (circuit, matrix, observable, etc.)"""
98

109

1110
class ResultAttributeError(AttributeError):
12-
"""Raised when one tries to access the attribute of the result that is
13-
incoherent with the associated job."""
11+
"""Raised when one tries to access the attribute of the result that is incoherent with the associated job."""
1412

1513

1614
class DeviceJobIncompatibleError(ValueError):
17-
"""Raised when one tries to run a job with a JobType that is not suitable
18-
for the selected device (for example SAMPLE job on a statevector simulator)."""
15+
"""Raised when one tries to run a job with a JobType that is not suitable for the selected device
16+
(for example SAMPLE job on a statevector simulator)"""
1917

2018

2119
class RemoteExecutionError(ConnectionError):
22-
"""Raised when an error occurred during a remote connection, submission or
23-
execution."""
20+
"""Raised when an error occurred during a remote connection, submission or execution"""
2421

2522

2623
class IBMRemoteExecutionError(RemoteExecutionError):
27-
"""Raised when an error occurred during the remote execution process of
28-
job(s) on an IBM device."""
24+
"""Raised when an error occurred during the remote execution process of job(s) on an IBM device"""
2925

3026

3127
class QLMRemoteExecutionError(RemoteExecutionError):
32-
"""Raised when an error occurred during the remote execution process of
33-
job(s) on the remote QLM."""
28+
"""Raised when an error occurred during the remote execution process of job(s) on the remote QLM"""
3429

3530

3631
class AWSBraketRemoteExecutionError(RemoteExecutionError):
37-
"""Raised when an error occurred during the remote execution process of
38-
job(s) on the remote Amazon Braket."""
39-
40-
41-
class UnsupportedBraketFeaturesWarning(UserWarning):
42-
"""Warning for potential compatibility issues with Braket."""
43-
44-
45-
class OpenQASMTranslationWarning(UserWarning):
46-
"""Warning for potential translation error when exporting to OpenQASM."""
32+
"""Raised when an error occurred during the remote execution process of job(s) on the remote Amazon Braket"""

0 commit comments

Comments
 (0)