Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Linde committed Nov 29, 2024
1 parent 878cecb commit 823c623
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 40 deletions.
6 changes: 2 additions & 4 deletions docs_files/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sphinx.cmd.build as sphinx_build
import sphinx.ext.apidoc as sphinx_apidoc

sphinx_apiddoc_args =[
sphinx_apiddoc_args = [
"-o=docs_build",
"--templatedir=docs_files/templates",
"--force",
Expand All @@ -14,11 +14,9 @@
"qgym",
]

sphinx_build_args = ["docs_build","docs"]
sphinx_build_args = ["docs_build", "docs"]

sphinx_apidoc.main(sphinx_apiddoc_args)
sphinx_build.main(sphinx_build_args)

shutil.rmtree("docs_build")


2 changes: 1 addition & 1 deletion qgym/envs/routing/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
A valid action is an integer in the domain [0, n_connections]. The values 0 to
n_connections-1 represent an added SWAP gate. The value of n_connections indicates
that the agents wants to surpass the current gate and move to the next gate.
Illegal actions will not be executed. An action is considered illegal when the agent
want to surpass a gate that cannot be executed with the current mapping.
Expand Down
2 changes: 1 addition & 1 deletion qgym/envs/scheduling/machine_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def not_in_same_cycle(self) -> dict[str, set[str]] | dict[int, set[int]]:

@staticmethod
def _check_machine_properties_mapping(
machine_properties: Mapping[str, Any]
machine_properties: Mapping[str, Any],
) -> dict[str, Any]:
"""Check if the given machine properties ``Mapping`` is a valid descriptions of
the machine properties and returns a ``Dict`` to easily initialize a
Expand Down
2 changes: 1 addition & 1 deletion qgym/envs/scheduling/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def get_circuit(self, mode: str = "human") -> list[Gate]:

@staticmethod
def _parse_machine_properties(
machine_properties: Mapping[str, Any] | str | MachineProperties
machine_properties: Mapping[str, Any] | str | MachineProperties,
) -> MachineProperties:
"""
Parse the machine_properties given by the user and return a
Expand Down
2 changes: 1 addition & 1 deletion qgym/envs/scheduling/scheduling_rewarders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
schedule_gate_bonus: = 3,
)
After initialization, the rewarders can be given to the
After initialization, the rewarders can be given to the
:class:`~qgym.envs.Scheduling` environment.
.. note::
Expand Down
2 changes: 1 addition & 1 deletion qgym/utils/input_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def parse_visualiser(


def parse_connection_graph(
graph: nx.Graph | ArrayLike | list[int] | tuple[int, ...]
graph: nx.Graph | ArrayLike | list[int] | tuple[int, ...],
) -> nx.Graph:
"""Parse the user input (given in ``__init__``) to create a connection graph.
Expand Down
7 changes: 2 additions & 5 deletions qgym/wrappers/initial_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
from numpy.typing import NDArray
from qiskit import QuantumCircuit
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler import Layout, AnalysisPass
from qiskit.transpiler import AnalysisPass, Layout

from qgym.utils.qiskit_utils import (
get_interaction_graph,
parse_circuit,
)
from qgym.utils.qiskit_utils import get_interaction_graph, parse_circuit

if TYPE_CHECKING:
from stable_baselines3.common.base_class import BaseAlgorithm
Expand Down
3 changes: 2 additions & 1 deletion qgym/wrappers/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def compute_routing(self, circuit: QuantumCircuit | DAGCircuit) -> DAGCircuit:
raise ValueError(msg)

return insert_swaps_in_circuit(
circuit, self.env._state.swap_gates_inserted # type: ignore[attr-defined]
circuit,
self.env._state.swap_gates_inserted, # type: ignore[attr-defined]
)


Expand Down
1 change: 0 additions & 1 deletion tests/envs/initial_mapping/test_initial_mapping_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def small_env(small_graph: nx.Graph) -> InitialMapping:


class TestEnvironment:

def test_validity(self, small_env: InitialMapping) -> None:
# todo: maybe switch this to the gymnasium env checker
check_env(small_env, warn=True)
Expand Down
3 changes: 0 additions & 3 deletions tests/generators/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_abc() -> None:


class TestNullCircuitGenerator:

@pytest.fixture(name="generator")
def null_circuit_generator_fixture(self) -> NullCircuitGenerator:
return NullCircuitGenerator()
Expand Down Expand Up @@ -54,7 +53,6 @@ def test_iter(self, generator: NullCircuitGenerator) -> None:


class TestBasicCircuitGenerator:

@pytest.fixture(name="simple_generator")
def basic_circuit_generator_fixture(self) -> BasicCircuitGenerator:
generator = BasicCircuitGenerator(seed=42)
Expand Down Expand Up @@ -142,7 +140,6 @@ def test_seed(self) -> None:


class TestWorkshopCircuitGenerator:

@pytest.fixture(name="simple_generator")
def workshop_circuit_generator_fixture(self) -> WorkshopCircuitGenerator:
generator = WorkshopCircuitGenerator(seed=42)
Expand Down
2 changes: 0 additions & 2 deletions tests/generators/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_abc() -> None:


class TestNullGraphGenerator:

@pytest.fixture(name="generator")
def null_graph_generator_fixture(self) -> NullGraphGenerator:
generator = NullGraphGenerator()
Expand Down Expand Up @@ -51,7 +50,6 @@ def test_iter(self, generator: NullGraphGenerator) -> None:


class TestBasicGraphGenerator:

@pytest.fixture(name="simple_generator")
def basic_graph_generator_fixture(self) -> BasicGraphGenerator:
generator = BasicGraphGenerator()
Expand Down
2 changes: 0 additions & 2 deletions tests/generators/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_abc() -> None:


class TestNullInteractionGenerator:

@pytest.fixture(name="generator")
def null_interaction_generator_fixture(self) -> NullInteractionGenerator:
return NullInteractionGenerator()
Expand Down Expand Up @@ -53,7 +52,6 @@ def test_iter(self, generator: NullInteractionGenerator) -> None:


class TestBasicGraphGenerator:

@pytest.fixture(name="simple_generator")
def null_interaction_generator_fixture(self) -> BasicInteractionGenerator:
generator = BasicInteractionGenerator()
Expand Down
1 change: 0 additions & 1 deletion tests/generators/test_qiskit_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class TestMaxCutQAOAGenerator:

@pytest.mark.parametrize("n_nodes", range(1, 6))
def test_iterating(self, n_nodes: int) -> None:
generator = MaxCutQAOAGenerator(n_nodes, 0.5, seed=42)
Expand Down
1 change: 0 additions & 1 deletion tests/utils/test_input_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def test_negative(self) -> None:


class TestParseSeed:

def test_none(self) -> None:
rng = parse_seed(None)
assert isinstance(rng, Generator)
Expand Down
5 changes: 0 additions & 5 deletions tests/utils/test_qiskit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


class TestParseCircuit:

def test_quantum_circuit(self) -> None:
circuit = QuantumCircuit(1)
dag_circuit = parse_circuit(circuit)
Expand All @@ -34,7 +33,6 @@ def test_dag_circuit(self) -> None:


class TestGetInteractionGraph:

@pytest.mark.parametrize("circuit_size", range(6))
def test_empty_circuit(self, circuit_size: int) -> None:
circuit = QuantumCircuit(circuit_size)
Expand Down Expand Up @@ -64,7 +62,6 @@ def test_multi_qubit_value_error(self) -> None:


class TestGetInteractionCircuit:

@pytest.mark.parametrize("circuit_size", range(1, 6))
def test_empty_circuit(self, circuit_size: int) -> None:
circuit = QuantumCircuit(circuit_size)
Expand Down Expand Up @@ -111,14 +108,12 @@ def test_multi_qubit_value_error(self) -> None:
ids=["no registers", "multiple registers", "wrong name"],
)
def test_non_physical_circuit_error(self, circuit: QuantumCircuit) -> None:

expected_msg = "Interaction circuits are defined for physical circuits only"
with pytest.raises(ValueError, match=expected_msg):
get_interaction_circuit(circuit)


class TestAddSwapsToCircuit:

def test_multiple_swaps(self) -> None:
"""
Input: Expected Output:
Expand Down
2 changes: 0 additions & 2 deletions tests/wrappers/test_initial_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class TestQiskitMapperWrapper:

@pytest.fixture(name="circuit")
def circuit_fixture(self) -> QuantumCircuit:
"""Create a circuit with a cycle of cx gates."""
Expand Down Expand Up @@ -59,7 +58,6 @@ def test_sabre_layout(


class TestAgentMapperWrapper:

@pytest.fixture(name="circuit")
def circuit_fixture(self) -> QuantumCircuit:
"""Create a circuit with a line of cx gates."""
Expand Down
13 changes: 5 additions & 8 deletions tests/wrappers/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
import numpy as np
import pytest
from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.passes import SabreSwap, BasicSwap
from stable_baselines3 import PPO
from qiskit.converters import dag_to_circuit
from qgym.envs.routing import BasicRewarder, Routing
from qgym.wrappers.routing import QiskitRoutingWrapper, AgentRoutingWrapper
from qiskit.transpiler import CouplingMap, Layout
from qiskit.transpiler.passes import BasicSwap, SabreSwap
from stable_baselines3 import PPO

from qiskit.transpiler import Layout
from qgym.envs.routing import BasicRewarder, Routing
from qgym.wrappers.routing import AgentRoutingWrapper, QiskitRoutingWrapper


class TestQiskitRoutingWrapper:

@pytest.fixture(name="circuit")
def circuit_fixture(self) -> QuantumCircuit:
"""Create a circuit with a cycle of cx gates."""
Expand Down Expand Up @@ -58,7 +56,6 @@ def test_sabre_swap(


class TestAgentMapperWrapper:

@pytest.fixture(name="circuit")
def circuit_fixture(self) -> QuantumCircuit:
"""Create a circuit with a cycle of cx gates."""
Expand Down

0 comments on commit 823c623

Please sign in to comment.