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

Tsp report #536

Open
wants to merge 98 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
ce04099
first version of tsp report + changes (many more requirements added)
pchtsp May 17, 2024
dad9f0e
add how-to reports to README
pchtsp May 17, 2024
c6f4c0f
added documentation on developing reports
pchtsp May 17, 2024
5780bff
unsuccessful tests with quarto library to call quarto and generate re…
pchtsp Jun 7, 2024
1b7378d
Merge branch 'master' into tsp_report
pchtsp Jun 7, 2024
f6b4704
added reports model, endpoint, schemas. Each report has an execution_…
pchtsp Jun 11, 2024
17e9173
fixed some wrong comments
pchtsp Jun 11, 2024
4496e11
migrations to database for reports
pchtsp Jun 12, 2024
a3bcdaf
pass executions tests
pchtsp Jun 12, 2024
82f0aa9
delete airflow dependency
pchtsp Jun 12, 2024
f30ee6d
added some additional I/O methods to the Experiment and a `generate_r…
pchtsp Jun 21, 2024
0b1619f
now it's possible to run the create the report from python using a js…
pchtsp Jun 21, 2024
409662f
New activate_dags (#543)
ggsdc Jun 28, 2024
9f83a97
Fixed numpy and pandas conoined error
ggsdc Jun 28, 2024
5c0fb2d
make tests valid with env. var CF_ALARMS_ENDPOINT=0
pchtsp Jun 28, 2024
59ad52b
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
pchtsp Jun 28, 2024
132a0c3
added quarto to github actions
pchtsp Jun 28, 2024
e0737aa
quarto is needed in test_dags
pchtsp Jun 28, 2024
83610f8
Small adjustments to pass unit tests on local and on github actions
ggsdc Jun 28, 2024
0427605
some working tests on reports.
pchtsp Jul 1, 2024
ee96b79
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
pchtsp Jul 1, 2024
4050939
Adjustments to file storage.
ggsdc Jul 2, 2024
082eff9
Added test for main get
ggsdc Jul 2, 2024
3da8771
fix uploading tests: add static and use absolute path for e.v. UPLOAD…
pchtsp Jul 3, 2024
0be825a
some comments
pchtsp Jul 3, 2024
3a47e13
Added some more funtionalities
ggsdc Jul 3, 2024
a6ecb0d
added endpoint to client and finished code in dag.
pchtsp Jul 3, 2024
9268ac9
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
pchtsp Jul 3, 2024
5b566f9
Merge branch 'develop' into tsp_report
ggsdc Jul 15, 2024
b8d711f
Small change for CodeQL
ggsdc Jul 15, 2024
35d9cc8
Some more checks on path building to restrict where the reports can b…
ggsdc Jul 15, 2024
b1d79db
Made delete endpoint to delete report file.
ggsdc Jul 16, 2024
95535bf
Added test for creation of report
ggsdc Jul 16, 2024
6077e20
Fixed wrong path
ggsdc Jul 16, 2024
0171fd8
added some unittests and integration tests for reports (incomplete)
pchtsp Jul 16, 2024
039cf08
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
pchtsp Jul 16, 2024
bdfb141
Modified default location of reports.
ggsdc Jul 16, 2024
b2ca5c1
More fixes to tests
ggsdc Jul 16, 2024
778aad2
Modified cornflow dockerfile
ggsdc Jul 16, 2024
68f4989
Modified default location of reports.
ggsdc Jul 16, 2024
824d472
Some print and error catching to get the error on Github actions
ggsdc Jul 17, 2024
4853159
More debugging
ggsdc Jul 17, 2024
3529616
Modified the way the error is built to be able to decode it as a JSON
ggsdc Jul 17, 2024
fba7418
The problem was that the destination folder for the files was not cor…
ggsdc Jul 17, 2024
8a2502a
Added test for the PUT of reports
ggsdc Jul 17, 2024
a3e5871
Changed the way get one report reports back the name of the report an…
ggsdc Jul 17, 2024
f955e62
Fixed status code on failing test
ggsdc Jul 17, 2024
c698a17
Fixed error on client test
ggsdc Jul 17, 2024
35913d5
Added tests for base client
ggsdc Jul 17, 2024
e4bdf9e
Added some typing
ggsdc Jul 17, 2024
ffcef7c
integration tests passing for tsp and timer reports
pchtsp Jul 18, 2024
63363e3
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
pchtsp Jul 18, 2024
06dd07c
added more time to tests for github actions
pchtsp Jul 19, 2024
b9a97c5
reports now can be created and edited with a file by the service_user…
pchtsp Jul 24, 2024
8236957
(previous was an incomplete commit)
pchtsp Jul 24, 2024
862f8c4
minor fixes to pass failing tests
pchtsp Jul 24, 2024
fe26094
another failing test
pchtsp Jul 24, 2024
eba17e4
fixed some errors in tests. some print statements for debugging
pchtsp Jul 24, 2024
9452cbc
Changes to Dockerfile toc reate the reports folder on the container
ggsdc Jul 26, 2024
ecdebff
Modified workflows and order of installation of cornflow-client depen…
ggsdc Jul 26, 2024
8a017c9
Undo change on DOCKERFILE
ggsdc Jul 26, 2024
45e2988
Debug log to have the name on the test
ggsdc Jul 26, 2024
4ca157b
Activated debug mode on testing configuration
ggsdc Jul 26, 2024
65eafb2
Added error logs on log in
ggsdc Jul 26, 2024
de3f636
Changed name of service user on cornflow integration testing yaml
ggsdc Jul 26, 2024
ec91924
Some small changes to tests to have them more organized
ggsdc Jul 26, 2024
7d0e2f5
Merge branch 'develop' into tsp_report
ggsdc Jul 26, 2024
9990309
Merge branch 'refs/heads/develop' into tsp_report
ggsdc Jul 26, 2024
698495a
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
ggsdc Jul 26, 2024
94e871c
take out prints
pchtsp Jul 29, 2024
fb529b0
update swagger REST API doc
pchtsp Jul 29, 2024
37cf3a2
graph coloring report
pchtsp Jul 31, 2024
a89c67f
fixed all tests
pchtsp Jul 31, 2024
8fbd570
take out hexaly from requirements
pchtsp Jul 31, 2024
6c98216
Fixed errors that caused test to fail
ggsdc Aug 2, 2024
ad57525
fix the report schema errors
pchtsp Aug 2, 2024
a5aea1a
Bump version for new client alpha
ggsdc Aug 2, 2024
8e51d58
Merge branch 'refs/heads/develop' into tsp_report
ggsdc Aug 2, 2024
c1d8803
Updated workflows for publishing
ggsdc Aug 2, 2024
6b9ae3a
Merge branch 'develop' into tsp_report
ggsdc Aug 2, 2024
c464839
Bump cornflow and airflow versions for new image building
ggsdc Aug 5, 2024
5a80ae8
Merge remote-tracking branch 'origin/tsp_report' into tsp_report
ggsdc Aug 5, 2024
d1beb92
change in where to get the get_cmap function from recent versions of …
pchtsp Aug 5, 2024
74077ba
fixed schema modification for reports
pchtsp Aug 7, 2024
31a2f54
fix: now we do not move the report, we just return the path to it.
pchtsp Aug 7, 2024
d055170
Bump cornflow-client version
ggsdc Aug 8, 2024
18871c6
Bump version for new client alpha
ggsdc Aug 8, 2024
495537e
Bump cornflow-client version on requirements file
ggsdc Aug 8, 2024
6845f53
Fixed error on requirements file
ggsdc Aug 8, 2024
bae1109
complete example of sudoku
pchtsp Aug 12, 2024
9b044db
changes while testing the windproblem
pchtsp Aug 15, 2024
9621e26
Merge branch 'sudoku' into tsp_report
pchtsp Aug 15, 2024
31c5c06
fixes to cornflowclient + tests for WindProblem
pchtsp Aug 16, 2024
0228868
take out github repo link + bump version of cornflowclient
pchtsp Aug 16, 2024
5767e21
added already deployed of cornflowclient and github link to installat…
pchtsp Aug 16, 2024
ec4f332
sudoku changes
pchtsp Sep 20, 2024
c4753aa
improve README + filter tests with flag
pchtsp Sep 20, 2024
ca1a24d
minor fixes
pchtsp Sep 20, 2024
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
12 changes: 6 additions & 6 deletions .github/workflows/cornflow-client-publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install wheel
Expand All @@ -27,16 +27,16 @@ jobs:
- name: Build a binary wheel and a source tarball
run: python setup.py sdist bdist_wheel
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
packages_dir: libs/client/dist/
repository-url: https://test.pypi.org/legacy/
packages-dir: libs/client/dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.pypi_password }}
packages_dir: libs/client/dist/
packages-dir: libs/client/dist/
- name: Get version number
uses: winterjung/split@v2
id: split
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/cornflow-publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install wheel
Expand All @@ -27,16 +27,16 @@ jobs:
- name: Build a binary wheel and a source tarball
run: python setup.py sdist bdist_wheel
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.CORNFLOW_TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
packages_dir: cornflow-server/dist/
repository-url: https://test.pypi.org/legacy/
packages-dir: cornflow-server/dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.CORNFLOW_PYPI_TOKEN }}
packages_dir: cornflow-server/dist/
packages-dir: cornflow-server/dist/
- name: Get version number
uses: winterjung/split@v2
id: split
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_cornflow_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ jobs:
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
python -m pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
python -m pip install -U orloge pulp
python -m pip install -U "git+https://github.com/baobabsoluciones/cornflow@${CLIENT_BRANCH}#subdirectory=libs/client"
python -m pip install -U -r airflow_config/requirements.txt
python -m pip uninstall cornflow-client -y
python -m pip install -U "git+https://github.com/baobabsoluciones/cornflow@${CLIENT_BRANCH}#subdirectory=libs/client"
airflow db init
airflow users create -u admin -f admin -l admin -r Admin -p admin -e [email protected]
airflow webserver -p 8080 &
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test_cornflow_dags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# To install LaTeX to build PDF book
tinytex: true
- name: Install cbc
run: |
sudo apt-get install -y coinor-cbc
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/test_cornflow_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# To install LaTeX to build PDF book
tinytex: true
- name: Copy DAG files
run: |
cd ..
Expand Down Expand Up @@ -80,8 +87,9 @@ jobs:
python -m pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
python -m pip install -U orloge pulp
python -m pip uninstall cornflow-client -y
python -m pip install -U "git+https://github.com/baobabsoluciones/cornflow@${CLIENT_BRANCH}#subdirectory=libs/client"
python -m pip install -U -r airflow_config/requirements.txt
python -m pip uninstall cornflow-client -y
python -m pip install -U "git+https://github.com/baobabsoluciones/cornflow@${CLIENT_BRANCH}#subdirectory=libs/client"
airflow db init
airflow users create \
--username admin \
Expand All @@ -101,9 +109,9 @@ jobs:
AIRFLOW__API__AUTH_BACKEND: airflow.api.auth.backend.basic_auth
AIRFLOW__WEBSERVER__SECRET_KEY: e9adafa751fd35adfc1fdd3285019be15eea0758f76e38e1e37a1154fb36
AIRFLOW__CORE__LOAD_EXAMPLES: 0
AIRFLOW_CONN_CF_URI: http://airflow:Airflow_test_password1@localhost:5050
AIRFLOW_CONN_CF_URI: http://service_user:Airflow_test_password1@localhost:5050
- name: Run unit tests
run: |
run: |
coverage run --source=./cornflow/ --rcfile=./.coveragerc -m unittest discover -s cornflow/tests/unit
coverage report -m
env:
Expand All @@ -115,7 +123,7 @@ jobs:
AIRFLOW_PWD: notadmin
CF_ALARMS_ENDPOINT: 1
- name: Run ldap unit tests
run: |
run: |
coverage run -a --source=./cornflow/ --rcfile=./.coveragerc -m unittest discover -s cornflow/tests/ldap
coverage report -m
env:
Expand Down Expand Up @@ -143,7 +151,7 @@ jobs:
LOG_LEVEL: 30
CORNFLOW_SERVICE_USER: cornflow
- name: Run postgres unit tests
run: |
run: |
coverage run -a --source=./cornflow/ --rcfile=./.coveragerc -m unittest cornflow/tests/unit/test_commands.py
coverage report -m
env:
Expand Down
34 changes: 22 additions & 12 deletions cornflow-dags/DAG/activate_dags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cornflow_client.airflow.dag_utilities as utils

from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.secrets.environment_variables import EnvironmentVariablesBackend
Expand All @@ -10,6 +11,9 @@ def create_dag(app):
def solve(**kwargs):
return utils.cf_solve_app(app, EnvironmentVariablesBackend(), **kwargs)

def run(**kwargs):
return utils.cf_report(app, EnvironmentVariablesBackend(), **kwargs)

if app.default_args is not None:
default_args = app.default_args
else:
Expand All @@ -27,18 +31,24 @@ def solve(**kwargs):
tags=["model"],
**kwargs
)
with dag:
notify = getattr(app, "notify", True)
if not notify:
t1 = PythonOperator(task_id=app.name, python_callable=solve)
else:
t1 = PythonOperator(
task_id=app.name,
python_callable=solve,
on_failure_callback=utils.callback_email,
)

return dag

notify = getattr(app, "notify", True)
if not notify:
t1 = PythonOperator(task_id=app.name, python_callable=solve, dag=dag)
else:
t1 = PythonOperator(
task_id=app.name,
python_callable=solve,
on_failure_callback=utils.callback_email,
dag=dag
)

t2 = PythonOperator(task_id=f"{app.name}_report", python_callable=run, dag=dag)


t1 >> t2

return dag


for app in get_new_apps():
Expand Down
17 changes: 17 additions & 0 deletions cornflow-dags/DAG/dag_timer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os.path

import time
from cornflow_client import get_empty_schema
from cornflow_client import ApplicationCore, InstanceCore, SolutionCore, ExperimentCore
from cornflow_client.constants import SOLUTION_STATUS_FEASIBLE, STATUS_OPTIMAL
import logging

from xml.etree import ElementTree as ET


class Instance(InstanceCore):
schema = get_empty_schema()
Expand Down Expand Up @@ -33,6 +37,19 @@ def get_objective(self) -> float:
def check_solution(self, *args, **kwargs):
return dict()

def generate_report(self, report_name="report") -> str:
report_path = os.path.abspath("./report.html")
html = ET.Element("html")
body = ET.Element("body")
html.append(body)
div = ET.Element("div", attrib={"class": "foo"})
body.append(div)
span = ET.Element("span", attrib={"class": "bar"})
div.append(span)
with open(report_path, "w") as f:
ET.ElementTree(html).write(f, encoding="unicode", method="html")
return report_path


class Timer(ApplicationCore):
name = "timer"
Expand Down
23 changes: 5 additions & 18 deletions cornflow-dags/DAG/graph_coloring/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from cornflow_client import (
get_empty_schema,
ApplicationCore,
)
from cornflow_client import get_empty_schema, ApplicationCore, add_reports_to_schema
from typing import List, Dict
import pytups as pt
import os

from .solvers import OrToolsCP
Expand All @@ -18,31 +14,22 @@ class GraphColoring(ApplicationCore):
schema = get_empty_schema(
properties=dict(timeLimit=dict(type="number")), solvers=list(solvers.keys())
)
schema = add_reports_to_schema(schema, ["report"])

@property
def test_cases(self) -> List[Dict]:
def read_file(filePath):
with open(filePath, "r") as f:
contents = f.read().splitlines()

pairs = (
pt.TupList(contents[1:])
.vapply(lambda v: v.split(" "))
.vapply(lambda v: dict(n1=int(v[0]), n2=int(v[1])))
)
return dict(pairs=pairs)

file_dir = os.path.join(os.path.dirname(__file__), "data")

get_file = lambda name: os.path.join(file_dir, name)
return [
{
"name": "gc_4_1",
"instance": read_file(os.path.join(file_dir, "gc_4_1")),
"instance": Instance.from_txt_file(get_file("gc_4_1")).to_dict(),
"description": "Example data with 4 pairs",
},
{
"name": "gc_50_1",
"instance": read_file(os.path.join(file_dir, "gc_50_1")),
"instance": Instance.from_txt_file(get_file("gc_50_1")).to_dict(),
"description": "Example data with 50 pairs",
},
]
24 changes: 22 additions & 2 deletions cornflow-dags/DAG/graph_coloring/core/experiment.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from cornflow_client import ExperimentCore
from cornflow_client.core.tools import load_json
from pytups import TupList
from .instance import Instance
from .solution import Solution
import os
import quarto


class Experiment(ExperimentCore):
Expand All @@ -14,6 +16,12 @@ class Experiment(ExperimentCore):
def instance(self) -> Instance:
return super().instance

@classmethod
def from_dict(cls, data: dict):
return cls(
Instance.from_dict(data["instance"]), Solution.from_dict(data["solution"])
)

@property
def solution(self) -> Solution:
return super().solution
Expand All @@ -29,7 +37,19 @@ def check_solution(self, *args, **kwargs) -> dict:
# if a pair of nodes have the same colors: that's a problem
colors = self.solution.get_assignments()
pairs = self.instance.get_pairs()
nodes = self.instance.get_nodes()
missing_colors = TupList(set(nodes) - colors.keys())
errors = [
{"n1": n1, "n2": n2} for (n1, n2) in pairs if colors[n1] == colors[n2]
{"n1": n1, "n2": n2}
for (n1, n2) in pairs
if n1 in colors and n2 in colors and colors[n1] == colors[n2]
]
return dict(pairs=errors)
return dict(pairs=errors, missing=missing_colors)

def generate_report(self, report_name="report") -> str:
if not os.path.isabs(report_name):
report_name = os.path.join(
os.path.dirname(__file__), "../report/", report_name
)

return self.generate_report_quarto(quarto, report_name=report_name)
31 changes: 30 additions & 1 deletion cornflow-dags/DAG/graph_coloring/core/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,40 @@
from cornflow_client import InstanceCore, get_empty_schema
from cornflow_client.core.tools import load_json
import pytups as pt
import networkx as nx


class Instance(InstanceCore):
schema = load_json(os.path.join(os.path.dirname(__file__), "../schemas/input.json"))
schema_checks = get_empty_schema()

def get_pairs(self):
return pt.TupList((el["n1"], el["n2"]) for el in self.data["pairs"])
return pt.TupList(self.data["pairs"]).take(["n1", "n2"])

def get_nodes(self):
pairs = self.data["pairs"]
n1s = pt.TupList(pairs).vapply(lambda v: v["n1"])
n2s = pt.TupList(pairs).vapply(lambda v: v["n2"])
return (n1s + n2s).unique2()

@classmethod
def from_txt_file(cls, filePath):
with open(filePath, "r") as f:
contents = f.read().splitlines()

pairs = (
pt.TupList(contents[1:])
.vapply(lambda v: v.split(" "))
.vapply(lambda v: dict(n1=int(v[0]), n2=int(v[1])))
)
return Instance.from_dict(dict(pairs=pairs))

def get_graph(self):
nodes = self.get_nodes()
arcs = self.get_pairs()
G = nx.Graph()
for node in nodes:
G.add_node(node)
for n1, n2 in arcs:
G.add_edge(n1, n2)
return G
1 change: 1 addition & 0 deletions cornflow-dags/DAG/graph_coloring/report/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
Loading