Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #97

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
14 changes: 9 additions & 5 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ jobs:
pytest:

runs-on: ubuntu-latest
env:
UV_SYSTEM_PYTHON: 1
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout
Expand All @@ -17,9 +19,11 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: pip install --upgrade pip
- name: Setup UV
run: |
pip install --upgrade pip
pip install uv
- name: Install requirements
run: pip install .[test]
run: uv pip install .[test] --index-strategy unsafe-best-match --extra-index-url https://download.pytorch.org/whl/cpu
- name: Test with pytest
run: pytest tests
run: pytest tests -vv
31 changes: 22 additions & 9 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,41 @@ on: push
jobs:
mypy:
runs-on: ubuntu-latest
env:
UV_SYSTEM_PYTHON: 1
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- name: Install requirements
with:
python-version: '3.12'
- name: Setup UV
run: |
pip install --upgrade pip
pip install mypy .
pip install uv
- name: Install requirements
run: uv pip install mypy types-decorator types-redis types-tabulate .
- name: Run mypy
run: mypy qgym
run: mypy qgym --strict --install-types --non-interactive --show-error-context --show-error-codes


pylint:
lint:
runs-on: ubuntu-latest
env:
UV_SYSTEM_PYTHON: 1
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- name: Install requirements
with:
python-version: '3.12'
- name: Setup UV
run: |
pip install --upgrade pip
pip install pylint .
- name: Run pylint
run: pylint qgym
pip install --upgrade pip
pip install uv
- name: Install requirements
run: uv pip install ruff .
- name: Run ruff linter
run: ruff check
26 changes: 16 additions & 10 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ name: style
on: push

jobs:
black:
format:
runs-on: ubuntu-latest
env:
UV_SYSTEM_PYTHON: 1
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
jupyter: true

isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: isort/isort-action@master
python-version: '3.12'
- name: Setup UV
run: |
pip install --upgrade pip
pip install uv
- name: Install requirements
run: uv pip install ruff
- name: Run ruff format
run: ruff format --check
1 change: 1 addition & 0 deletions README.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supported python versions needs to be updated in the ReadMe

Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ Building qgym is a joint effort.
### Contributors and Power Users
- [Joris Henstra](https://www.linkedin.com/in/jorishenstra/)
- [Rares Oancea](https://www.linkedin.com/in/rares-adrian-oancea-8a67b0204/)

8 changes: 4 additions & 4 deletions docs_files/make_docs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Script that creates the documentation using ``sphinx``."""

import shutil

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 +16,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")


28 changes: 14 additions & 14 deletions docs_files/templates/conf.py_t
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import datetime
import importlib
import os
import sys
from typing import Optional

from numpy.typing import ArrayLike

package_name = "qgym"
sys.path.insert(
0, os.path.abspath(f"build/lib/{package_name}")
)
# -- Project information -----------------------------------------------------

import datetime
import importlib


year = datetime.date.today().year
project = package_name
Expand All @@ -34,20 +38,14 @@ napoleon_include_special_with_doc = True
# Make ArrayLike pretty. The `typehints_formatter`` must be a function with an
# annotation as first argument and a sphinx.config.Config as second argument. Returns
# the desired string or None for default behaviour.
try:
from typing import Optional

from numpy.typing import ArrayLike
def typehints_formatter(annotation, _):
if annotation == ArrayLike:
return ":py:const:`ArrayLike`"
if annotation == Optional[ArrayLike]:
return ":py:const:`Optional[ArrayLike]`"
return None

def typehints_formatter(annotation, _):
if annotation == ArrayLike:
return ":py:const:`ArrayLike`"
if annotation == Optional[ArrayLike]:
return ":py:const:`Optional[ArrayLike]`"
return None

except ImportError:
pass


# Intersphinx options for linking to external libraries.
Expand All @@ -57,6 +55,8 @@ intersphinx_mapping = {
"networkx": ("https://networkx.org/documentation/stable/", None),
"gymnasium": ("https://gymnasium.farama.org/", None),
"pygame": ("https://www.pygame.org/docs/", None),
"qiskit": ("https://docs.quantum.ibm.com/api/qiskit", None),
"stable_baselines3" : ("https://stable-baselines3.readthedocs.io/en/master/", None),
}

mathjax3_config = {
Expand Down
11 changes: 5 additions & 6 deletions notebooks/COMPLETED_mapping_qubits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import networkx as nx\n",
"import numpy as np\n",
"from IPython.display import clear_output\n",
"from networkx.generators import gnp_random_graph\n",
"import matplotlib.pyplot as plt\n",
"from stable_baselines3 import PPO\n",
"from stable_baselines3.common.env_checker import check_env\n",
"from stable_baselines3.common.utils import set_random_seed\n",
"from stable_baselines3.common.vec_env import SubprocVecEnv\n",
"from IPython.display import clear_output\n",
"\n",
"from qgym.envs.initial_mapping import *"
]
Expand Down Expand Up @@ -103,7 +101,8 @@
"outputs": [],
"source": [
"def generate_random_interaction_graph(connection_graph):\n",
" p = np.random.rand() # edge probability\n",
" rng = np.random.default_rng()\n",
" p = rng.rand() # edge probability\n",
" n = connection_graph.number_of_nodes()\n",
" return gnp_random_graph(n, p)\n",
"\n",
Expand Down
11 changes: 5 additions & 6 deletions notebooks/COMPLETED_maze_runner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@
" elif action == 3: # left\n",
" col = max(col - 1, 0)\n",
" else:\n",
" raise ValueError(\"Invalid action supplied.\")\n",
" msg = \"invalid action supplied\"\n",
" raise ValueError(msg)\n",
"\n",
" # go to new position if it is not a wall\n",
" if self.maze_map[row][col] != b\"W\":\n",
Expand Down Expand Up @@ -357,8 +358,7 @@
" row, col = new_state.position\n",
" if new_state.maze_map[row][col] == b\"G\":\n",
" return 1\n",
" else:\n",
" return 0"
" return 0"
]
},
{
Expand Down Expand Up @@ -410,10 +410,9 @@
"\n",
" if new_state[\"position\"] == old_state[\"position\"]:\n",
" return -1\n",
" elif new_state[\"maze_map\"][row][col] == b\"G\":\n",
" if new_state[\"maze_map\"][row][col] == b\"G\":\n",
" return 10\n",
" else:\n",
" return 0"
" return 0"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions notebooks/COMPLETED_routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import networkx as nx\n",
"from networkx.generators import gnp_random_graph\n",
"import matplotlib.pyplot as plt\n",
"import networkx as nx\n",
"from IPython.display import clear_output\n",
"from stable_baselines3 import PPO\n",
"from stable_baselines3.common.env_checker import check_env\n",
"from IPython.display import clear_output\n",
"\n",
"from qgym.envs.routing import *"
]
Expand Down
8 changes: 2 additions & 6 deletions notebooks/EMPTY_routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import networkx as nx\n",
"from networkx.generators import gnp_random_graph\n",
"import matplotlib.pyplot as plt\n",
"from stable_baselines3 import PPO\n",
"from stable_baselines3.common.vec_env import SubprocVecEnv\n",
"import networkx as nx\n",
"from IPython.display import clear_output\n",
"from stable_baselines3 import PPO\n",
"\n",
"from qgym.envs.routing import *"
]
Expand Down Expand Up @@ -416,7 +413,6 @@
"metadata": {},
"outputs": [],
"source": [
"...\n",
"model.save(\"routing_2\")"
]
},
Expand Down
Loading
Loading