Skip to content

support for python3.13 #415

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

Open
wants to merge 2 commits into
base: highs
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
22 changes: 15 additions & 7 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.13

- name: Upgrade pip
run: python -m pip install --upgrade pip
Expand All @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9-v7.3.15"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12","3.13", "pypy3.9-v7.3.15"]
os: [macos-11, macos-12, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022]
exclude:
# temporarily exclude pypy3 on mac-os as there failing tests caused by bug on cbc side
Expand All @@ -50,14 +50,22 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: 'pip'

- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-

- name: Check python version
run: python -c "import sys; import platform; print('Python %s implementation %s on %s' % (sys.version, platform.python_implementation(), sys.platform))"
Expand Down
4 changes: 2 additions & 2 deletions docs/python-mip_theme/static/lib/jquery/jquery.min.js

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions mip/highs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@
# need library matching operating system
platform = sys.platform.lower()
if "linux" in platform:
pattern = "highs_bindings.*.so"
patterns = ["highs_bindings.*.so", "_core.*.so"]
elif platform.startswith("win"):
pattern = "highs_bindings.*.pyd"
patterns = ["highs_bindings.*.pyd", "_core.*.pyd"]
elif any(platform.startswith(p) for p in ("darwin", "macos")):
pattern = "highs_bindings.*.so"
patterns = ["highs_bindings.*.so", "_core.*.so"]
else:
raise NotImplementedError(f"{sys.platform} not supported!")

# there should only be one match
[libfile] = glob.glob(os.path.join(pkg_path, pattern))
matched_files = []
for pattern in patterns:
matched_files.extend(glob.glob(os.path.join(pkg_path, pattern)))
if len(matched_files) != 1:
raise FileNotFoundError(f"Could not find HiGHS library in {pkg_path}.")
[libfile] = matched_files
logger.debug("Choosing HiGHS library {libfile} via highspy package.")

highslib = ffi.dlopen(libfile)
Expand Down
2 changes: 2 additions & 0 deletions mip/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def add(
return new_var

def __getitem__(self: "VarList", key):
if key is None:
raise KeyError("Empty key access (e.g., varlist[]) is not allowed in Python 3.13")
if isinstance(key, str):
return self.__model.var_by_name(key)
return self.__vars[key]
Expand Down
4 changes: 2 additions & 2 deletions mip/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def constr_by_name(self: "Model", name: str) -> Optional["mip.Constr"]:
constraint or None if not found
"""
cidx = self.solver.constr_get_index(name)
if cidx < 0 or cidx > len(self.constrs):
if cidx < 0 or cidx >= len(self.constrs):
return None
return self.constrs[cidx]

Expand All @@ -484,7 +484,7 @@ def var_by_name(self: "Model", name: str) -> Optional["mip.Var"]:
Variable or None if not found
"""
v = self.solver.var_get_index(name)
if v < 0 or v > len(self.vars):
if v < 0 or v >= len(self.vars):
return None
return self.vars[v]

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "mip"
description = "Python tools for Modeling and Solving Mixed-Integer Linear Programs (MIPs)"
readme = "README.md"
requires-python = ">=3.7,<3.13"
requires-python = ">=3.7,<3.14"
license = {file = "LICENSE"}
authors = [
{name="Tulio A.M. Toffolo", email="[email protected]"},
Expand All @@ -25,7 +25,7 @@ classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Scientific/Engineering :: Mathematics"
Expand All @@ -41,7 +41,7 @@ numpy = [
"numpy==1.21.*; python_version=='3.7'"
]
gurobi = ["gurobipy>=8"]
highs = ["highspy>=1.5.3; python_version<='3.11'"]
highs = ["highspy>=1.6.0"]
test = [
"pytest>=7.4",
"networkx==2.8.8; python_version>='3.8'",
Expand Down