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

infra: onboard to use ruff #53

Merged
merged 7 commits into from
Dec 3, 2024
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
9 changes: 5 additions & 4 deletions examples/1_Getting_started_with_AutoQASM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"source": [
"# general imports\n",
"from collections import Counter\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq\n",
"from autoqasm.instructions import measure, h, cnot"
"from autoqasm.instructions import cnot, h, measure\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator"
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions examples/2_Expressing_classical_control_flow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
"source": [
"# general imports\n",
"from collections import Counter\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq\n",
"from autoqasm.instructions import measure, h, cnot"
"from autoqasm.instructions import cnot, h, measure\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator"
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions examples/3_1_Iterative_phase_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
"# general imports\n",
"import math\n",
"from collections import Counter\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq\n",
"from autoqasm.instructions import measure, x, rz, h, cphaseshift, reset"
"from autoqasm.instructions import cphaseshift, h, measure, reset, rz, x\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator"
]
},
{
Expand Down
16 changes: 8 additions & 8 deletions examples/3_2_magic_state_distillation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
"outputs": [],
"source": [
"# general imports\n",
"from collections import Counter, defaultdict\n",
"from typing import Dict, List\n",
"from collections import Counter\n",
"import numpy as np\n",
"from collections import defaultdict\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator\n",
"import numpy as np\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq\n",
"import autoqasm.instructions as ins"
"import autoqasm.instructions as ins\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import LocalSimulator"
]
},
{
Expand Down Expand Up @@ -288,7 +288,7 @@
" ins.y(0)\n",
"\n",
" # measure ancilla\n",
" c = ins.measure([1, 2, 3, 4])"
" c = ins.measure([1, 2, 3, 4]) # noqa: F841"
]
},
{
Expand Down Expand Up @@ -409,7 +409,7 @@
"\n",
" # measuring in the basis of magic state\n",
" basis_rotation_t_type(0)\n",
" c2 = ins.measure(0)"
" c2 = ins.measure(0) # noqa: F841"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions examples/4_Native_programming.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"# general imports\n",
"import IPython\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import Devices\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq"
"import autoqasm as aq\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.devices import Devices"
]
},
{
Expand Down Expand Up @@ -60,7 +60,7 @@
}
],
"source": [
"from autoqasm.instructions import h, cnot, measure\n",
"from autoqasm.instructions import cnot, h, measure\n",
"\n",
"\n",
"@aq.main\n",
Expand Down Expand Up @@ -437,7 +437,7 @@
}
],
"source": [
"from ionq_gates import h, cnot\n",
"from ionq_gates import cnot, h # noqa: F811\n",
"\n",
"\n",
"@aq.main\n",
Expand Down
10 changes: 5 additions & 5 deletions examples/5_Pulse_programming_and_dynamical_decoupling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"# general imports\n",
"import numpy as np\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.aws import AwsDevice\n",
"from braket.devices import Devices\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq\n",
"from autoqasm import pulse\n",
"from autoqasm.instructions import rx, rz"
"from autoqasm.instructions import rx, rz\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.aws import AwsDevice\n",
"from braket.devices import Devices"
]
},
{
Expand Down
14 changes: 7 additions & 7 deletions examples/6_Customize_gate_calibrations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
"# general imports\n",
"import numpy as np\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.aws import AwsDevice\n",
"from braket.devices import Devices\n",
"from braket.circuits import Gate, QubitSet, FreeParameter\n",
"from braket.pulse import DragGaussianWaveform\n",
"\n",
"# AutoQASM imports\n",
"import autoqasm as aq\n",
"from autoqasm import pulse\n",
"from autoqasm.instructions import rx, rz, measure"
"from autoqasm.instructions import measure, rx, rz\n",
"\n",
"# AWS imports: Import Braket SDK modules\n",
"from braket.aws import AwsDevice\n",
"from braket.circuits import FreeParameter, Gate, QubitSet\n",
"from braket.devices import Devices\n",
"from braket.pulse import DragGaussianWaveform"
]
},
{
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
[tool.black]
[tool.ruff]
target-version = "py39"
line-length = 100
lint.isort = { known-first-party = [
"braket",
] }
lint.extend-select = ["I"]
lint.preview = true


26 changes: 0 additions & 26 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,3 @@ filterwarnings=
# Ref: https://github.com/pytest-dev/pytest-cov/issues/557
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

[isort]
line_length = 100
multi_line_output = 3
include_trailing_comma = true
profile = black

[flake8]
ignore =
# not pep8, black adds whitespace before ':'
E203,
# not pep8, https://www.python.org/dev/peps/pep-0008/#pet-peeves
E231,
# not pep8, black adds line break before binary operator
W503,
# Google Python style is not RST until after processed by Napoleon
# See https://github.com/peterjc/flake8-rst-docstrings/issues/17
RST201,RST203,RST301,
max_line_length = 100
max-complexity = 10
exclude =
__pycache__
.tox
.git
bin
build
venv
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@
],
extras_require={
"test": [
"black",
"botocore",
"flake8<=5.0.4",
"isort",
"jsonschema==3.2.0",
"pre-commit",
"pylint",
"pytest",
"pytest-cov",
"pytest-rerunfailures",
"pytest-xdist[psutil]",
"ruff",
"sphinx",
"sphinx-rtd-theme",
"sphinxcontrib-apidoc",
Expand Down
1 change: 1 addition & 0 deletions src/autoqasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def my_program():
result[0] = measure __qubits__[0];
result[1] = measure __qubits__[1];
"""

from . import errors, instructions, operators # noqa: F401
from .api import gate, gate_calibration, main, subroutine # noqa: F401
from .hybrid_job import hybrid_job # noqa: F401
Expand Down
5 changes: 3 additions & 2 deletions src/autoqasm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,9 @@ def _get_gate_args(f: Callable) -> aq_program.GateArgs:

if param.annotation == aq_instructions.QubitIdentifierType:
gate_args.append_qubit(param.name)
elif param.annotation == float or any(
type_ == float for type_ in get_args(param.annotation)
elif param.annotation == float or any( # noqa: E721
type_ == float # noqa: E721
for type_ in get_args(param.annotation)
):
gate_args.append_angle(param.name)
else:
Expand Down
5 changes: 1 addition & 4 deletions src/autoqasm/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

"""Errors raised in the AutoQASM build process."""


from __future__ import annotations


Expand Down Expand Up @@ -96,9 +95,7 @@ def __init__(self, true_type: type | None, false_type: type | None):
self.message = """\
`if` clause resolves to {}, but `else` clause resolves to {}. \
Both the `if` and `else` clauses of an inline conditional expression \
must resolve to the same type.""".format(
if_type, else_type
)
must resolve to the same type.""".format(if_type, else_type)

def __str__(self):
return self.message
Expand Down
2 changes: 1 addition & 1 deletion src/autoqasm/instructions/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from typing import Union

import oqpy
from braket.circuits.free_parameter_expression import FreeParameterExpression

from autoqasm.instructions.instructions import _qubit_instruction
from autoqasm.types import QubitIdentifierType
from braket.circuits.free_parameter_expression import FreeParameterExpression

GateParameterType = Union[float, FreeParameterExpression, oqpy._ClassicalVar]

Expand Down
2 changes: 1 addition & 1 deletion src/autoqasm/instructions/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
from typing import Any

import oqpy
from braket.circuits.basis_state import BasisState, BasisStateInput

from autoqasm import program as aq_program
from autoqasm import types as aq_types
from autoqasm.instructions.qubits import _qubit
from autoqasm.types import QubitIdentifierType
from braket.circuits.basis_state import BasisState, BasisStateInput


def _qubit_instruction(
Expand Down
26 changes: 15 additions & 11 deletions src/autoqasm/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@
from .comparisons import gt_, gteq_, lt_, lteq_ # noqa: F401
from .conditional_expressions import if_exp # noqa: F401
from .control_flow import for_stmt, if_stmt, while_stmt # noqa: F401
from .data_structures import ListPopOpts # noqa: F401
from .data_structures import ListStackOpts # noqa: F401
from .data_structures import list_append # noqa: F401
from .data_structures import list_pop # noqa: F401
from .data_structures import list_stack # noqa: F401
from .data_structures import new_list # noqa: F401
from .data_structures import (
ListPopOpts, # noqa: F401
ListStackOpts, # noqa: F401
list_append, # noqa: F401
list_pop, # noqa: F401
list_stack, # noqa: F401
new_list, # noqa: F401
)
from .exceptions import assert_stmt # noqa: F401
from .logical import and_ # noqa: F401
from .logical import eq # noqa: F401
from .logical import not_ # noqa: F401
from .logical import not_eq # noqa: F401
from .logical import or_ # noqa: F401
from .logical import (
and_, # noqa: F401
eq, # noqa: F401
not_, # noqa: F401
not_eq, # noqa: F401
or_, # noqa: F401
)
from .return_statements import return_output_from_main # noqa: F401
from .slices import GetItemOpts, get_item, set_item # noqa: F401
from .typecast import int_ # noqa: F401
2 changes: 1 addition & 1 deletion src/autoqasm/operators/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

"""Operators for arithmetic operators: // """
"""Operators for arithmetic operators: //"""

from __future__ import annotations

Expand Down
1 change: 1 addition & 0 deletions src/autoqasm/operators/typecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


"""Operators for int cast statements."""

from __future__ import annotations

from typing import Any
Expand Down
3 changes: 1 addition & 2 deletions src/autoqasm/program/pragmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def pragma_example() -> None:
from enum import Enum
from typing import Iterable

from braket.device_schema import DeviceActionType

from autoqasm import errors, program
from braket.device_schema import DeviceActionType


class PragmaType(str, Enum):
Expand Down
12 changes: 6 additions & 6 deletions src/autoqasm/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

import oqpy.base
import pygments
from braket.aws.aws_device import AwsDevice
from braket.circuits.free_parameter_expression import FreeParameterExpression
from braket.circuits.serialization import IRType, SerializableProgram
from braket.device_schema import DeviceActionType
from braket.devices.device import Device
from braket.pulse.ast.qasm_parser import ast_to_qasm
from openpulse import ast
from openqasm_pygments import OpenQASM3Lexer
from pygments.formatters.terminal import TerminalFormatter
Expand All @@ -44,6 +38,12 @@
SerializationProperties,
)
from autoqasm.types import QubitIdentifierType as Qubit
from braket.aws.aws_device import AwsDevice
from braket.circuits.free_parameter_expression import FreeParameterExpression
from braket.circuits.serialization import IRType, SerializableProgram
from braket.device_schema import DeviceActionType
from braket.devices.device import Device
from braket.pulse.ast.qasm_parser import ast_to_qasm

# Create the thread-local object for the program conversion context.
_local = threading.local()
Expand Down
Loading
Loading