Skip to content

Commit 8b69190

Browse files
committed
use cmake define
1 parent 8523add commit 8b69190

File tree

8 files changed

+240
-106
lines changed

8 files changed

+240
-106
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: build-wheels-hipo
2+
3+
on: [push]
4+
# on: [pull_request]
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
build_sdist:
12+
name: Build source distribution
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Build sdist
18+
shell: bash
19+
run: pipx run build --sdist
20+
21+
- name: check metadata
22+
run: pipx run twine check dist/*
23+
24+
build_wheels:
25+
name: Build HiPO wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }}
26+
runs-on: ${{ matrix.buildplat[0] }}
27+
strategy:
28+
# Ensure that a wheel builder finishes even if another fails
29+
fail-fast: false
30+
matrix:
31+
# From NumPy
32+
# Github Actions doesn't support pairing matrix values together, let's improvise
33+
# https://github.com/github/feedback/discussions/7835#discussioncomment-1769026
34+
buildplat:
35+
- [ubuntu-24.04, manylinux_x86_64]
36+
- [ubuntu-24.04, manylinux_i686]
37+
- [ubuntu-24.04-arm, manylinux_aarch64]
38+
- [ubuntu-24.04, musllinux_x86_64] # No OpenBlas, no test
39+
- [ubuntu-24.04, musllinux_i686]
40+
- [ubuntu-24.04-arm, musllinux_aarch64]
41+
- [macos-15-intel, macosx_x86_64]
42+
- [macos-14, macosx_arm64]
43+
- [windows-2022, win_amd64]
44+
- [windows-2022, win32]
45+
python: ["cp38", "cp39","cp310", "cp311","cp312", "cp313"]
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
# - name: Edit pyproject.toml (macOS)
51+
# if: runner.os == 'macOS'
52+
# shell: bash
53+
# run: |
54+
# # macOS sed requires a backup extension (here, an empty string '')
55+
# sed -i '' '/cmake\.args = \[/,/\]/{
56+
# s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
57+
# "-DHIPO=ON"|
58+
# }' pyproject.toml
59+
# echo "--- pyproject.toml content after macOS edit ---"
60+
# cat pyproject.toml
61+
62+
# - name: Edit pyproject.toml (Linux)
63+
# if: runner.os == 'Linux'
64+
# shell: bash
65+
# run: |
66+
# # Linux sed does NOT require a backup extension
67+
# sed -i '/cmake\.args = \[/,/\]/{
68+
# s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
69+
# "-DHIPO=ON",\
70+
# "-DBUILD_OPENBLAS=ON"|
71+
# }' pyproject.toml
72+
# echo "--- pyproject.toml content after Linux edit ---"
73+
# cat pyproject.toml
74+
75+
# - name: Edit pyproject.toml (Windows)
76+
# if: runner.os == 'Windows'
77+
# shell: pwsh
78+
# run: |
79+
# $content = Get-Content pyproject.toml -Raw
80+
# $newContent = $content -replace 'cmake\.args = \[\s*"-DPYTHON_BUILD_SETUP=ON"\s*\]', @"
81+
# cmake.args = [
82+
# "-DPYTHON_BUILD_SETUP=ON",
83+
# "-DHIPO=ON",
84+
# "-DBUILD_OPENBLAS=ON"
85+
# ]
86+
# "@
87+
# $newContent | Set-Content pyproject.toml
88+
# cat pyproject.toml
89+
90+
- name: Build wheels
91+
uses: pypa/cibuildwheel@v3.0
92+
env:
93+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
94+
CIBW_TEST_COMMAND: "pytest {project}/tests {project}/check/test_highspy_hipo.py"
95+
CIBW_TEST_REQUIRES: "pytest"
96+
CIBW_BUILD_TAG: "apache"
97+
CIBW_CONFIG_SETTINGS_LINUX: "cmake.define.HIPO=ON cmake.define.BUILD_OPENBLAS=ON"
98+
CIBW_CONFIG_SETTINGS_MACOS: "cmake.define.HIPO=ON"
99+
CIBW_CONFIG_SETTINGS_WINDOWS: "cmake.define.HIPO=ON cmake.define.BUILD_OPENBLAS=ON"
100+

.github/workflows/build-wheels.yml

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: build-wheels
22

3-
on: [push]
4-
# on: [pull_request]
3+
# on: [push]
4+
on: [pull_request]
55

66
concurrency:
77
group: ${{ github.workflow }}-${{ github.ref }}
@@ -46,47 +46,6 @@ jobs:
4646

4747
steps:
4848
- uses: actions/checkout@v4
49-
50-
- name: Edit pyproject.toml (macOS)
51-
if: runner.os == 'macOS'
52-
shell: bash
53-
run: |
54-
# macOS sed requires a backup extension (here, an empty string '')
55-
sed -i '' '/cmake\.args = \[/,/\]/{
56-
s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
57-
"-DHIPO=ON"|
58-
}' pyproject.toml
59-
echo "--- pyproject.toml content after macOS edit ---"
60-
cat pyproject.toml
61-
62-
- name: Edit pyproject.toml (Linux)
63-
if: runner.os == 'Linux'
64-
shell: bash
65-
run: |
66-
# Linux sed does NOT require a backup extension
67-
sed -i '/cmake\.args = \[/,/\]/{
68-
s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
69-
"-DHIPO=ON",\
70-
"-DBUILD_OPENBLAS=ON"|
71-
}' pyproject.toml
72-
echo "--- pyproject.toml content after Linux edit ---"
73-
cat pyproject.toml
74-
75-
- name: Edit pyproject.toml (Windows)
76-
if: runner.os == 'Windows'
77-
shell: pwsh
78-
run: |
79-
$content = Get-Content pyproject.toml -Raw
80-
$newContent = $content -replace 'cmake\.args = \[\s*"-DPYTHON_BUILD_SETUP=ON"\s*\]', @"
81-
cmake.args = [
82-
"-DPYTHON_BUILD_SETUP=ON",
83-
"-DHIPO=ON",
84-
"-DBUILD_OPENBLAS=ON"
85-
]
86-
"@
87-
$newContent | Set-Content pyproject.toml
88-
cat pyproject.toml
89-
9049
- name: Build wheels
9150
uses: pypa/cibuildwheel@v3.0
9251
env:

.github/workflows/test-python-macos.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Test Python Interface
2323
run: |
2424
python3 -m pip install .
25-
pytest -v -k "not test_hipo"
25+
pytest -v
2626
2727
- name: Test Python Examples
2828
run: |
@@ -44,22 +44,24 @@ jobs:
4444
with:
4545
python-version: ${{ matrix.python }}
4646

47-
- name: Edit pyproject
48-
run: |
49-
ls
50-
sed -i '' '/cmake\.args = \[/,/\]/{
51-
s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
52-
"-DHIPO=ON"|
53-
}' pyproject.toml
54-
cat pyproject.toml
47+
# - name: Edit pyproject
48+
# run: |
49+
# ls
50+
# sed -i '' '/cmake\.args = \[/,/\]/{
51+
# s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
52+
# "-DHIPO=ON"|
53+
# }' pyproject.toml
54+
# cat pyproject.toml
5555

56-
- name: Install build dependencies
57-
run: python3 -m pip install numpy wheel pytest
56+
# - name: Install build dependencies
57+
# run: python3 -m pip install numpy wheel pytest
5858

5959
- name: Test Python Interface
6060
run: |
6161
python3 -m pip install .
62+
--config-settings=cmake.define.HIPO=ON
6263
pytest
64+
pytest check/test_highspy_hipo.py
6365
6466
- name: Test Python Examples
6567
run: |

.github/workflows/test-python-ubuntu.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Test Python Interface
2323
run: |
2424
python3 -m pip install .
25-
pytest -v -k "not test_hipo"
25+
pytest -v
2626
2727
- name: Test Python Examples
2828
run: |
@@ -43,23 +43,26 @@ jobs:
4343
with:
4444
python-version: ${{ matrix.python }}
4545

46-
- name: Edit pyproject
47-
run: |
48-
ls
49-
sed -i '/cmake\.args = \[/,/\]/{
50-
s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
51-
"-DHIPO=ON",\
52-
"-DBUILD_OPENBLAS=ON"|
53-
}' pyproject.toml
54-
cat pyproject.toml
46+
# - name: Edit pyproject
47+
# run: |
48+
# ls
49+
# sed -i '/cmake\.args = \[/,/\]/{
50+
# s|"-DPYTHON_BUILD_SETUP=ON"|"-DPYTHON_BUILD_SETUP=ON",\
51+
# "-DHIPO=ON",\
52+
# "-DBUILD_OPENBLAS=ON"|
53+
# }' pyproject.toml
54+
# cat pyproject.toml
5555

56-
- name: Install build dependencies
57-
run: python3 -m pip install numpy wheel pytest
56+
# - name: Install build dependencies
57+
# run: python3 -m pip install numpy wheel pytest
5858

5959
- name: Test Python Interface
6060
run: |
61-
python3 -m pip install .
61+
python3 -m pip install . \
62+
--config-settings=cmake.define.HIPO=ON \
63+
--config-settings=cmake.define.BUILD_OPENBLAS=ON
6264
pytest -v
65+
pytest check/test_highspy_hipo.py
6366
6467
- name: Test Python Examples
6568
run: |

.github/workflows/test-python-win.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Test python install
2424
run: |
2525
python -m pip install .
26-
pytest -k "not test_hipo"
26+
pytest
2727
2828
- name: Test Python Examples
2929
run: |
@@ -45,27 +45,31 @@ jobs:
4545
with:
4646
python-version: ${{ matrix.python }}
4747

48-
- name: Edit pyproject
49-
run: |
50-
ls
51-
$content = Get-Content pyproject.toml -Raw
52-
$newContent = $content -replace 'cmake\.args = \[\s*"-DPYTHON_BUILD_SETUP=ON"\s*\]', @"
53-
cmake.args = [
54-
"-DPYTHON_BUILD_SETUP=ON",
55-
"-DHIPO=ON",
56-
"-DBUILD_OPENBLAS=ON"
57-
]
58-
"@
59-
$newContent | Set-Content pyproject.toml
60-
cat pyproject.toml
48+
# - name: Edit pyproject
49+
# run: |
50+
# ls
51+
# $content = Get-Content pyproject.toml -Raw
52+
# $newContent = $content -replace 'cmake\.args = \[\s*"-DPYTHON_BUILD_SETUP=ON"\s*\]', @"
53+
# cmake.args = [
54+
# "-DPYTHON_BUILD_SETUP=ON",
55+
# "-DHIPO=ON",
56+
# "-DBUILD_OPENBLAS=ON"
57+
# ]
58+
# "@
59+
# $newContent | Set-Content pyproject.toml
60+
# cat pyproject.toml
6161

62-
- name: Install build dependencies
63-
run: python -m pip install numpy wheel pytest
62+
# check if automatic
63+
# - name: Install build dependencies
64+
# run: python -m pip install numpy wheel pytest
6465

6566
- name: Test python install
6667
run: |
67-
python -m pip install .
68+
python -m pip install . `
69+
--config-settings=cmake.define.HIPO=ON `
70+
--config-settings=cmake.define.BUILD_OPENBLAS=ON
6871
pytest
72+
pytest check/test_highspy_hipo.py
6973
7074
- name: Test Python Examples
7175
run: |

check/test_highspy_hipo.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import tempfile
2+
import unittest
3+
import highspy
4+
from highspy.highs import highs_linear_expression, qsum
5+
import numpy as np
6+
from sys import platform
7+
import signal
8+
9+
10+
class TestHighsPy(unittest.TestCase):
11+
def get_example_model(self):
12+
"""
13+
minimize f = x0 + x1
14+
subject to x1 <= 7
15+
5 <= x0 + 2x1 <= 15
16+
6 <= 3x0 + 2x1
17+
0 <= x0 <= 4; 1 <= x1
18+
"""
19+
inf = highspy.kHighsInf
20+
h = highspy.Highs()
21+
# Define a HighsLp instance
22+
lp = highspy.HighsLp()
23+
lp.num_col_ = 2
24+
lp.num_row_ = 3
25+
lp.col_cost_ = np.array([1, 1], dtype=np.double)
26+
lp.col_lower_ = np.array([0, 1], dtype=np.double)
27+
lp.col_upper_ = np.array([4, inf], dtype=np.double)
28+
lp.row_lower_ = np.array([-inf, 5, 6], dtype=np.double)
29+
lp.row_upper_ = np.array([7, 15, inf], dtype=np.double)
30+
lp.a_matrix_.start_ = np.array([0, 2, 5])
31+
lp.a_matrix_.index_ = np.array([1, 2, 0, 1, 2])
32+
lp.a_matrix_.value_ = np.array([1, 3, 1, 2, 2], dtype=np.double)
33+
h.passModel(lp)
34+
return h
35+
36+
def test_example_model_builder(self):
37+
"""
38+
minimize f = x0 + x1
39+
subject to x1 <= 7
40+
5 <= x0 + 2x1 <= 15
41+
6 <= 3x0 + 2x1
42+
0 <= x0 <= 4; 1 <= x1
43+
"""
44+
h = highspy.Highs()
45+
46+
x0 = h.addVariable(lb=0, ub=4, obj=1)
47+
x1 = h.addVariable(lb=1, ub=7, obj=1)
48+
49+
h.addConstr(5 <= x0 + 2 * x1 <= 15)
50+
h.addConstr(6 <= 3 * x0 + 2 * x1)
51+
52+
lp = h.getLp()
53+
54+
self.assertEqual(lp.num_col_, 2)
55+
self.assertEqual(lp.num_row_, 2)
56+
self.assertAlmostEqual(lp.col_cost_[0], 1)
57+
self.assertAlmostEqual(lp.col_lower_[0], 0)
58+
self.assertAlmostEqual(lp.col_upper_[0], 4)
59+
self.assertAlmostEqual(lp.row_lower_[0], 5)
60+
self.assertAlmostEqual(lp.row_upper_[0], 15)
61+
self.assertAlmostEqual(lp.row_lower_[1], 6)
62+
self.assertAlmostEqual(lp.row_upper_[1], highspy.kHighsInf)
63+
64+
def test_hipo(self):
65+
print("running hipo test")
66+
h = self.get_example_model()
67+
h.setOptionValue("solver", "hipo")
68+
h.setOptionValue("output_flag", True)
69+
70+
[status, output_flag] = h.getOptionValue("solver")
71+
self.assertEqual(output_flag, "hipo")
72+
73+
h.run()
74+
self.assertEqual(status, highspy.HighsStatus.kOk)
75+
76+
status = h.getModelStatus()
77+
self.assertEqual(status, highspy.HighsModelStatus.kOptimal)

0 commit comments

Comments
 (0)