Skip to content

Commit c3272a0

Browse files
authored
🎨 Rename Python classes to not violate N801 (#523)
## Description This PR renames all Python classes to not violate [N801](https://docs.astral.sh/ruff/rules/invalid-class-name/). ## Checklist: - [x] The pull request only contains commits that are focused and relevant to this change. - [x] ~I have added appropriate tests that cover the new/changed functionality.~ - [x] ~I have updated the documentation to reflect these changes.~ - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes.
1 parent b886a91 commit c3272a0

File tree

7 files changed

+152
-121
lines changed

7 files changed

+152
-121
lines changed

bindings/bindings.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,27 @@ NB_MODULE(MQT_SYREC_MODULE_NAME, m) {
184184

185185
m.doc() = "Python interface for the SyReC programming language for the synthesis of reversible circuits";
186186

187-
nb::class_<QubitInliningStack::QubitInliningStackEntry>(m, "qubit_inlining_stack_entry")
187+
nb::class_<QubitInliningStack::QubitInliningStackEntry>(m, "QubitInliningStackEntry")
188188
.def(nb::init<>(), "Constructs an empty qubit inlining stack entry")
189189
.def_prop_ro("line_number_of_call_of_target_module", [](const QubitInliningStack::QubitInliningStackEntry& stackEntry) { return stackEntry.lineNumberOfCallOfTargetModule; }, "Returns the line number in the source file in which the call statement variant was defined")
190190
.def_prop_ro("is_target_module_accessed_via_call_stmt", [](const QubitInliningStack::QubitInliningStackEntry& stackEntry) { return stackEntry.isTargetModuleAccessedViaCallStmt; }, "Returns whether the target module was called using a CallStatement")
191191
.def_prop_ro("stringified_signature_of_called_module", &QubitInliningStack::QubitInliningStackEntry::stringifySignatureOfCalledModule, "Returns the stringified target module signature");
192192

193-
nb::class_<QubitInliningStack>(m, "qubit_inlining_stack")
193+
nb::class_<QubitInliningStack>(m, "QubitInliningStack")
194194
.def(nb::init<>(), "Constructs an empty qubit inlining stack")
195195
.def("size", &QubitInliningStack::size, "Get the number of stack entries")
196196
.def("__getitem__", &QubitInliningStack::getStackEntryAt, "idx"_a, nb::rv_policy::reference_internal);
197197

198-
nb::class_<AnnotatableQuantumComputation::InlinedQubitInformation>(m, "inlined_qubit_information")
198+
nb::class_<AnnotatableQuantumComputation::InlinedQubitInformation>(m, "InlinedQubitInformation")
199199
.def(nb::init<>(), "Constructs an empty inlined qubit information container")
200200
.def_prop_ro("user_declared_qubit_label", [](const AnnotatableQuantumComputation::InlinedQubitInformation& inlinedQubitInfo) { return inlinedQubitInfo.userDeclaredQubitLabel; }, "Get the label of the qubit as defined by the user in the SyReC program")
201201
.def_prop_ro("inline_stack", [](const AnnotatableQuantumComputation::InlinedQubitInformation& inlinedQubitInfo) { return inlinedQubitInfo.inlineStack; }, "Get the inline stack associated with the qubit");
202202

203-
nb::enum_<AnnotatableQuantumComputation::QubitLabelType>(m, "qubit_label_type")
203+
nb::enum_<AnnotatableQuantumComputation::QubitLabelType>(m, "QubitLabelType")
204204
.value("internal", AnnotatableQuantumComputation::QubitLabelType::Internal, "Generate the qubit label using the internal qubit identifier (only available for ancillary qubits and local SyReC module variables)")
205205
.value("user_declared", AnnotatableQuantumComputation::QubitLabelType::UserDeclared, "Generate the qubit label using the user declared variable identifier (only available for the qubits of the variables of a SyReC program [ancillary qubits are not associated with a variable and thus have no user declared label])");
206206

207-
nb::class_<AnnotatableQuantumComputation, qc::QuantumComputation>(m, "annotatable_quantum_computation")
207+
nb::class_<AnnotatableQuantumComputation, qc::QuantumComputation>(m, "AnnotatableQuantumComputation")
208208
.def(nb::init<>(), "Constructs an annotatable quantum computation")
209209
.def(nb::init<bool>(), "generate_quantum_operation_annotations"_a, "Constructs an annotatable quantum computation while also specifying whether quantum operation annotations can be generated")
210210
.def("get_qubit_label", &AnnotatableQuantumComputation::getQubitLabel, "qubit"_a, "qubit_label_type"_a, "Get either the internal or user-declared label of a qubit as a stringified SyReC variable access based on its location in the quantum register storing the qubit and, optionally, the layout of the SyReC variable stored in the register.")
@@ -213,7 +213,7 @@ NB_MODULE(MQT_SYREC_MODULE_NAME, m) {
213213
.def("get_annotations_of_quantum_operation", &AnnotatableQuantumComputation::getAnnotationsOfQuantumOperation, "quantum_operation_index_in_quantum_operation"_a, "Get the annotations of a specific quantum operation in the quantum computation")
214214
.def("get_inlined_qubit_information", &AnnotatableQuantumComputation::getInlinedQubitInformation, "qubit"_a, "Get the inlined information of a qubit");
215215

216-
nb::class_<NBitValuesContainer>(m, "n_bit_values_container")
216+
nb::class_<NBitValuesContainer>(m, "NBitValuesContainer")
217217
.def(nb::init<>(), "Constructs an empty container of size zero.")
218218
.def(nb::init<std::size_t>(), "n"_a, "Constructs a zero-initialized container of size n.")
219219
.def(nb::init<std::size_t, uint64_t>(), "n"_a, "initial_line_values"_a, "Constructs a container of size n from an integer initial_line_values")
@@ -227,15 +227,15 @@ NB_MODULE(MQT_SYREC_MODULE_NAME, m) {
227227
.def("flip", &NBitValuesContainer::flip, "n"_a, "Flip the value of the bit at position n")
228228
.def("__str__", [](const NBitValuesContainer& container) { return container.stringify(); }, "Returns a string containing the stringified values of the stored bits.");
229229

230-
nb::class_<Statistics>(m, "statistics")
230+
nb::class_<Statistics>(m, "Statistics")
231231
.def(nb::init<>(), "Constructs an object to record collected statistics.")
232232
.def_rw("runtime_in_milliseconds", &Statistics::runtimeInMilliseconds, "The recorded runtime in milliseconds");
233233

234-
nb::enum_<utils::IntegerConstantTruncationOperation>(m, "integer_constant_truncation_operation")
234+
nb::enum_<utils::IntegerConstantTruncationOperation>(m, "IntegerConstantTruncationOperation")
235235
.value("modulo", utils::IntegerConstantTruncationOperation::Modulo, "Use the modulo operation for the truncation of constant values")
236236
.value("bitwise_and", utils::IntegerConstantTruncationOperation::BitwiseAnd, "Use the bitwise AND operation for the truncation of constant values");
237237

238-
nb::class_<ConfigurableOptions>(m, "configurable_options")
238+
nb::class_<ConfigurableOptions>(m, "ConfigurableOptions")
239239
.def(nb::init<>(), "Constructs a configurable options object.")
240240
.def_rw("default_bitwidth", &ConfigurableOptions::defaultBitwidth, "Defines the default variable bitwidth used by the SyReC parser for variables whose bitwidth specification was omitted")
241241
.def_rw("integer_constant_truncation_operation", &ConfigurableOptions::integerConstantTruncationOperation, "Defines the operation used by the SyReC parser for the truncation of integer constant values. For further details we refer to the semantics of the SyReC language")
@@ -244,7 +244,7 @@ NB_MODULE(MQT_SYREC_MODULE_NAME, m) {
244244
.def_rw("generate_inlined_qubit_debug_information", &ConfigurableOptions::generatedInlinedQubitDebugInformation, "Should debug information for the qubits associated with the local variables of a SyReC module be generated")
245245
.def_rw("generate_quantum_operation_annotations", &ConfigurableOptions::generateQuantumOperationAnnotations, "Should the optional quantum operation annotations be generated during the synthesis of a SyReC program, disabled by default");
246246

247-
nb::class_<Program>(m, "program")
247+
nb::class_<Program>(m, "Program")
248248
.def(nb::init<>(), "Constructs SyReC program object.")
249249
.def("read", &Program::read, "filename"_a, "configurable_options"_a = ConfigurableOptions(), "Read and process a SyReC program from a file.")
250250
.def("read_from_string", &Program::readFromString, "stringified_program"_a, "configurable_options"_a = ConfigurableOptions(), "Process an already stringified SyReC program.");

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"nanobind>=2.10.2",
3+
"nanobind==2.10.2",
44
"scikit-build-core>=0.11.6",
55
"setuptools-scm>=9.2.2",
66
"mqt.core~=3.4.0",
@@ -229,7 +229,7 @@ known-first-party = ["mqt.syrec"]
229229
"docs/**" = ["T20"]
230230
"python/mqt/syrec/syrec_editor.py" = ["T20"]
231231
"noxfile.py" = ["T20", "TID251"]
232-
"*.pyi" = ["D418", "E501", "N801", "PYI021"]
232+
"*.pyi" = ["D418", "E501", "PYI021"]
233233
"*.ipynb" = [
234234
"D", # pydocstyle
235235
"E402", # Allow imports to appear anywhere in Jupyter notebooks
@@ -326,7 +326,7 @@ mqt-syrec = { workspace = true }
326326

327327
[dependency-groups]
328328
build = [
329-
"nanobind>=2.10.2",
329+
"nanobind==2.10.2",
330330
"scikit-build-core>=0.11.6",
331331
"setuptools-scm>=9.2.2",
332332
"mqt.core~=3.4.0",

python/mqt/syrec/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,34 @@ def _dll_patch() -> None:
3333

3434
from ._version import version as __version__
3535
from .pysyrec import (
36-
annotatable_quantum_computation,
37-
configurable_options,
36+
AnnotatableQuantumComputation,
37+
ConfigurableOptions,
38+
InlinedQubitInformation,
39+
IntegerConstantTruncationOperation,
40+
NBitValuesContainer,
41+
Program,
42+
QubitInliningStack,
43+
QubitInliningStackEntry,
44+
QubitLabelType,
45+
Statistics,
3846
cost_aware_synthesis,
39-
inlined_qubit_information,
40-
integer_constant_truncation_operation,
4147
line_aware_synthesis,
42-
n_bit_values_container,
43-
program,
44-
qubit_inlining_stack,
45-
qubit_inlining_stack_entry,
46-
qubit_label_type,
4748
simple_simulation,
48-
statistics,
4949
)
5050

5151
__all__ = [
52+
"AnnotatableQuantumComputation",
53+
"ConfigurableOptions",
54+
"InlinedQubitInformation",
55+
"IntegerConstantTruncationOperation",
56+
"NBitValuesContainer",
57+
"Program",
58+
"QubitInliningStack",
59+
"QubitInliningStackEntry",
60+
"QubitLabelType",
61+
"Statistics",
5262
"__version__",
53-
"annotatable_quantum_computation",
54-
"configurable_options",
5563
"cost_aware_synthesis",
56-
"inlined_qubit_information",
57-
"integer_constant_truncation_operation",
5864
"line_aware_synthesis",
59-
"n_bit_values_container",
60-
"program",
61-
"qubit_inlining_stack",
62-
"qubit_inlining_stack_entry",
63-
"qubit_label_type",
6465
"simple_simulation",
65-
"statistics",
6666
]

python/mqt/syrec/pysyrec.pyi

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from typing import overload
1111

1212
import mqt.core.ir
1313

14-
class qubit_inlining_stack_entry:
14+
class QubitInliningStackEntry:
1515
def __init__(self) -> None:
1616
"""Constructs an empty qubit inlining stack entry"""
1717

@@ -29,16 +29,16 @@ class qubit_inlining_stack_entry:
2929
def stringified_signature_of_called_module(self) -> str | None:
3030
"""Returns the stringified target module signature"""
3131

32-
class qubit_inlining_stack:
32+
class QubitInliningStack:
3333
def __init__(self) -> None:
3434
"""Constructs an empty qubit inlining stack"""
3535

3636
def size(self) -> int:
3737
"""Get the number of stack entries"""
3838

39-
def __getitem__(self, idx: int) -> qubit_inlining_stack_entry: ...
39+
def __getitem__(self, idx: int) -> QubitInliningStackEntry: ...
4040

41-
class inlined_qubit_information:
41+
class InlinedQubitInformation:
4242
def __init__(self) -> None:
4343
"""Constructs an empty inlined qubit information container"""
4444

@@ -47,10 +47,10 @@ class inlined_qubit_information:
4747
"""Get the label of the qubit as defined by the user in the SyReC program"""
4848

4949
@property
50-
def inline_stack(self) -> qubit_inlining_stack | None:
50+
def inline_stack(self) -> QubitInliningStack | None:
5151
"""Get the inline stack associated with the qubit"""
5252

53-
class qubit_label_type(enum.Enum):
53+
class QubitLabelType(enum.Enum):
5454
internal = 0
5555
"""
5656
Generate the qubit label using the internal qubit identifier (only available for ancillary qubits and local SyReC module variables)
@@ -61,7 +61,7 @@ class qubit_label_type(enum.Enum):
6161
Generate the qubit label using the user declared variable identifier (only available for the qubits of the variables of a SyReC program [ancillary qubits are not associated with a variable and thus have no user declared label])
6262
"""
6363

64-
class annotatable_quantum_computation(mqt.core.ir.QuantumComputation):
64+
class AnnotatableQuantumComputation(mqt.core.ir.QuantumComputation):
6565
@overload
6666
def __init__(self) -> None:
6767
"""Constructs an annotatable quantum computation"""
@@ -72,7 +72,7 @@ class annotatable_quantum_computation(mqt.core.ir.QuantumComputation):
7272
Constructs an annotatable quantum computation while also specifying whether quantum operation annotations can be generated
7373
"""
7474

75-
def get_qubit_label(self, qubit: int, qubit_label_type: qubit_label_type) -> str | None:
75+
def get_qubit_label(self, qubit: int, qubit_label_type: QubitLabelType) -> str | None:
7676
"""
7777
Get either the internal or user-declared label of a qubit as a stringified SyReC variable access based on its location in the quantum register storing the qubit and, optionally, the layout of the SyReC variable stored in the register.
7878
"""
@@ -88,10 +88,10 @@ class annotatable_quantum_computation(mqt.core.ir.QuantumComputation):
8888
Get the annotations of a specific quantum operation in the quantum computation
8989
"""
9090

91-
def get_inlined_qubit_information(self, qubit: int) -> inlined_qubit_information | None:
91+
def get_inlined_qubit_information(self, qubit: int) -> InlinedQubitInformation | None:
9292
"""Get the inlined information of a qubit"""
9393

94-
class n_bit_values_container:
94+
class NBitValuesContainer:
9595
@overload
9696
def __init__(self) -> None:
9797
"""Constructs an empty container of size zero."""
@@ -128,7 +128,7 @@ class n_bit_values_container:
128128
def flip(self, n: int) -> bool:
129129
"""Flip the value of the bit at position n"""
130130

131-
class statistics:
131+
class Statistics:
132132
def __init__(self) -> None:
133133
"""Constructs an object to record collected statistics."""
134134

@@ -139,14 +139,14 @@ class statistics:
139139
@runtime_in_milliseconds.setter
140140
def runtime_in_milliseconds(self, arg: float, /) -> None: ...
141141

142-
class integer_constant_truncation_operation(enum.Enum):
142+
class IntegerConstantTruncationOperation(enum.Enum):
143143
modulo = 0
144144
"""Use the modulo operation for the truncation of constant values"""
145145

146146
bitwise_and = 1
147147
"""Use the bitwise AND operation for the truncation of constant values"""
148148

149-
class configurable_options:
149+
class ConfigurableOptions:
150150
def __init__(self) -> None:
151151
"""Constructs a configurable options object."""
152152

@@ -159,13 +159,13 @@ class configurable_options:
159159
@default_bitwidth.setter
160160
def default_bitwidth(self, arg: int, /) -> None: ...
161161
@property
162-
def integer_constant_truncation_operation(self) -> integer_constant_truncation_operation:
162+
def integer_constant_truncation_operation(self) -> IntegerConstantTruncationOperation:
163163
"""
164164
Defines the operation used by the SyReC parser for the truncation of integer constant values. For further details we refer to the semantics of the SyReC language
165165
"""
166166

167167
@integer_constant_truncation_operation.setter
168-
def integer_constant_truncation_operation(self, arg: integer_constant_truncation_operation, /) -> None: ...
168+
def integer_constant_truncation_operation(self, arg: IntegerConstantTruncationOperation, /) -> None: ...
169169
@property
170170
def allow_access_on_assigned_to_variable_parts_in_dimension_access_of_variable_access(self) -> bool:
171171
"""
@@ -201,36 +201,36 @@ class configurable_options:
201201
@generate_quantum_operation_annotations.setter
202202
def generate_quantum_operation_annotations(self, arg: bool, /) -> None: ...
203203

204-
class program:
204+
class Program:
205205
def __init__(self) -> None:
206206
"""Constructs SyReC program object."""
207207

208-
def read(self, filename: str, configurable_options: configurable_options = ...) -> str:
208+
def read(self, filename: str, configurable_options: ConfigurableOptions = ...) -> str:
209209
"""Read and process a SyReC program from a file."""
210210

211-
def read_from_string(self, stringified_program: str, configurable_options: configurable_options = ...) -> str:
211+
def read_from_string(self, stringified_program: str, configurable_options: ConfigurableOptions = ...) -> str:
212212
"""Process an already stringified SyReC program."""
213213

214214
def cost_aware_synthesis(
215-
annotated_quantum_computation: annotatable_quantum_computation,
216-
program: program,
217-
configurable_options: configurable_options = ...,
218-
optional_recorded_statistics: statistics | None = None,
215+
annotated_quantum_computation: AnnotatableQuantumComputation,
216+
program: Program,
217+
configurable_options: ConfigurableOptions = ...,
218+
optional_recorded_statistics: Statistics | None = None,
219219
) -> bool:
220220
"""Cost-aware synthesis of the SyReC program."""
221221

222222
def line_aware_synthesis(
223-
annotated_quantum_computation: annotatable_quantum_computation,
224-
program: program,
225-
configurable_options: configurable_options = ...,
226-
optional_recorded_statistics: statistics | None = None,
223+
annotated_quantum_computation: AnnotatableQuantumComputation,
224+
program: Program,
225+
configurable_options: ConfigurableOptions = ...,
226+
optional_recorded_statistics: Statistics | None = None,
227227
) -> bool:
228228
"""Line-aware synthesis of the SyReC program."""
229229

230230
def simple_simulation(
231-
output: n_bit_values_container,
231+
output: NBitValuesContainer,
232232
quantum_computation: mqt.core.ir.QuantumComputation,
233-
input_: n_bit_values_container,
234-
optional_recorded_statistics: statistics | None = None,
233+
input_: NBitValuesContainer,
234+
optional_recorded_statistics: Statistics | None = None,
235235
) -> None:
236236
"""Simulation of a synthesized SyReC program"""

0 commit comments

Comments
 (0)