Skip to content
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
4 changes: 2 additions & 2 deletions quick/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def _gate_mapping(
self,
gate: GATES,
target_indices: int | Sequence[int],
control_indices: int | Sequence[int] = [],
control_indices: int | Sequence[int] | None = None,
angles: Sequence[float] = (0, 0, 0)
) -> None:
""" Apply a gate to the circuit.
Expand All @@ -551,7 +551,7 @@ def _gate_mapping(
The gate to apply to the circuit.
`target_indices` : int | Sequence[int]
The index of the target qubit(s).
`control_indices` : int | Sequence[int], optional, default=[]
`control_indices` : int | Sequence[int], optional, default=None
The index of the control qubit(s).
`angles` : Sequence[float], optional, default=(0, 0, 0)
The rotation angles in radians.
Expand Down
8 changes: 6 additions & 2 deletions quick/circuit/cirqcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,16 @@ def _gate_mapping(
self,
gate: GATES,
target_indices: int | Sequence[int],
control_indices: int | Sequence[int] = [],
control_indices: int | Sequence[int] | None = None,
angles: Sequence[float] = (0, 0, 0)
) -> None:

targets = [target_indices] if isinstance(target_indices, int) else list(target_indices)
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

if control_indices is None:
controls: list[int] = []
else:
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

# Given Cirq uses MSB convention, we will explicitly
# convert the qubit indices to LSB convention
Expand Down
8 changes: 6 additions & 2 deletions quick/circuit/pennylanecircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,16 @@ def _gate_mapping(
self,
gate: GATES,
target_indices: int | Sequence[int],
control_indices: int | Sequence[int] = [],
control_indices: int | Sequence[int] | None = None,
angles: Sequence[float] = (0, 0, 0)
) -> None:

targets = [target_indices] if isinstance(target_indices, int) else list(target_indices)
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

if control_indices is None:
controls: list[int] = []
else:
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

# Given Pennylane uses MSB convention, we will explicitly
# convert the qubit indices to LSB convention
Expand Down
18 changes: 11 additions & 7 deletions quick/circuit/qiskitcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,27 @@ def _gate_mapping(
self,
gate: GATES,
target_indices: int | Sequence[int],
control_indices: int | Sequence[int] = [],
control_indices: int | Sequence[int] | None = None,
angles: Sequence[float] = (0, 0, 0)
) -> None:

target_indices = [target_indices] if isinstance(target_indices, int) else target_indices
control_indices = [control_indices] if isinstance(control_indices, int) else control_indices
targets = [target_indices] if isinstance(target_indices, int) else list(target_indices)

if control_indices is None:
controls: list[int] = []
else:
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

# Lazily extract the value of the gate from the mapping to avoid
# creating all the gates at once, and to maintain the abstraction
gate_operation = self.gate_mapping[gate](angles)

if control_indices:
for target_index in target_indices:
self.circuit.append(gate_operation.control(len(control_indices)), [*control_indices[:], target_index])
if controls:
for target_index in targets:
self.circuit.append(gate_operation.control(len(controls)), [*controls[:], target_index])
return

for target_index in target_indices:
for target_index in targets:
self.circuit.append(gate_operation, [target_index])

def GlobalPhase(
Expand Down
8 changes: 6 additions & 2 deletions quick/circuit/quimbcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ def _gate_mapping(
self,
gate: GATES,
target_indices: int | Sequence[int],
control_indices: int | Sequence[int] = [],
control_indices: int | Sequence[int] | None = None,
angles: Sequence[float] = (0, 0, 0)
) -> None:

targets = [target_indices] if isinstance(target_indices, int) else list(target_indices)
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

if control_indices is None:
controls: list[int] = []
else:
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

# Given Quimb uses MSB convention, we will explicitly
# convert the qubit indices to LSB convention
Expand Down
8 changes: 6 additions & 2 deletions quick/circuit/tketcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ def _gate_mapping(
self,
gate: GATES,
target_indices: int | Sequence[int],
control_indices: int | Sequence[int] = [],
control_indices: int | Sequence[int] | None = None,
angles: Sequence[float] = (0, 0, 0)
) -> None:

targets = [target_indices] if isinstance(target_indices, int) else list(target_indices)
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

if control_indices is None:
controls: list[int] = []
else:
controls = [control_indices] if isinstance(control_indices, int) else list(control_indices)

# Given TKET uses MSB convention, we will explicitly
# convert the qubit indices to LSB convention
Expand Down
1 change: 0 additions & 1 deletion tests/circuit/test_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import pytest
from quick.circuit import Ansatz, Circuit
from typing import Type

from tests.circuit import CIRCUIT_FRAMEWORKS

Expand Down
7 changes: 3 additions & 4 deletions tests/circuit/test_circuit_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import numpy as np
from numpy.testing import assert_almost_equal
import pytest
from typing import Type

from quick.circuit import Circuit
from quick.random import generate_random_state, generate_random_unitary
Expand Down Expand Up @@ -1313,7 +1312,7 @@ def test_eq(
@pytest.mark.parametrize("circuit_framework", CIRCUIT_FRAMEWORKS)
def test_eq_fail(
self,
circuit_framework: Type[Circuit]
circuit_framework: type[Circuit]
) -> None:
""" Test the `__eq__` dunder method failure.

Expand Down Expand Up @@ -1360,7 +1359,7 @@ def test_eq_fail(
@pytest.mark.parametrize("circuit_framework", CIRCUIT_FRAMEWORKS)
def test_eq_invalid_type(
self,
circuit_framework: Type[Circuit]
circuit_framework: type[Circuit]
) -> None:
""" Test the `__eq__` dunder method failure with invalid type.

Expand All @@ -1377,7 +1376,7 @@ def test_eq_invalid_type(
@pytest.mark.parametrize("circuit_framework", CIRCUIT_FRAMEWORKS)
def test_is_equivalent(
self,
circuit_framework: Type[Circuit]
circuit_framework: type[Circuit]
) -> None:
""" Test the `is_equivalent` method.

Expand Down
1 change: 0 additions & 1 deletion tests/circuit/test_circuit_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import numpy as np
import pytest
from typing import Type

from quick.circuit import Circuit

Expand Down
1 change: 0 additions & 1 deletion tests/circuit/test_circuit_to_controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
__all__ = ["TestControlled"]

import pytest
from typing import Type

from quick.circuit import Circuit

Expand Down
1 change: 0 additions & 1 deletion tests/circuit/test_control_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import numpy as np
import pytest
from typing import Type

from quick.circuit import Circuit
from quick.circuit.gate_matrix import RX
Expand Down
1 change: 0 additions & 1 deletion tests/circuit/test_qft_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from numpy.testing import assert_almost_equal
from numpy.typing import NDArray
import pytest
from typing import Type

from quick.circuit import Circuit, CirqCircuit, PennylaneCircuit, QiskitCircuit, TKETCircuit

Expand Down
1 change: 0 additions & 1 deletion tests/synthesis/unitarypreparation/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from numpy.testing import assert_almost_equal
import pytest
import random
from typing import Type

from quick.circuit import Circuit, QiskitCircuit
from quick.primitives import Operator
Expand Down
Loading