Skip to content

Commit 7c448ab

Browse files
authored
Merge pull request #133 from PerformanceEstimation/demo/proof_extraction
Demo/proof extraction
2 parents 2c86ec2 + 4e4fe2d commit 7c448ab

12 files changed

Lines changed: 2048 additions & 123 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ dmypy.json
137137
# Documentation
138138
docs/autodocgen-output
139139
docs/build
140+
docs/source/notebooks_folder

PEPit/pep.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ class PEP(object):
4444
_list_of_psd_sent_to_wrapper (list): list of :class:`PSDMatrix` objects actually sent to the wrapper.
4545
4646
objective (Expression): the expression to be maximized by the solver.
47-
It is set by the method `solve`. And should not be updated otherwise.
47+
It is set by the method `solve`.
48+
And should not be updated otherwise.
4849
4950
G_value (ndarray): the value of the Gram matrix G that the solver found.
50-
F_value (ndarray): the value of the vector of :class:`Expression`s F that the solver found.
51+
F_value (ndarray): the value of the vector of :class:`Expression` F that the solver found.
5152
5253
residual (ndarray): the dual value found by the solver to the lmi constraints G >> 0.
5354
@@ -191,6 +192,8 @@ def set_initial_condition(self, condition, name=None):
191192
# Set name
192193
if name is not None:
193194
condition.set_name(name=name)
195+
else:
196+
condition.set_name(name="Initial condition")
194197

195198
# Call add_constraint method
196199
self.add_constraint(constraint=condition)
@@ -414,9 +417,10 @@ def _prepare_constraints(self, verbose=1):
414417
# Note maximizing the minimum of all the performance metrics
415418
# is equivalent to maximize objective which is constraint to be smaller than all the performance metrics.
416419

417-
for performance_metric in self.list_of_performance_metrics:
420+
for rank, performance_metric in enumerate(self.list_of_performance_metrics):
418421
assert isinstance(performance_metric, Expression)
419422
performance_metric_constraint = (self.objective <= performance_metric)
423+
performance_metric_constraint.set_name(name="Performance metric {}".format(rank+1))
420424
self._list_of_prepared_constraints.append(performance_metric_constraint)
421425

422426
if verbose:

PEPit/wrapper.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class Wrapper(object):
1616
1717
Attributes:
1818
_list_of_constraints_sent_to_solver (list): list of :class:`Constraint` and :class:`PSDMatrix` objects
19-
associated to the PEP. This list does not contain constraints
20-
due to internal representation of the problem by the solver.
19+
associated to the :class:`PEP`.
20+
This list does not contain constraints due to internal
21+
representation of the problem by the solver.
2122
optimal_F (numpy.array): Elements of F after solving.
2223
optimal_G (numpy.array): Gram matrix of the PEP after solving.
2324
objective (Expression): The objective expression that must be maximized.
@@ -30,9 +31,9 @@ class Wrapper(object):
3031
solver_name (str): The name of the solver the wrapper interact with.
3132
verbose (int): Level of information details to print (Override the solver verbose parameter).
3233
33-
- 0: No verbose at all
34-
- 1: PEPit information is printed but not solver's
35-
- 2: Both PEPit and solver details are printed
34+
- 0: No verbose at all.
35+
- 1: PEPit information is printed but not solver's.
36+
- 2: Both PEPit and solver details are printed.
3637
3738
"""
3839

@@ -44,9 +45,9 @@ def __init__(self, verbose=1):
4445
Args:
4546
verbose (int): Level of information details to print (Override the solver verbose parameter).
4647
47-
- 0: No verbose at all
48-
- 1: PEPit information is printed but not solver's
49-
- 2: Both PEPit and solver details are printed
48+
- 0: No verbose at all.
49+
- 1: PEPit information is printed but not solver's.
50+
- 2: Both PEPit and solver details are printed.
5051
5152
"""
5253
# Initialize lists of constraints that are used to solve the SDP.
@@ -131,8 +132,9 @@ def assign_dual_values(self):
131132
residual (ndarray): main dual PSD matrix (dual to the PSD constraint on the Gram matrix).
132133
133134
Raises:
134-
TypeError if the attribute `_list_of_constraints_sent_to_solver` of this object
135-
is neither a :class:`Constraint` object, nor a :class:`PSDMatrix` one.
135+
TypeError
136+
if the attribute `_list_of_constraints_sent_to_solver` of this object is neither
137+
a :class:`Constraint` object, nor a :class:`PSDMatrix` one.
136138
137139
"""
138140
dual_values, residual = self._recover_dual_values()

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sphinx
22
sphinx-autodocgen
33
sphinx-rtd-theme
4-
myst-parser
4+
myst-nb
55
easydev
66
-r ../requirements.txt

docs/source/_static/custom.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* 1. Fix the double math numbering */
2+
/* This targets the MyST-generated label that floats above the equation */
3+
div.myst-math-label {
4+
display: none !important;
5+
}
6+
7+
/* 2. Layout Fixes */
8+
/* Ensures the actual MathJax number on the right has space */
9+
div.math {
10+
overflow: visible !important;
11+
width: 100%;
12+
}
13+
14+
/* 3. Kill the 'ghost' equation numbers generated by Sphinx/MyST */
15+
span.eqno {
16+
display: none !important;
17+
visibility: hidden !important;
18+
position: absolute !important; /* Move it out of the layout flow */
19+
width: 0 !important;
20+
height: 0 !important;
21+
}

docs/source/conf.py

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
# Configuration file for the Sphinx documentation builder.
2-
#
3-
# This file only contains a selection of the most common options. For a full
4-
# list see the documentation:
5-
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6-
7-
# -- Path setup --------------------------------------------------------------
8-
9-
# If extensions (or modules to document with autodoc) are in another directory,
10-
# add these directories to sys.path here. If the directory is relative to the
11-
# documentation root, use os.path.abspath to make it absolute, like shown here.
12-
#
13-
# import os
141
import os
152
import sys
3+
import shutil
164

175
# The module you're documenting (assumes you've added the project root dir to sys.path)
186
sys.path.insert(0, os.path.abspath('../..'))
7+
import PEPit
198

209
# -- Project information -----------------------------------------------------
21-
2210
project = 'PEPit'
2311
copyright = '2021, PEPit Contributors'
2412
author = 'PEPit Contributors'
@@ -32,7 +20,6 @@
3220
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3321
# ones.
3422
extensions = [
35-
# 'easydev.copybutton',
3623
'sphinx.ext.autodoc',
3724
'sphinx.ext.doctest',
3825
'sphinx.ext.intersphinx',
@@ -43,68 +30,97 @@
4330
'sphinx.ext.viewcode',
4431
'sphinx.ext.napoleon',
4532
'sphinx.ext.autosummary',
46-
# 'sphinxcontrib_autodocgen',
47-
'myst_parser',
33+
'myst_nb',
4834
]
4935

50-
napoleon_custom_sections = [('Returns', 'params_style'),
51-
('Attributes', 'params_style')]
36+
source_suffix = {
37+
'.rst': 'restructuredtext',
38+
'.md': 'markdown',
39+
'.ipynb': 'myst-nb',
40+
}
5241

53-
import PEPit
42+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '**.ipynb_checkpoints']
43+
templates_path = ['_templates']
44+
45+
# -- MyST & Notebook Settings ------------------------------------------------
46+
nb_execution_mode = "off"
47+
myst_title_to_header = True
48+
myst_dmath_allow_labels = False # Disable MyST labels to stop double-numbering
49+
myst_update_mathjax = False # Let MathJax 3 handle its own configuration
50+
myst_dmath_double_inline = True
51+
52+
myst_enable_extensions = [
53+
"dollarmath",
54+
"amsmath",
55+
"colon_fence",
56+
"deflist",
57+
"html_image",
58+
"html_admonition",
59+
]
60+
61+
# -- MathJax 3 Settings ------------------------------------------------------
62+
mathjax3_config = {
63+
'tex': {
64+
'inlineMath': [['$', '$'], ['\\(', '\\)']],
65+
'displayMath': [['$$', '$$'], ['\\[', '\\]']],
66+
'processEscapes': True,
67+
'tags': 'ams', # AMS numbering (1), (2) on the right
68+
'useLabelIds': True
69+
},
70+
'options': {
71+
'processHtmlClass': 'tex2jax_process|mathjax_process|math|output_area',
72+
}
73+
}
74+
75+
# -- HTML Output Settings ---------------------------------------------------
76+
html_theme = 'sphinx_rtd_theme'
77+
html_static_path = ['_static']
78+
html_secnumber_suffix = " "
5479

80+
# -- Napoleon settings -------------------------------------------------------
81+
napoleon_google_docstring = True
82+
napoleon_numpy_docstring = True
83+
napoleon_include_init_with_doc = False
84+
napoleon_include_private_with_doc = False
85+
napoleon_include_special_with_doc = False
86+
87+
# -- Napoleon & Autodoc -----------------------------------------------------
88+
napoleon_custom_sections = [('Returns', 'params_style'), ('Attributes', 'params_style')]
89+
autoclass_content = 'both'
5590
autodocgen_config = [{
5691
'modules': [PEPit],
5792
'generated_source_dir': './autodocgen-output/',
5893

59-
# if module matches this then it and any of its submodules will be skipped
94+
# Skips any module with "__" in the name or specific internal modules
6095
'skip_module_regex': '(.*[.]__|myskippedmodule)',
6196

62-
# produce a text file containing a list of everything documented. you can use this in a test to notice
63-
# when you've intentionally added/removed/changed a documented API
97+
# Log file to track exactly what is being documented
6498
'write_documented_items_output_file': 'autodocgen_documented_items.txt',
6599

66-
# customize autodoc on a per-module basis
100+
# Custom options for specific classes if needed
67101
'autodoc_options_decider': {
68-
'mymodule.FooBar': {'inherited-members': True},
102+
'PEPit.FooBar': {'inherited-members': True},
69103
},
70104

71-
# choose a different title for specific modules, e.g. the toplevel one
72-
'module_title_decider': lambda modulename: 'API Reference' if modulename == 'mymodule' else modulename,
105+
# Renames the top-level module to "API Reference" in the TOC
106+
'module_title_decider': lambda modulename: 'API Reference' if modulename == 'PEPit' else modulename,
73107
}]
74108

75-
autoclass_content = 'both'
76-
77-
# Include or not the special methods
78-
napoleon_include_special_with_doc = False
109+
# -- Automated Notebook Copying ---------------------------------------------
110+
current_dir = os.path.dirname(__file__)
111+
nb_source = os.path.abspath(os.path.join(current_dir, '../../ressources/demo/'))
112+
nb_dest = os.path.join(current_dir, 'notebooks_folder')
79113

80-
# Add any paths that contain templates here, relative to this directory.
81-
templates_path = ['_templates']
114+
if os.path.exists(nb_dest):
115+
shutil.rmtree(nb_dest)
116+
os.makedirs(nb_dest)
82117

83-
# List of patterns, relative to source directory, that match files and
84-
# directories to ignore when looking for source files.
85-
# This pattern also affects html_static_path and html_extra_path.
86-
exclude_patterns = []
118+
if os.path.exists(nb_source):
119+
for file in os.listdir(nb_source):
120+
if file.endswith('.ipynb'):
121+
shutil.copy2(os.path.join(nb_source, file), os.path.join(nb_dest, file))
87122

88-
# -- Options for HTML output -------------------------------------------------
89123

90-
# The theme to use for HTML and HTML Help pages. See the documentation for
91-
# a list of builtin themes.
92-
#
93-
html_theme = 'sphinx_rtd_theme'
94-
95-
# # Make the copy paste possible for any example code in documentation
96-
# import easydev
97-
#
98-
# jscopybutton_path = easydev.copybutton.get_copybutton_path()
99-
#
100-
# # if not os.path.isdir('_static'):
101-
# # os.mkdir('_static')
102-
#
103-
# import shutil
104-
#
105-
# shutil.copy(jscopybutton_path, '_static')
106-
107-
# Add any paths that contain custom static files (such as style sheets) here,
108-
# relative to this directory. They are copied after the builtin static files,
109-
# so a file named "default.css" will overwrite the builtin "default.css".
110-
html_static_path = ['_static']
124+
# -- Setup Function ---------------------------------------------------------
125+
def setup(app):
126+
app.add_css_file('custom.css')

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Welcome to PEPit's documentation!
1414
quickstart
1515
api
1616
examples
17+
tutorials
1718
whatsnew
1819
contributing
1920

docs/source/tutorials.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Tutorials
2+
=========
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
:caption: Contents:
7+
8+
Finding worst-case guarantees <notebooks_folder/PEPit_demo.ipynb>
9+
Extracting a proof <notebooks_folder/PEPit_demo_extracting_a_proof.ipynb>

docs/source/whatsnew/0.4.1.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ What's new in PEPit 0.4.1
44
New features:
55
-------------
66

7-
- New: one can disable some software verification tools (licensing, installation, etc) to allow for fast processing time (via boolean option safe_mode).
7+
- One can now disable some software verification tools (licensing, installation, etc) to allow for fast processing time (via boolean option safe_mode).
88

99
- Constraints (scalar and LMI) can now be deactivated using the `deactivate` method and activated back using the `activated` method. Note the PEP can be solved several times with different activated constraints. The method `solve` only creates the interpolation constraints once for all.
1010

11+
New demo:
12+
---------
13+
14+
- The file `ressources/demo/PEPit_demo_extracting_a_proof.ipynb` contains an example usage of the new :class:`Constraint` feature.
15+
1116
Fixes:
1217
------
1318

0 commit comments

Comments
 (0)