diff --git a/examples/1_Getting_started_with_AutoQASM.ipynb b/examples/1_Getting_started_with_AutoQASM.ipynb index cd89a7d..35da038 100644 --- a/examples/1_Getting_started_with_AutoQASM.ipynb +++ b/examples/1_Getting_started_with_AutoQASM.ipynb @@ -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" ] }, { diff --git a/examples/2_Expressing_classical_control_flow.ipynb b/examples/2_Expressing_classical_control_flow.ipynb index eef0d51..25ec1c5 100644 --- a/examples/2_Expressing_classical_control_flow.ipynb +++ b/examples/2_Expressing_classical_control_flow.ipynb @@ -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" ] }, { diff --git a/examples/3_1_Iterative_phase_estimation.ipynb b/examples/3_1_Iterative_phase_estimation.ipynb index 4a8a93c..6275889 100644 --- a/examples/3_1_Iterative_phase_estimation.ipynb +++ b/examples/3_1_Iterative_phase_estimation.ipynb @@ -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" ] }, { diff --git a/examples/3_2_magic_state_distillation.ipynb b/examples/3_2_magic_state_distillation.ipynb index bd5ef5d..320106b 100644 --- a/examples/3_2_magic_state_distillation.ipynb +++ b/examples/3_2_magic_state_distillation.ipynb @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { diff --git a/examples/4_Native_programming.ipynb b/examples/4_Native_programming.ipynb index 6cd72fb..a8bc91a 100644 --- a/examples/4_Native_programming.ipynb +++ b/examples/4_Native_programming.ipynb @@ -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" ] }, { @@ -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", @@ -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", diff --git a/examples/5_Pulse_programming_and_dynamical_decoupling.ipynb b/examples/5_Pulse_programming_and_dynamical_decoupling.ipynb index aa5237b..b739f09 100644 --- a/examples/5_Pulse_programming_and_dynamical_decoupling.ipynb +++ b/examples/5_Pulse_programming_and_dynamical_decoupling.ipynb @@ -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" ] }, { diff --git a/examples/6_Customize_gate_calibrations.ipynb b/examples/6_Customize_gate_calibrations.ipynb index c0b14fa..e0e5369 100644 --- a/examples/6_Customize_gate_calibrations.ipynb +++ b/examples/6_Customize_gate_calibrations.ipynb @@ -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" ] }, { diff --git a/pyproject.toml b/pyproject.toml index aa4949a..7b2a144 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 + + diff --git a/setup.cfg b/setup.cfg index d75c4f0..2c3421d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py index 3fa424d..8b201a3 100644 --- a/setup.py +++ b/setup.py @@ -39,10 +39,7 @@ ], extras_require={ "test": [ - "black", "botocore", - "flake8<=5.0.4", - "isort", "jsonschema==3.2.0", "pre-commit", "pylint", @@ -50,6 +47,7 @@ "pytest-cov", "pytest-rerunfailures", "pytest-xdist[psutil]", + "ruff", "sphinx", "sphinx-rtd-theme", "sphinxcontrib-apidoc", diff --git a/src/autoqasm/__init__.py b/src/autoqasm/__init__.py index 113f36c..41ddd7b 100644 --- a/src/autoqasm/__init__.py +++ b/src/autoqasm/__init__.py @@ -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 diff --git a/src/autoqasm/api.py b/src/autoqasm/api.py index 9de784b..386c279 100644 --- a/src/autoqasm/api.py +++ b/src/autoqasm/api.py @@ -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: diff --git a/src/autoqasm/errors.py b/src/autoqasm/errors.py index 2b259f8..d052fa4 100644 --- a/src/autoqasm/errors.py +++ b/src/autoqasm/errors.py @@ -13,7 +13,6 @@ """Errors raised in the AutoQASM build process.""" - from __future__ import annotations @@ -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 diff --git a/src/autoqasm/instructions/gates.py b/src/autoqasm/instructions/gates.py index d858ac8..24c8aa7 100644 --- a/src/autoqasm/instructions/gates.py +++ b/src/autoqasm/instructions/gates.py @@ -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] diff --git a/src/autoqasm/instructions/instructions.py b/src/autoqasm/instructions/instructions.py index 5a0024b..3db70e4 100644 --- a/src/autoqasm/instructions/instructions.py +++ b/src/autoqasm/instructions/instructions.py @@ -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( diff --git a/src/autoqasm/operators/__init__.py b/src/autoqasm/operators/__init__.py index 4486cf4..171aa8b 100644 --- a/src/autoqasm/operators/__init__.py +++ b/src/autoqasm/operators/__init__.py @@ -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 diff --git a/src/autoqasm/operators/arithmetic.py b/src/autoqasm/operators/arithmetic.py index 1decb7d..baa9762 100644 --- a/src/autoqasm/operators/arithmetic.py +++ b/src/autoqasm/operators/arithmetic.py @@ -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 diff --git a/src/autoqasm/operators/typecast.py b/src/autoqasm/operators/typecast.py index ef808c2..e2f59bf 100644 --- a/src/autoqasm/operators/typecast.py +++ b/src/autoqasm/operators/typecast.py @@ -13,6 +13,7 @@ """Operators for int cast statements.""" + from __future__ import annotations from typing import Any diff --git a/src/autoqasm/program/pragmas.py b/src/autoqasm/program/pragmas.py index 49b31d2..4172ab9 100644 --- a/src/autoqasm/program/pragmas.py +++ b/src/autoqasm/program/pragmas.py @@ -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): diff --git a/src/autoqasm/program/program.py b/src/autoqasm/program/program.py index d833bfa..6eacaed 100644 --- a/src/autoqasm/program/program.py +++ b/src/autoqasm/program/program.py @@ -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 @@ -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() diff --git a/src/autoqasm/pulse/pulse.py b/src/autoqasm/pulse/pulse.py index 790eb9d..1a43cf7 100644 --- a/src/autoqasm/pulse/pulse.py +++ b/src/autoqasm/pulse/pulse.py @@ -17,6 +17,10 @@ from __future__ import annotations import oqpy + +from autoqasm import program as aq_program +from autoqasm.instructions.qubits import _get_physical_qubit_indices +from autoqasm.types import BitVar, QubitIdentifierType, is_qubit_identifier_type from braket.parametric import FreeParameterExpression from braket.parametric.free_parameter import FreeParameter from braket.pulse import PulseSequence @@ -25,10 +29,6 @@ from braket.pulse.waveforms import Waveform from braket.registers.qubit_set import QubitSet -from autoqasm import program as aq_program -from autoqasm.instructions.qubits import _get_physical_qubit_indices -from autoqasm.types import BitVar, QubitIdentifierType, is_qubit_identifier_type - def _pulse_instruction(name: str, frame: Frame, *args) -> None: """Define a pulse instruction. diff --git a/src/autoqasm/simulator/conversion.py b/src/autoqasm/simulator/conversion.py index 31981be..a162e24 100644 --- a/src/autoqasm/simulator/conversion.py +++ b/src/autoqasm/simulator/conversion.py @@ -15,6 +15,7 @@ from typing import Any, Union import numpy as np + from braket.default_simulator.openqasm._helpers.casting import convert_bool_array_to_string from braket.default_simulator.openqasm.parser.openqasm_ast import ( ArrayLiteral, diff --git a/src/autoqasm/simulator/native_interpreter.py b/src/autoqasm/simulator/native_interpreter.py index 7da4307..2ab49cc 100644 --- a/src/autoqasm/simulator/native_interpreter.py +++ b/src/autoqasm/simulator/native_interpreter.py @@ -16,6 +16,9 @@ from logging import Logger from typing import Any, List, Optional, Union +from openqasm3.ast import IntegerLiteral + +from autoqasm.simulator.program_context import McmProgramContext from braket.default_simulator.openqasm._helpers.casting import cast_to, wrap_value_into_literal from braket.default_simulator.openqasm.interpreter import Interpreter from braket.default_simulator.openqasm.parser.openqasm_ast import ( @@ -34,9 +37,6 @@ ) from braket.default_simulator.openqasm.parser.openqasm_parser import parse from braket.default_simulator.simulation import Simulation -from openqasm3.ast import IntegerLiteral - -from autoqasm.simulator.program_context import McmProgramContext class NativeInterpreter(Interpreter): diff --git a/src/autoqasm/simulator/program_context.py b/src/autoqasm/simulator/program_context.py index 8b1f1da..f48bf2c 100644 --- a/src/autoqasm/simulator/program_context.py +++ b/src/autoqasm/simulator/program_context.py @@ -18,6 +18,9 @@ from typing import Optional, Union import numpy as np +from sympy import Integer + +from autoqasm.simulator.conversion import convert_to_output from braket.default_simulator.openqasm._helpers.arrays import ( convert_discrete_set_to_list, convert_range_def_to_slice, @@ -34,9 +37,6 @@ ) from braket.default_simulator.openqasm.program_context import ProgramContext, Table from braket.default_simulator.operation import GateOperation -from sympy import Integer - -from autoqasm.simulator.conversion import convert_to_output class QubitTable(Table): diff --git a/src/autoqasm/simulator/simulation.py b/src/autoqasm/simulator/simulation.py index 18b0fc4..ef53e72 100644 --- a/src/autoqasm/simulator/simulation.py +++ b/src/autoqasm/simulator/simulation.py @@ -12,12 +12,12 @@ # language governing permissions and limitations under the License. import numpy as np + +from autoqasm.simulator.linalg_utils import measurement_collapse_sv, measurement_sample from braket.default_simulator import StateVectorSimulation from braket.default_simulator.gate_operations import PauliX from braket.default_simulator.linalg_utils import marginal_probability -from autoqasm.simulator.linalg_utils import measurement_collapse_sv, measurement_sample - class Simulation(StateVectorSimulation): def add_qubits(self, num_qubits: int) -> None: diff --git a/src/autoqasm/simulator/simulator.py b/src/autoqasm/simulator/simulator.py index 60a9e98..470e01e 100644 --- a/src/autoqasm/simulator/simulator.py +++ b/src/autoqasm/simulator/simulator.py @@ -11,15 +11,14 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +from autoqasm.simulator.native_interpreter import NativeInterpreter +from autoqasm.simulator.program_context import McmProgramContext +from autoqasm.simulator.simulation import Simulation from braket.default_simulator import StateVectorSimulator from braket.ir.openqasm import Program as OpenQASMProgram from braket.task_result import AdditionalMetadata, TaskMetadata from braket.tasks import GateModelQuantumTaskResult -from autoqasm.simulator.native_interpreter import NativeInterpreter -from autoqasm.simulator.program_context import McmProgramContext -from autoqasm.simulator.simulation import Simulation - class McmSimulator(StateVectorSimulator): DEVICE_ID = "autoqasm" diff --git a/src/autoqasm/types/types.py b/src/autoqasm/types/types.py index 11bcf2c..2b7ad0c 100644 --- a/src/autoqasm/types/types.py +++ b/src/autoqasm/types/types.py @@ -21,11 +21,11 @@ import numpy as np import oqpy import oqpy.base -from braket.circuits import FreeParameterExpression -from braket.registers import Qubit from openpulse import ast from autoqasm import errors, program +from braket.circuits import FreeParameterExpression +from braket.registers import Qubit def is_qasm_type(val: Any) -> bool: diff --git a/test/unit_tests/autoqasm/test_api.py b/test/unit_tests/autoqasm/test_api.py index 3ee0c3c..81409df 100644 --- a/test/unit_tests/autoqasm/test_api.py +++ b/test/unit_tests/autoqasm/test_api.py @@ -19,13 +19,13 @@ import math import pytest -from braket.devices import LocalSimulator -from braket.tasks.local_quantum_task import LocalQuantumTask import autoqasm as aq from autoqasm import errors from autoqasm.instructions import cnot, h, measure, rx, x from autoqasm.simulator import McmSimulator +from braket.devices import LocalSimulator +from braket.tasks.local_quantum_task import LocalQuantumTask def _test_on_local_sim(program: aq.Program, inputs=None) -> None: diff --git a/test/unit_tests/autoqasm/test_devices.py b/test/unit_tests/autoqasm/test_devices.py index 674110c..d50e25d 100644 --- a/test/unit_tests/autoqasm/test_devices.py +++ b/test/unit_tests/autoqasm/test_devices.py @@ -11,23 +11,22 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""AutoQASM tests exercising device-specific targeting functionality. -""" +"""AutoQASM tests exercising device-specific targeting functionality.""" import json from unittest.mock import Mock, patch import pytest + +import autoqasm as aq +from autoqasm import errors +from autoqasm.instructions import cnot, cphaseshift00, h, rx, x from braket.aws import AwsDevice from braket.device_schema import DeviceActionType from braket.device_schema.simulators import GateModelSimulatorDeviceCapabilities from braket.devices import Devices from braket.parametric import FreeParameter -import autoqasm as aq -from autoqasm import errors -from autoqasm.instructions import cnot, cphaseshift00, h, rx, x - RIGETTI_REGION = "us-west-1" MOCK_DEFAULT_S3_DESTINATION_FOLDER = ( diff --git a/test/unit_tests/autoqasm/test_gate_decorator.py b/test/unit_tests/autoqasm/test_gate_decorator.py index b6b934f..1df310f 100644 --- a/test/unit_tests/autoqasm/test_gate_decorator.py +++ b/test/unit_tests/autoqasm/test_gate_decorator.py @@ -11,8 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""AutoQASM tests exercising the @aq.gate decorator and related functionality. -""" +"""AutoQASM tests exercising the @aq.gate decorator and related functionality.""" import numpy as np import pytest diff --git a/test/unit_tests/autoqasm/test_hybrid_job.py b/test/unit_tests/autoqasm/test_hybrid_job.py index 71d0eeb..e1956e2 100644 --- a/test/unit_tests/autoqasm/test_hybrid_job.py +++ b/test/unit_tests/autoqasm/test_hybrid_job.py @@ -21,12 +21,12 @@ from unittest.mock import MagicMock, mock_open, patch import pytest + +import autoqasm as aq from braket.aws import AwsQuantumJob from braket.devices import Devices from braket.jobs.local import LocalQuantumJob -import autoqasm as aq - @pytest.fixture def aws_session(): diff --git a/test/unit_tests/autoqasm/test_operators.py b/test/unit_tests/autoqasm/test_operators.py index fc53cad..1a78a80 100644 --- a/test/unit_tests/autoqasm/test_operators.py +++ b/test/unit_tests/autoqasm/test_operators.py @@ -850,9 +850,7 @@ def test_control_flow(): expected = """OPENQASM 3.0; qubit[1] __qubits__; -{} __qubits__[0];""".format( - "h" if value else "x" - ) +{} __qubits__[0];""".format("h" if value else "x") assert test_control_flow.build().to_ir() == expected diff --git a/test/unit_tests/autoqasm/test_parameters.py b/test/unit_tests/autoqasm/test_parameters.py index dd7412b..9b214fd 100644 --- a/test/unit_tests/autoqasm/test_parameters.py +++ b/test/unit_tests/autoqasm/test_parameters.py @@ -15,14 +15,14 @@ import numpy as np import pytest -from braket.circuits import FreeParameter -from braket.devices import LocalSimulator -from braket.tasks.local_quantum_task import LocalQuantumTask import autoqasm as aq from autoqasm import pulse from autoqasm.instructions import cnot, cphaseshift, gpi, h, measure, ms, rx, rz, x from autoqasm.simulator import McmSimulator +from braket.circuits import FreeParameter +from braket.devices import LocalSimulator +from braket.tasks.local_quantum_task import LocalQuantumTask def _test_parametric_on_local_sim(program: aq.Program, inputs: dict[str, float]) -> np.ndarray: diff --git a/test/unit_tests/autoqasm/test_program.py b/test/unit_tests/autoqasm/test_program.py index a0d96db..c8c576a 100644 --- a/test/unit_tests/autoqasm/test_program.py +++ b/test/unit_tests/autoqasm/test_program.py @@ -19,10 +19,10 @@ import oqpy.base import pytest -from braket.circuits.serialization import IRType import autoqasm as aq from autoqasm.instructions import cnot, measure, rx +from braket.circuits.serialization import IRType def test_program_conversion_context() -> None: diff --git a/test/unit_tests/autoqasm/test_pulse.py b/test/unit_tests/autoqasm/test_pulse.py index 882ea3b..f18b292 100644 --- a/test/unit_tests/autoqasm/test_pulse.py +++ b/test/unit_tests/autoqasm/test_pulse.py @@ -16,8 +16,6 @@ import textwrap import pytest -from braket.parametric import FreeParameter -from braket.pulse import ArbitraryWaveform, Frame, Port import autoqasm as aq from autoqasm.instructions import rx @@ -32,6 +30,8 @@ shift_frequency, shift_phase, ) +from braket.parametric import FreeParameter +from braket.pulse import ArbitraryWaveform, Frame, Port PORT = Port(port_id="device_port_x0", dt=1e-9, properties={}) FRAME1 = Frame(frame_id="predefined_frame_1", frequency=2e9, port=PORT, phase=0, is_predefined=True) diff --git a/test/unit_tests/autoqasm/test_return.py b/test/unit_tests/autoqasm/test_return.py index 6527ec9..f0f7b05 100644 --- a/test/unit_tests/autoqasm/test_return.py +++ b/test/unit_tests/autoqasm/test_return.py @@ -14,11 +14,11 @@ """AutoQASM tests exercising the return statement for `aq.main`.""" import pytest -from braket.pulse import Frame, Port import autoqasm as aq from autoqasm.instructions import measure from autoqasm.pulse import capture_v0 +from braket.pulse import Frame, Port def test_float_lit(): diff --git a/test/unit_tests/autoqasm/test_serialization_config.py b/test/unit_tests/autoqasm/test_serialization_config.py index d3c9d18..428cde1 100644 --- a/test/unit_tests/autoqasm/test_serialization_config.py +++ b/test/unit_tests/autoqasm/test_serialization_config.py @@ -15,11 +15,10 @@ import textwrap -from braket.pulse import Frame, GaussianWaveform, Port - import autoqasm as aq from autoqasm.program import OpenQASMSerializationProperties from autoqasm.pulse import barrier, play +from braket.pulse import Frame, GaussianWaveform, Port PORT = Port(port_id="device_port_x0", dt=1e-9, properties={}) FRAME = Frame(frame_id="predefined_frame_1", frequency=2e9, port=PORT, phase=0, is_predefined=True) diff --git a/test/unit_tests/autoqasm/test_simulator.py b/test/unit_tests/autoqasm/test_simulator.py index 7322171..f7a3252 100644 --- a/test/unit_tests/autoqasm/test_simulator.py +++ b/test/unit_tests/autoqasm/test_simulator.py @@ -12,13 +12,13 @@ # language governing permissions and limitations under the License. import pytest -from braket.ir.openqasm import Program as OpenQASMProgram -from braket.tasks import GateModelQuantumTaskResult from autoqasm.simulator import McmSimulator from autoqasm.simulator.native_interpreter import NativeInterpreter from autoqasm.simulator.program_context import McmProgramContext from autoqasm.simulator.simulation import Simulation +from braket.ir.openqasm import Program as OpenQASMProgram +from braket.tasks import GateModelQuantumTaskResult INPUTS_QASM = "test/resources/inputs.qasm" diff --git a/tox.ini b/tox.ini index 7aaa3d4..21dfb51 100644 --- a/tox.ini +++ b/tox.ini @@ -41,71 +41,36 @@ extras = test [testenv:linters] basepython = python3 -skip_install = true +# Remove this to check what versions are installed for the env. This stops running pip freeze. +list_dependencies_command = echo deps = - {[testenv:isort]deps} - {[testenv:black]deps} - {[testenv:flake8]deps} + {[testenv:ruff-format]deps} + {[testenv:ruff-check]deps} commands = - # isort MUST come before black as it will revert any changes made by black - {[testenv:isort]commands} - {[testenv:black]commands} - {[testenv:flake8]commands} + {[testenv:ruff-format]commands} + {[testenv:ruff-check]commands} # Read only linter env [testenv:linters_check] basepython = python3 -skip_install = true -deps = - {[testenv:isort_check]deps} - {[testenv:black_check]deps} - {[testenv:flake8]deps} -commands = - {[testenv:isort_check]commands} - {[testenv:black_check]commands} - {[testenv:flake8]commands} - -[testenv:flake8] -basepython = python3 -skip_install = true -deps = - flake8 - git+https://github.com/amazon-braket/amazon-braket-build-tools.git -commands = - flake8 --extend-exclude src {posargs} - flake8 --enable-extensions=BCS src {posargs} - -[testenv:isort] -basepython = python3 -skip_install = true -deps = - isort +deps = ruff +extras = linters commands = - isort . {posargs} + {[testenv:ruff-check]commands} -[testenv:isort_check] +[testenv:ruff-check] basepython = python3 -skip_install = true -deps = - isort +extras = linters +deps = ruff commands = - isort . -c {posargs} + ruff check src {posargs} -[testenv:black] +[testenv:ruff-format] basepython = python3 -skip_install = true -deps = - black -commands = - black ./ {posargs} - -[testenv:black_check] -basepython = python3 -skip_install = true -deps = - black +extras = linters +deps = ruff commands = - black --check ./ {posargs} + ruff format . {posargs} [testenv:docs] basepython = python3