diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cf59ca9c..157c5e0f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: check-useless-excludes - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v6.0.0 hooks: - id: check-added-large-files - id: check-ast @@ -40,7 +40,7 @@ repos: # Changes tabs to spaces - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.5 + rev: v1.5.6 hooks: - id: remove-tabs @@ -52,14 +52,14 @@ repos: additional_dependencies: [toml] - repo: https://github.com/PyCQA/doc8/ - rev: v1.1.1 + rev: v2.0.0 hooks: - id: doc8 require_serial: false additional_dependencies: [tomli] - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.4.1 hooks: - id: codespell require_serial: false @@ -67,38 +67,38 @@ repos: args: [-S, '.git,third_party', -I, .codespell.allow] - repo: https://github.com/adrienverge/yamllint.git - rev: v1.35.1 + rev: v1.38.0 hooks: - id: yamllint require_serial: false - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + rev: v3.21.2 hooks: - id: pyupgrade args: [--py37-plus, --keep-mock] - repo: https://github.com/PyCQA/isort - rev: 5.13.2 + rev: 7.0.0 hooks: - id: isort name: isort (python) - - repo: https://github.com/psf/black - rev: 24.3.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.1.0 hooks: - id: black language_version: python3 - repo: https://github.com/asottile/blacken-docs - rev: 1.16.0 + rev: 1.20.0 hooks: - id: blacken-docs args: [-S, -l, '120'] additional_dependencies: [black==22.10.0] - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 + rev: 7.3.0 hooks: - id: flake8 name: flake8-strict @@ -120,7 +120,7 @@ repos: additional_dependencies: [pybind11>=2.6, numpy, requests, matplotlib, networkx] - repo: https://github.com/mgedmin/check-manifest - rev: '0.49' + rev: '0.51' hooks: - id: check-manifest additional_dependencies: ['setuptools-scm', 'pybind11>=2.6'] diff --git a/examples/unitary_simulator.py b/examples/unitary_simulator.py index d91b0ede..bf859a64 100644 --- a/examples/unitary_simulator.py +++ b/examples/unitary_simulator.py @@ -15,7 +15,6 @@ """Example of using the UnitarySimulator.""" - import numpy as np from projectq.backends import UnitarySimulator diff --git a/projectq/backends/__init__.py b/projectq/backends/__init__.py index e531ed9f..d934a1bf 100755 --- a/projectq/backends/__init__.py +++ b/projectq/backends/__init__.py @@ -28,6 +28,7 @@ * an interface to the Azure Quantum service devices (and simulators) * an interface to the IonQ trapped ionq hardware (and simulator). """ + from ._aqt import AQTBackend from ._awsbraket import AWSBraketBackend from ._azure import AzureQuantumBackend diff --git a/projectq/backends/_awsbraket/_awsbraket_boto3_client_test.py b/projectq/backends/_awsbraket/_awsbraket_boto3_client_test.py index 2b6e33e0..d75c7625 100644 --- a/projectq/backends/_awsbraket/_awsbraket_boto3_client_test.py +++ b/projectq/backends/_awsbraket/_awsbraket_boto3_client_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" Test for projectq.backends._awsbraket._awsbraket_boto3_client.py """ +"""Test for projectq.backends._awsbraket._awsbraket_boto3_client.py""" import pytest @@ -110,21 +110,15 @@ def test_retrieve(mocker, var_status, var_result, retrieve_setup): _awsbraket_boto3_client.retrieve(credentials=creds, task_arn=arntask, num_retries=2) print(exinfo.value) if var_status == 'failed': - assert ( - str(exinfo.value) - == "Error while running the code: FAILED. \ + assert str(exinfo.value) == "Error while running the code: FAILED. \ The failure reason was: This is a failure reason." - ) if var_status == 'cancelling': assert str(exinfo.value) == "The job received a CANCEL operation: CANCELLING." if var_status == 'other': - assert ( - str(exinfo.value) - == "Timeout. The Arn of your submitted job \ + assert str(exinfo.value) == "Timeout. The Arn of your submitted job \ is arn:aws:braket:us-east-1:id:taskuuid \ and the status of the job is OTHER." - ) # ============================================================================== @@ -155,7 +149,7 @@ def test_retrieve_devicetypes(mocker, retrieve_devicetypes_setup): @has_boto3 def test_send_too_many_qubits(mocker, send_too_many_setup): - (creds, s3_folder, search_value, device_value, info_too_much) = send_too_many_setup + creds, s3_folder, search_value, device_value, info_too_much = send_too_many_setup mock_boto3_client = mocker.MagicMock(spec=['search_devices', 'get_device']) mock_boto3_client.search_devices.return_value = search_value @@ -222,21 +216,15 @@ def test_send_real_device_online_verbose(mocker, var_status, var_result, real_de ) print(exinfo.value) if var_status == 'failed': - assert ( - str(exinfo.value) - == "Error while running the code: FAILED. The failure \ + assert str(exinfo.value) == "Error while running the code: FAILED. The failure \ reason was: This is a failure reason." - ) if var_status == 'cancelling': assert str(exinfo.value) == "The job received a CANCEL operation: CANCELLING." if var_status == 'other': - assert ( - str(exinfo.value) - == "Timeout. The Arn of your submitted job \ + assert str(exinfo.value) == "Timeout. The Arn of your submitted job \ is arn:aws:braket:us-east-1:id:taskuuid \ and the status of the job is OTHER." - ) # ============================================================================== @@ -282,7 +270,7 @@ def test_send_that_errors_are_caught(mocker, var_error, send_that_error_setup): @has_boto3 -@pytest.mark.parametrize("var_error", [('ResourceNotFoundException')]) +@pytest.mark.parametrize("var_error", ['ResourceNotFoundException']) def test_retrieve_error_arn_not_exist(mocker, var_error, arntask, creds): mock_boto3_client = mocker.MagicMock(spec=['get_quantum_task']) mock_boto3_client.get_quantum_task.side_effect = botocore.exceptions.ClientError( diff --git a/projectq/backends/_awsbraket/_awsbraket_test.py b/projectq/backends/_awsbraket/_awsbraket_test.py index 1a5288c8..76dfa493 100644 --- a/projectq/backends/_awsbraket/_awsbraket_test.py +++ b/projectq/backends/_awsbraket/_awsbraket_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" Test for projectq.backends._awsbraket._awsbraket.py""" +"""Test for projectq.backends._awsbraket._awsbraket.py""" import copy import math @@ -477,7 +477,7 @@ def test_awsbraket_sent_error_2(): @has_boto3 def test_awsbraket_retrieve(mocker, retrieve_setup): - (arntask, creds, completed_value, device_value, results_dict) = retrieve_setup + arntask, creds, completed_value, device_value, results_dict = retrieve_setup mock_boto3_client = mocker.MagicMock(spec=['get_quantum_task', 'get_device', 'get_object']) mock_boto3_client.get_quantum_task.return_value = completed_value diff --git a/projectq/backends/_circuits/_drawer.py b/projectq/backends/_circuits/_drawer.py index 071ad2ce..3288678d 100755 --- a/projectq/backends/_circuits/_drawer.py +++ b/projectq/backends/_circuits/_drawer.py @@ -14,7 +14,6 @@ """Contain a compiler engine which generates TikZ Latex code describing the circuit.""" - from projectq.cengines import BasicEngine, LastEngineException from projectq.meta import get_control_count from projectq.ops import Allocate, Deallocate, FlushGate, Measure diff --git a/projectq/backends/_circuits/_drawer_matplotlib.py b/projectq/backends/_circuits/_drawer_matplotlib.py index 7c6b5855..95353d5d 100644 --- a/projectq/backends/_circuits/_drawer_matplotlib.py +++ b/projectq/backends/_circuits/_drawer_matplotlib.py @@ -30,7 +30,7 @@ def _format_gate_str(cmd): param_str = '' gate_name = str(cmd.gate) if '(' in gate_name: - (gate_name, param_str) = re.search(r'(.+)\((.*)\)', gate_name).groups() + gate_name, param_str = re.search(r'(.+)\((.*)\)', gate_name).groups() params = re.findall(r'([^,]+)', param_str) params_str_list = [] for param in params: diff --git a/projectq/backends/_circuits/_plot.py b/projectq/backends/_circuits/_plot.py index b450309f..a09acd5a 100644 --- a/projectq/backends/_circuits/_plot.py +++ b/projectq/backends/_circuits/_plot.py @@ -308,7 +308,7 @@ def draw_gates( # pylint: disable=too-many-arguments for qubit_line in qubit_lines.values(): for idx, data in enumerate(qubit_line): if data is not None: - (gate_str, targets, controls) = data + gate_str, targets, controls = data targets_order = [drawing_order[tgt] for tgt in targets] draw_gate( axes, diff --git a/projectq/backends/_circuits/_plot_test.py b/projectq/backends/_circuits/_plot_test.py index 3e81d23d..614f1c75 100644 --- a/projectq/backends/_circuits/_plot_test.py +++ b/projectq/backends/_circuits/_plot_test.py @@ -12,13 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. """ - Tests for projectq.backends._circuits._plot.py. +Tests for projectq.backends._circuits._plot.py. - To generate the baseline images, - run the tests with '--mpl-generate-path=baseline' +To generate the baseline images, +run the tests with '--mpl-generate-path=baseline' - Then run the tests simply with '--mpl' +Then run the tests simply with '--mpl' """ + from copy import deepcopy import pytest diff --git a/projectq/backends/_ibm/_ibm_http_client.py b/projectq/backends/_ibm/_ibm_http_client.py index 27602984..cb64b6a0 100755 --- a/projectq/backends/_ibm/_ibm_http_client.py +++ b/projectq/backends/_ibm/_ibm_http_client.py @@ -14,7 +14,6 @@ """Back-end to run quantum program on IBM QE cloud platform.""" - # helpers to run the jsonified gate sequence on ibm quantum experience server # api documentation does not exist and has to be deduced from the qiskit code # source at: https://github.com/Qiskit/qiskit-ibmq-provider diff --git a/projectq/backends/_ibm/_ibm_test.py b/projectq/backends/_ibm/_ibm_test.py index dc9e2c2c..e7cccdf5 100755 --- a/projectq/backends/_ibm/_ibm_test.py +++ b/projectq/backends/_ibm/_ibm_test.py @@ -370,12 +370,8 @@ def mock_send(*args, **kwargs): assert prob_dict['00'] == pytest.approx(0.512) assert prob_dict['11'] == pytest.approx(0.488) result = "\nu2(0,pi/2) q[1];\ncx q[1], q[2];\ncx q[1], q[3];" - if sys.version_info.major == 3: - result += "\nu3(6.28318530718, 0, 0) q[1];\nu1(11.780972450962) q[1];" - result += "\nu3(6.28318530718, 0, 0) q[1];\nu1(10.995574287564) q[1];" - else: - result += "\nu3(6.28318530718, 0, 0) q[1];\nu1(11.780972451) q[1];" - result += "\nu3(6.28318530718, 0, 0) q[1];\nu1(10.9955742876) q[1];" + result += "\nu3(6.28318530718, 0, 0) q[1];\nu1(11.780972450962) q[1];" + result += "\nu3(6.28318530718, 0, 0) q[1];\nu1(10.995574287564) q[1];" result += "\nbarrier q[1], q[2], q[3];" result += "\nu3(0.2, -pi/2, pi/2) q[1];\nmeasure q[1] -> c[1];" result += "\nmeasure q[2] -> c[2];\nmeasure q[3] -> c[3];" diff --git a/projectq/cengines/_basicmapper.py b/projectq/cengines/_basicmapper.py index 45f477d3..61e05f09 100644 --- a/projectq/cengines/_basicmapper.py +++ b/projectq/cengines/_basicmapper.py @@ -17,6 +17,7 @@ There is only one engine currently allowed to be derived from BasicMapperEngine. This allows the simulator to automatically translate logical qubit ids to mapped ids. """ + from copy import deepcopy from projectq.meta import LogicalQubitIDTag, drop_engine_after, insert_engine diff --git a/projectq/cengines/_linearmapper_test.py b/projectq/cengines/_linearmapper_test.py index 5a5657ad..d0a5364d 100644 --- a/projectq/cengines/_linearmapper_test.py +++ b/projectq/cengines/_linearmapper_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Tests for projectq.cengines._linearmapper.py.""" + from copy import deepcopy import pytest diff --git a/projectq/cengines/_main_test.py b/projectq/cengines/_main_test.py index 665e8815..264d3264 100755 --- a/projectq/cengines/_main_test.py +++ b/projectq/cengines/_main_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Tests for projectq.cengines._main.py.""" + import sys import weakref diff --git a/projectq/cengines/_swapandcnotflipper.py b/projectq/cengines/_swapandcnotflipper.py index 997274a0..108ee08c 100755 --- a/projectq/cengines/_swapandcnotflipper.py +++ b/projectq/cengines/_swapandcnotflipper.py @@ -16,6 +16,7 @@ It also translates Swap gates to CNOTs if necessary. """ + from copy import deepcopy from projectq.meta import get_control_count diff --git a/projectq/cengines/_tagremover.py b/projectq/cengines/_tagremover.py index a939366e..c4cc88b3 100755 --- a/projectq/cengines/_tagremover.py +++ b/projectq/cengines/_tagremover.py @@ -17,6 +17,7 @@ A TagRemover engine removes temporary command tags (such as Compute/Uncompute), thus enabling optimization across meta statements (loops after unrolling, compute/uncompute, ...) """ + from projectq.meta import ComputeTag, UncomputeTag from ._basics import BasicEngine diff --git a/projectq/cengines/_twodmapper.py b/projectq/cengines/_twodmapper.py index 7a54a029..bdceba73 100644 --- a/projectq/cengines/_twodmapper.py +++ b/projectq/cengines/_twodmapper.py @@ -19,6 +19,7 @@ Output: Quantum circuit in which qubits are placed in 2-D square grid in which only nearest neighbour qubits can perform a 2 qubit gate. The mapper uses Swap gates in order to move qubits next to each other. """ + import itertools import math import random diff --git a/projectq/libs/revkit/_control_function.py b/projectq/libs/revkit/_control_function.py index 40a07fe9..3b0ccd5a 100644 --- a/projectq/libs/revkit/_control_function.py +++ b/projectq/libs/revkit/_control_function.py @@ -14,7 +14,6 @@ """RevKit support for control function oracles.""" - from projectq.ops import BasicGate from ._utils import _exec diff --git a/projectq/meta/_control_test.py b/projectq/meta/_control_test.py index 73810b95..b8441b1a 100755 --- a/projectq/meta/_control_test.py +++ b/projectq/meta/_control_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Tests for projectq.meta._control.py""" + import pytest from projectq import MainEngine diff --git a/projectq/ops/_command_test.py b/projectq/ops/_command_test.py index 19db3644..5dfe7474 100755 --- a/projectq/ops/_command_test.py +++ b/projectq/ops/_command_test.py @@ -287,12 +287,8 @@ def test_command_str(main_engine): cmd.tags = ["TestTag"] cmd.add_control_qubits(ctrl_qubit) cmd2 = _command.Command(main_engine, Rx(0.5 * math.pi), (qubit,)) - if sys.version_info.major == 3: - assert cmd.to_string(symbols=False) == "CRx(1.570796326795) | ( Qureg[1], Qureg[0] )" - assert str(cmd2) == "Rx(1.570796326795) | Qureg[0]" - else: - assert cmd.to_string(symbols=False) == "CRx(1.5707963268) | ( Qureg[1], Qureg[0] )" - assert str(cmd2) == "Rx(1.5707963268) | Qureg[0]" + assert cmd.to_string(symbols=False) == "CRx(1.570796326795) | ( Qureg[1], Qureg[0] )" + assert str(cmd2) == "Rx(1.570796326795) | Qureg[0]" def test_command_to_string(main_engine): @@ -305,9 +301,5 @@ def test_command_to_string(main_engine): assert cmd.to_string(symbols=True) == "CRx(0.5π) | ( Qureg[1], Qureg[0] )" assert cmd2.to_string(symbols=True) == "Rx(0.5π) | Qureg[0]" - if sys.version_info.major == 3: - assert cmd.to_string(symbols=False) == "CRx(1.570796326795) | ( Qureg[1], Qureg[0] )" - assert cmd2.to_string(symbols=False) == "Rx(1.570796326795) | Qureg[0]" - else: - assert cmd.to_string(symbols=False) == "CRx(1.5707963268) | ( Qureg[1], Qureg[0] )" - assert cmd2.to_string(symbols=False) == "Rx(1.5707963268) | Qureg[0]" + assert cmd.to_string(symbols=False) == "CRx(1.570796326795) | ( Qureg[1], Qureg[0] )" + assert cmd2.to_string(symbols=False) == "Rx(1.570796326795) | Qureg[0]" diff --git a/projectq/ops/_qubit_operator.py b/projectq/ops/_qubit_operator.py index 80c901dd..57f88691 100644 --- a/projectq/ops/_qubit_operator.py +++ b/projectq/ops/_qubit_operator.py @@ -383,14 +383,14 @@ def __imul__(self, multiplier): # pylint: disable=too-many-locals,too-many-bran n_operators_left = len(left_term) n_operators_right = len(right_term) while left_operator_index < n_operators_left and right_operator_index < n_operators_right: - (left_qubit, left_loc_op) = left_term[left_operator_index] - (right_qubit, right_loc_op) = right_term[right_operator_index] + left_qubit, left_loc_op = left_term[left_operator_index] + right_qubit, right_loc_op = right_term[right_operator_index] # Multiply local operators acting on the same qubit if left_qubit == right_qubit: left_operator_index += 1 right_operator_index += 1 - (scalar, loc_op) = _PAULI_OPERATOR_PRODUCTS[(left_loc_op, right_loc_op)] + scalar, loc_op = _PAULI_OPERATOR_PRODUCTS[(left_loc_op, right_loc_op)] # Add new term. if loc_op != 'I': diff --git a/projectq/ops/_qubit_operator_test.py b/projectq/ops/_qubit_operator_test.py index 3b5e3050..9bfed645 100644 --- a/projectq/ops/_qubit_operator_test.py +++ b/projectq/ops/_qubit_operator_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Tests for _qubit_operator.py.""" + import cmath import copy import math diff --git a/projectq/ops/_uniformly_controlled_rotation_test.py b/projectq/ops/_uniformly_controlled_rotation_test.py index 49bef25e..9cb6c630 100644 --- a/projectq/ops/_uniformly_controlled_rotation_test.py +++ b/projectq/ops/_uniformly_controlled_rotation_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Tests for projectq.ops._uniformly_controlled_rotation.""" + import math import pytest diff --git a/projectq/setups/decompositions/time_evolution.py b/projectq/setups/decompositions/time_evolution.py index 9e029391..3b153c25 100644 --- a/projectq/setups/decompositions/time_evolution.py +++ b/projectq/setups/decompositions/time_evolution.py @@ -18,6 +18,7 @@ if the hamiltonian has only one term or if all the terms commute with each other in which case one can implement each term individually. """ + import math from projectq.cengines import DecompositionRule diff --git a/projectq/setups/decompositions/time_evolution_test.py b/projectq/setups/decompositions/time_evolution_test.py index 8d0197a5..afeb7157 100644 --- a/projectq/setups/decompositions/time_evolution_test.py +++ b/projectq/setups/decompositions/time_evolution_test.py @@ -13,6 +13,7 @@ # limitations under the License. "Tests for projectq.setups.decompositions.time_evolution." + import copy import numpy diff --git a/projectq/setups/grid.py b/projectq/setups/grid.py index 6d58e792..a18f8c1f 100644 --- a/projectq/setups/grid.py +++ b/projectq/setups/grid.py @@ -20,7 +20,6 @@ to each other. This setup allows to choose the final gate set (with some limitations). """ - from projectq.cengines import GridMapper from projectq.ops import CNOT, Swap diff --git a/projectq/setups/ionq.py b/projectq/setups/ionq.py index 3c451048..42dacb4c 100644 --- a/projectq/setups/ionq.py +++ b/projectq/setups/ionq.py @@ -19,6 +19,7 @@ ->The 11 qubit device ->The 29 qubits simulator """ + from projectq.backends._exceptions import DeviceOfflineError from projectq.backends._ionq._ionq_http_client import IonQ from projectq.backends._ionq._ionq_mapper import BoundedQubitMapper diff --git a/setup.py b/setup.py index 24a647bd..4e20d795 100755 --- a/setup.py +++ b/setup.py @@ -141,14 +141,14 @@ def parse_toml(filename): if line.startswith('name'): result['project']['name'] = line.split('=')[1].strip().strip("'") elif line.startswith('dependencies'): - (name, pkgs, shift) = _parse_list(project_data[idx:]) + name, pkgs, shift = _parse_list(project_data[idx:]) result['project'][name] = pkgs idx += shift idx = 0 N = len(optional_dependencies) while idx < N: - (opt_name, opt_pkgs, shift) = _parse_list(optional_dependencies[idx:]) + opt_name, opt_pkgs, shift = _parse_list(optional_dependencies[idx:]) result['project']['optional-dependencies'][opt_name] = opt_pkgs idx += shift