Skip to content
Open
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
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -52,53 +52,53 @@ 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
files: .*\.(py|txt|cmake|md|rst|sh|ps1|hpp|tpp|cpp|cc)$
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
Expand All @@ -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']
1 change: 0 additions & 1 deletion examples/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

"""Example of using the UnitarySimulator."""


import numpy as np

from projectq.backends import UnitarySimulator
Expand Down
1 change: 1 addition & 0 deletions projectq/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 7 additions & 19 deletions projectq/backends/_awsbraket/_awsbraket_boto3_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."
)


# ==============================================================================
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
)


# ==============================================================================
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions projectq/backends/_awsbraket/_awsbraket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion projectq/backends/_circuits/_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion projectq/backends/_circuits/_drawer_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion projectq/backends/_circuits/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions projectq/backends/_circuits/_plot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion projectq/backends/_ibm/_ibm_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions projectq/backends/_ibm/_ibm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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];"
Expand Down
1 change: 1 addition & 0 deletions projectq/cengines/_basicmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions projectq/cengines/_linearmapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions projectq/cengines/_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions projectq/cengines/_swapandcnotflipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
It also translates Swap gates to CNOTs if necessary.
"""

from copy import deepcopy

from projectq.meta import get_control_count
Expand Down
1 change: 1 addition & 0 deletions projectq/cengines/_tagremover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions projectq/cengines/_twodmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion projectq/libs/revkit/_control_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"""RevKit support for control function oracles."""


from projectq.ops import BasicGate

from ._utils import _exec
Expand Down
1 change: 1 addition & 0 deletions projectq/meta/_control_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions projectq/ops/_command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]"
6 changes: 3 additions & 3 deletions projectq/ops/_qubit_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
1 change: 1 addition & 0 deletions projectq/ops/_qubit_operator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions projectq/ops/_uniformly_controlled_rotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions projectq/setups/decompositions/time_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading