Skip to content

Commit

Permalink
establish web/mosek folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Jul 19, 2023
1 parent bf537b0 commit f36e195
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
.idea
__pycache__
.venv
.ruff_cache

web/mosek
tests/cqo1.ptf
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ repos:
- id: fix-encoding-pragma

- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: reorder-python-imports
args: [--py37-plus, --add-import, 'from __future__ import annotations']

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.35.0
hooks:
- id: markdownlint-fix

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.277'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
628 changes: 597 additions & 31 deletions poetry.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ python = ">=3.9"
numpy = "*"
mosek = "*"

[tool.poetry.group.linting.dependencies]
pylint = "*"
ruff = "0.0.277"
pre-commit = "*"
black = "23.3.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
select = ["E", "F", "I"]
line-length = 100
target-version = "py38"
exclude = [
"*__init__.py"
]
ignore = ["E402"]
2 changes: 0 additions & 2 deletions qodana.yaml

This file was deleted.

22 changes: 12 additions & 10 deletions tests/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
# it may make the linter nervous though
license.upsert()

from mosek.fusion import *
import mosek.fusion as fusion

if __name__ == "__main__":
with Model("cqo1") as M:
x = M.variable("x", 3, Domain.greaterThan(0.0))
y = M.variable("y", 3, Domain.unbounded())
with fusion.Model("cqo1") as M:
x = M.variable("x", 3, fusion.Domain.greaterThan(0.0))
y = M.variable("y", 3, fusion.Domain.unbounded())

# Create the aliases
# z1 = [ y[0],x[0],x[1] ]
# and z2 = [ y[1],y[2],x[2] ]
z1 = Var.vstack(y.index(0), x.slice(0, 2))
z2 = Var.vstack(y.slice(1, 3), x.index(2))
z1 = fusion.Var.vstack(y.index(0), x.slice(0, 2))
z2 = fusion.Var.vstack(y.slice(1, 3), x.index(2))

# Create the constraint
# x[0] + x[1] + 2.0 x[2] = 1.0
M.constraint("lc", Expr.dot([1.0, 1.0, 2.0], x), Domain.equalsTo(1.0))
M.constraint(
"lc", fusion.Expr.dot([1.0, 1.0, 2.0], x), fusion.Domain.equalsTo(1.0)
)

# Create the constraints
# z1 belongs to C_3
Expand All @@ -31,11 +33,11 @@
# rotated quadratic cone of size 3, i.e.
# z1[0] >= sqrt(z1[1]^2 + z1[2]^2)
# and 2.0 z2[0] z2[1] >= z2[2]^2
qc1 = M.constraint("qc1", z1, Domain.inQCone())
qc2 = M.constraint("qc2", z2, Domain.inRotatedQCone())
qc1 = M.constraint("qc1", z1, fusion.Domain.inQCone())
qc2 = M.constraint("qc2", z2, fusion.Domain.inRotatedQCone())

# Set the objective function to (y[0] + y[1] + y[2])
M.objective("obj", ObjectiveSense.Minimize, Expr.sum(y))
M.objective("obj", fusion.ObjectiveSense.Minimize, fusion.Expr.sum(y))

# Solve the problem
M.solve()
Expand Down
2 changes: 2 additions & 0 deletions web/mosek/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore everything in this folder
*

0 comments on commit f36e195

Please sign in to comment.