Skip to content

Commit 3c9a7ae

Browse files
author
Rajib Chakravorty
committed
removed unnecessary exception definitions and check_package method; simply moved the imports of the libraries inside the relevant methods
1 parent 9744f77 commit 3c9a7ae

File tree

7 files changed

+17
-177
lines changed

7 files changed

+17
-177
lines changed

qctrlopencontrols/base/check_packages.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

qctrlopencontrols/cirq/circuit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020

2121
import numpy as np
2222

23-
import cirq
24-
2523
from ..dynamic_decoupling_sequences.dynamic_decoupling_sequence import DynamicDecouplingSequence
2624
from ..exceptions.exceptions import ArgumentsValueError
2725
from ..globals import (FIX_DURATION_UNITARY, INSTANT_UNITARY)
2826

2927

30-
def convert_dds_to_cirq_circuit(
28+
def convert_dds_to_cirq_circuit( #pylint: disable=too-many-locals
3129
dynamic_decoupling_sequence,
3230
target_qubits=None,
3331
gate_time=0.1,
@@ -93,6 +91,8 @@ def convert_dds_to_cirq_circuit(
9391
any offset.
9492
"""
9593

94+
import cirq
95+
9696
if dynamic_decoupling_sequence is None:
9797
raise ArgumentsValueError('No dynamic decoupling sequence provided.',
9898
{'dynamic_decoupling_sequence': dynamic_decoupling_sequence})

qctrlopencontrols/cirq/schedule.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
import numpy as np
2222

23-
import cirq
24-
2523
from ..dynamic_decoupling_sequences.dynamic_decoupling_sequence import DynamicDecouplingSequence
2624
from ..exceptions.exceptions import ArgumentsValueError
2725

2826

29-
def convert_dds_to_cirq_schedule(
27+
def convert_dds_to_cirq_schedule( #pylint: disable=too-many-locals
3028
dynamic_decoupling_sequence,
3129
target_qubits=None,
3230
gate_time=0.1,
@@ -87,6 +85,8 @@ def convert_dds_to_cirq_schedule(
8785
any offset.
8886
"""
8987

88+
import cirq
89+
9090
if dynamic_decoupling_sequence is None:
9191
raise ArgumentsValueError('No dynamic decoupling sequence provided.',
9292
{'dynamic_decoupling_sequence': dynamic_decoupling_sequence})
@@ -146,8 +146,8 @@ def convert_dds_to_cirq_schedule(
146146
nonzero_pulse_counts = 3 - np.sum(zero_pulses)
147147
if nonzero_pulse_counts > 1:
148148
raise ArgumentsValueError(
149-
'Open Controls support a sequence with one '
150-
'valid pulse at any offset. Found sequence '
149+
'Open Controls support a sequence with one'
150+
'valid pulse at any offset. Found sequence'
151151
'with multiple rotation operations at an offset.',
152152
{'dynamic_decoupling_sequence': str(dynamic_decoupling_sequence),
153153
'offset': dynamic_decoupling_sequence.offsets[op_idx],

qctrlopencontrols/exceptions/exceptions.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -57,79 +57,3 @@ def __init__(self, description, arguments, extras=None):
5757
for key in self.extras:
5858
self.message += '\n' + str(key) + '=' + repr(self.extras[key])
5959
super(ArgumentsValueError, self).__init__(self.message)
60-
61-
62-
class PackageVersionMismatchError(QctrlError):
63-
"""Exception raised when the version of required third party packages found but is
64-
below the minimum required.
65-
66-
Parameters
67-
----------
68-
description : string
69-
Description of the why the error is raised.
70-
arguments : dict
71-
Dictionary that contains the package name, required minimum version.
72-
extras : dict, optional
73-
Other variables, such as the version found in the system,
74-
that may be relevant to the error. Defaults to None.
75-
"""
76-
77-
def __init__(self, description, arguments, extras=None):
78-
self.description = description
79-
self.arguments = arguments
80-
self.extras = extras
81-
self.message = self.description
82-
83-
for key in self.arguments:
84-
self.message += '\n' + str(key) + '=' + repr(self.arguments[key])
85-
if extras is not None:
86-
for key in self.extras:
87-
self.message += '\n' + str(key) + '=' + repr(self.extras[key])
88-
super(PackageVersionMismatchError, self).__init__(self.message)
89-
90-
91-
class PackageNotFoundError(QctrlError):
92-
"""Exception raised when the required third party packages is not found.
93-
94-
Parameters
95-
----------
96-
description : string
97-
Description of the why the error is raised.
98-
arguments : dict
99-
Dictionary that contains the package name and the required minimum version.
100-
extras : dict, optional
101-
Other variables that may be relevant to the error. Defaults to None.
102-
"""
103-
104-
def __init__(self, description, arguments, extras=None):
105-
self.description = description
106-
self.arguments = arguments
107-
self.extras = extras
108-
self.message = self.description
109-
110-
for key in self.arguments:
111-
self.message += '\n' + str(key) + '=' + repr(self.arguments[key])
112-
if extras is not None:
113-
for key in self.extras:
114-
self.message += '\n' + str(key) + '=' + repr(self.extras[key])
115-
super(PackageNotFoundError, self).__init__(self.message)
116-
117-
118-
class PackageImportError(QctrlError):
119-
"""Exception raised when a package cannot be imported.
120-
121-
Parameters
122-
----------
123-
description : string
124-
Description of the why the error is raised.
125-
package_name : string, optional
126-
The name of the package that could not be imported. Defaults to None.
127-
"""
128-
def __init__(self, description, package_name=None):
129-
self.description = description
130-
self.package_name = package_name
131-
self.message = self.description
132-
133-
if package_name:
134-
self.message += '\n' + 'package' + '=' + repr(self.package_name)
135-
super(PackageImportError, self).__init__(self.message)

qctrlopencontrols/pyquil/program.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020

2121
import numpy as np
2222

23-
from pyquil import Program
24-
from pyquil.gates import I, RX, RY, RZ, MEASURE
25-
from pyquil.quil import Pragma
26-
2723
from ..dynamic_decoupling_sequences.dynamic_decoupling_sequence import DynamicDecouplingSequence
2824
from ..exceptions.exceptions import ArgumentsValueError
2925
from ..globals import (
3026
FIX_DURATION_UNITARY, INSTANT_UNITARY)
3127

3228

33-
def convert_dds_to_pyquil_program(
29+
def convert_dds_to_pyquil_program( #pylint: disable=too-many-locals
3430
dynamic_decoupling_sequence,
3531
target_qubits=None,
3632
gate_time=0.1,
@@ -93,6 +89,10 @@ def convert_dds_to_pyquil_program(
9389
any offset.
9490
"""
9591

92+
from pyquil import Program
93+
from pyquil.gates import I, RX, RY, RZ, MEASURE
94+
from pyquil.quil import Pragma
95+
9696
if dynamic_decoupling_sequence is None:
9797
raise ArgumentsValueError('No dynamic decoupling sequence provided.',
9898
{'dynamic_decoupling_sequence': dynamic_decoupling_sequence})

qctrlopencontrols/qiskit/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,3 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
"""
16-
==============
17-
qiskit module
18-
==============
19-
"""
20-
21-
# Minimum Qiskit version required
22-
QISKIT_TERRA_MINIMUM_VERSION = '0.8.2'

qctrlopencontrols/qiskit/quantum_circuit.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import numpy as np
2222

2323
from ..globals import (FIX_DURATION_UNITARY, INSTANT_UNITARY)
24-
from ..qiskit import QISKIT_TERRA_MINIMUM_VERSION
2524
from ..dynamic_decoupling_sequences.dynamic_decoupling_sequence import DynamicDecouplingSequence
26-
from ..exceptions.exceptions import ArgumentsValueError, PackageImportError
27-
from ..base.check_packages import check_package
25+
from ..exceptions.exceptions import ArgumentsValueError
2826

2927

3028
def convert_dds_to_qiskit_quantum_circuit(
@@ -73,12 +71,6 @@ def convert_dds_to_qiskit_quantum_circuit(
7371
------
7472
ArgumentsValueError
7573
If any of the input parameters are invalid
76-
PackageNotFoundError
77-
If Qiskit is not found
78-
PackageVersionMismatchError
79-
If the required minimum version of Qiskit is not found
80-
PackageImportError
81-
If Qiskit cannot be imported
8274
8375
Notes
8476
-----
@@ -101,16 +93,9 @@ def convert_dds_to_qiskit_quantum_circuit(
10193
any offset.
10294
"""
10395

104-
check_package('qiskit-terra', QISKIT_TERRA_MINIMUM_VERSION)
105-
106-
try:
107-
from qiskit import (
108-
QuantumRegister, ClassicalRegister, QuantumCircuit)
109-
from qiskit.qasm import pi
110-
except ImportError:
111-
raise PackageImportError(
112-
'Error while trying to import qiskit-terra.'
113-
)
96+
from qiskit import (
97+
QuantumRegister, ClassicalRegister, QuantumCircuit)
98+
from qiskit.qasm import pi
11499

115100
if dynamic_decoupling_sequence is None:
116101
raise ArgumentsValueError('No dynamic decoupling sequence provided.',

0 commit comments

Comments
 (0)