Skip to content

Commit

Permalink
add python 3.12 and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
virgesmith committed Nov 5, 2023
1 parent 7031c4a commit 567110e
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.10" ]
python-version: [ "3.11" ]
steps:
- uses: actions/checkout@v3
- name: "pip: Python ${{ matrix.python-version }} coverage"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mpi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3
- name: "pip: Python ${{ matrix.python-version }}"
Expand Down
2 changes: 1 addition & 1 deletion examples/boids/boids2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def step(self) -> None:
self.__normalise()

# set colours
self.boids.c = 0
self.boids.c = 0.0
self.boids.loc[in_range[0:self.N_predators].sum(axis=0) != 0, "c"] = 1/3
self.boids.loc[too_close[0:self.N_predators].sum(axis=0) != 0, "c"] = 2/3
self.boids.loc[0:self.N_predators - 1, "c"] = 1
Expand Down
2 changes: 1 addition & 1 deletion examples/conway/conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Conway(no.Model):

__glider = np.array([[0, 0, 1], [1, 0, 1], [0, 1, 1]], dtype=int)

def __init__(self, nx: int, ny: int, n: int, edge: no.Edge=no.Edge.WRAP) -> None:
def __init__(self, nx: int, ny: int, edge: no.Edge=no.Edge.WRAP) -> None:
super().__init__(no.LinearTimeline(0, 1), no.MonteCarlo.nondeterministic_stream)

# create n automata at regular positions
Expand Down
4 changes: 1 addition & 3 deletions examples/conway/run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# saturation (proportion initially alive)
sat = 0.36

n = int(nx * ny * sat)

# edges wrap - try with no.Edge.CONSTRAIN
m = Conway(nx, ny, n, no.Edge.WRAP)
m = Conway(nx, ny, no.Edge.WRAP)

no.run(m)
13 changes: 6 additions & 7 deletions examples/infection/infection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from time import sleep
import matplotlib.pyplot as plt
import numpy as np

from neworder.geospatial import GeospatialGraph
import pandas as pd
import osmnx as ox
from shapely import line_interpolate_point
import geopandas as gpd

import neworder as no
from neworder.geospatial import GeospatialGraph

class Status(Enum):
SUSCEPTIBLE = 0
Expand Down Expand Up @@ -54,17 +54,16 @@ def __init__(self,
# create the agent data, which is stored in a geopandas geodataframe
start_positions = self.domain.all_nodes.sample(n=n_agents, random_state=self.nprand, replace=True).index.values
speeds = self.nprand.lognormal(np.log(speed), 0.2, n_agents)
agents = gpd.GeoDataFrame(data={"node": start_positions, "speed": speeds, "status": Status.SUSCEPTIBLE, "t_infect": no.time.NEVER})
agents = pd.DataFrame(data={"node": start_positions, "speed": speeds, "status": Status.SUSCEPTIBLE, "t_infect": no.time.NEVER})
agents["dest"] = agents["node"].apply(self.__random_next_dest)
agents["path"] = agents[["node", "dest"]].apply(lambda r: self.domain.shortest_path(r["node"], r["dest"], weight="length"), axis=1)
agents["dist"] = agents.path.apply(lambda p: p.length)
agents["dist"] = agents.path.apply(lambda p: p.length).astype(float)
agents["offset"] = 0.0
agents["geometry"] = agents["path"].apply(lambda linestr: line_interpolate_point(linestr, 0))
infected = self.nprand.choice(agents.index, n_infected, replace=False)
agents.loc[infected, "status"] = Status.INFECTED
agents.loc[infected, "t_infect"] = self.timeline.index

self.agents = agents
self.agents = gpd.GeoDataFrame(agents, geometry=agents["path"].apply(lambda linestr: line_interpolate_point(linestr, 0)))
self.fig, self.g = self.__init_visualisation()

def step(self) -> None:
Expand Down Expand Up @@ -111,7 +110,7 @@ def __update_position(self) -> None:
# path <- (node, dest), dist <- new_dist
self.agents.loc[overshoots, "path"] = self.agents.loc[overshoots, ["node", "dest"]] \
.apply(lambda r: self.domain.shortest_path(r["node"], r["dest"], weight="length"), axis=1)
self.agents.loc[overshoots, "dist"] = self.agents.loc[overshoots, "path"].apply(lambda p: p.length)
self.agents.loc[overshoots, "dist"] = self.agents.loc[overshoots, "path"].apply(lambda p: p.length).astype(float)
# finally update position
self.agents.loc[overshoots, "geometry"] = self.agents.loc[overshoots, "path"].apply(lambda linestr: line_interpolate_point(linestr, 0))

Expand Down
2 changes: 1 addition & 1 deletion examples/people/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def check(self) -> bool:

def plot_pyramid(self) -> None:
a = np.arange(86)
s = self.population.groupby(by=["DC1117EW_C_SEX", "DC1117EW_C_AGE"])["DC1117EW_C_SEX"].count()
s = self.population.groupby(by=["DC1117EW_C_SEX", "DC1117EW_C_AGE"], observed=False)["DC1117EW_C_SEX"].count()
m = s[s.index.isin([1], level="DC1117EW_C_SEX")].values
f = s[s.index.isin([2], level="DC1117EW_C_SEX")].values

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
Expand Down Expand Up @@ -60,8 +61,8 @@ dev = [


[project.urls]
"Homepage" = "https://github.com/pypa/sampleproject"
"Bug Tracker" = "https://github.com/pypa/sampleproject/issues"
"Homepage" = "https://neworder.readthedocs.io/"
"Bug Tracker" = "https://github.com/virgesmith/neworder/issues"

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down
3 changes: 2 additions & 1 deletion test/test_mc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from math import factorial
import numpy as np
import numpy.typing as npt
import neworder as no
Expand Down Expand Up @@ -132,7 +133,7 @@ def test_mc_counts(base_model: no.Model) -> None:

def poisson_pdf(x: range, l: float) -> np.ndarray:
y = np.exp(-l)
return np.array([l**k * y / np.math.factorial(k) for k in x]) # type: ignore # Module has no attribute "math"; maybe "emath" or "mat"?
return np.array([l**k * y / factorial(k) for k in x]) # type: ignore # Module has no attribute "math"; maybe "emath" or "mat"?

tests = [(1.0, 1.0, 10000), (3.0, 0.5, 10000), (0.2, 2.0, 10000), (10.0, 1.0, 1000), (3.0, 1.0, 100000)]

Expand Down

0 comments on commit 567110e

Please sign in to comment.