Skip to content

Commit c1a6600

Browse files
authored
Merge pull request #226 from ds4dm/blacken-docs
Blacken docs
2 parents 05485f2 + 774c13e commit c1a6600

File tree

12 files changed

+47
-30
lines changed

12 files changed

+47
-30
lines changed

.github/workflows/continuous-testing.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ jobs:
5454
with: { environment-file: dev/conda.yaml }
5555
- name: "Configure, build, and test ecole-lib with sanitizer."
5656
shell: bash -l {0}
57-
run: bash dev/run.sh --fix-pythonpath configure -D SANITIZE_ADDRESS=ON -- test-lib
57+
# Using Ctest runner to avoid out of memory
58+
run: bash dev/run.sh --fix-pythonpath configure -D SANITIZE_ADDRESS=ON -- ctest-lib
5859

5960
check-code:
6061
runs-on: ubuntu-20.04

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ repos:
2020
- id: clang-tidy
2121
args: [--fix, --fix-errors]
2222
- repo: https://github.com/psf/black
23-
rev: 19.10b0
23+
rev: 21.7b0
2424
hooks:
2525
- id: black
26+
- repo: https://github.com/asottile/blacken-docs
27+
rev: v1.10.0
28+
hooks:
29+
- id: blacken-docs
30+
args: [ '--line-length', '100' ]
31+
additional_dependencies: [black==21.7b0]
2632
- repo: https://github.com/Lucas-C/pre-commit-hooks
2733
rev: v1.1.9
2834
hooks:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ meant to mimic the `OpenAi Gym <https://gym.openai.com/>`_ API (as much as possi
3636
for _ in range(10):
3737
obs, action_set, reward_offset, done, info = env.reset(next(instances))
3838
while not done:
39-
obs, action_set, reward, done, info = env.step(action_set[0])
39+
obs, action_set, reward, done, info = env.step(action_set[0])
4040
4141
4242
Documentation

dev/conda.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies:
2222

2323
# Documentation
2424
- doxygen
25-
- sphinx>=3.0
25+
- sphinx = 4.0
2626
- breathe>=4.15
2727
- sphinx_rtd_theme
2828

dev/run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ function test_lib {
184184
}
185185

186186

187+
# CTest runner runs test individually, reducing mem consumption
188+
function ctest_lib {
189+
if files_have_changed 'CMakeLists.txt' 'libecole'; then
190+
if_rebuild_then build_lib_test
191+
local extra_args=("$@")
192+
if [ "${fail_fast}" = "true" ]; then
193+
extra_args+=("--stop-on-failure ")
194+
fi
195+
# Possible option --parallel
196+
cmake_build test -- ARGS="${extra_args[@]}"
197+
else
198+
log "Skipping ${FUNCNAME[0]} as unchanged since ${rev}."
199+
fi
200+
}
201+
202+
187203
function test_py {
188204
local -r relevant_files=('CMakeLists.txt' 'libecole/CMakeLists.txt' 'libecole/src' 'libecole/include' 'python')
189205
if files_have_changed "${relevant_files[@]}"; then

docs/howto/create-environments.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ example, so we do not override it.
5959

6060

6161
class SimpleBranchingDynamics(ecole.dynamics.BranchingDynamics):
62-
6362
def reset_dynamics(self, model):
6463
# Share memory with Ecole model
6564
pyscipopt_model = model.as_pyscipopt()
@@ -95,7 +94,6 @@ To do so, we will take parameters in the constructor.
9594
:skipif: pyscipopt is None
9695

9796
class SimpleBranchingDynamics(ecole.dynamics.BranchingDynamics):
98-
9997
def __init__(self, disable_presolve=True, disable_cuts=True, *args, **kwargs):
10098
super().__init__(*args, **kwargs)
10199
self.disable_presolve = disable_presolve

docs/howto/create-functions.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ maximum absolute value.
3131

3232

3333
class ScaledNodeBipartite(NodeBipartite):
34-
3534
def extract(self, model, done):
3635
# Call parent method to get the original observation
3736
obs = super().extract(model, done)
@@ -55,7 +54,6 @@ This will illustrate how the class paradigm is useful to saving information betw
5554
.. testcode::
5655

5756
class MovingScaledNodeBipartite(NodeBipartite):
58-
5957
def __init__(self, alpha, *args, **kwargs):
6058
# Construct parent class with other parameters
6159
super().__init__(*args, **kwargs)
@@ -123,8 +121,7 @@ For instance, we can create a ``StochasticReward`` function that will wrap any g
123121

124122

125123
class StochasticReward:
126-
127-
def __init__(self, reward_function, probability = 0.05):
124+
def __init__(self, reward_function, probability=0.05):
128125
self.reward_function = reward_function
129126
self.probability = probability
130127

@@ -135,7 +132,7 @@ For instance, we can create a ``StochasticReward`` function that will wrap any g
135132
# Unconditionally getting reward as reward_funcition.extract may have side effects
136133
reward = self.reward_function.extract(model, done)
137134
if random.random() < probability:
138-
return 0.
135+
return 0.0
139136
else:
140137
return reward
141138

docs/howto/observation-functions.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ you can explicitly pass ``None`` to the environment constructor.
5151
>>> env = ecole.environment.Branching(observation_function=None)
5252
>>> env.observation_function # doctest: +SKIP
5353
ecole.observation.nothing()
54-
>>> obs, _, _, _, _= env.reset("path/to/problem")
54+
>>> obs, _, _, _, _ = env.reset("path/to/problem")
5555
>>> obs is None
5656
True
5757

@@ -64,8 +64,8 @@ To use multiple observation functions, wrap them in a ``list`` or ``dict``.
6464
.. doctest::
6565

6666
>>> obs_func = {
67-
... "some_name": ecole.observation.NodeBipartite(),
68-
... "other_name": ecole.observation.Nothing(),
67+
... "some_name": ecole.observation.NodeBipartite(),
68+
... "other_name": ecole.observation.Nothing(),
6969
... }
7070
>>> env = ecole.environment.Branching(observation_function=obs_func)
7171
>>> obs, _, _, _, _ = env.reset("path/to/problem")
@@ -78,9 +78,7 @@ Similarily with a tuple
7878

7979
.. doctest::
8080

81-
>>> obs_func = (
82-
... ecole.observation.NodeBipartite(), ecole.observation.Nothing()
83-
... )
81+
>>> obs_func = (ecole.observation.NodeBipartite(), ecole.observation.Nothing())
8482
>>> env = ecole.environment.Branching(observation_function=obs_func)
8583
>>> obs, _, _, _, _ = env.reset("path/to/problem")
8684
>>> obs # doctest: +SKIP

docs/howto/reward-functions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Arithmetic operations are even allowed between different reward functions,
8686

8787
from ecole.reward import LpIterations, IsDone
8888

89-
4.0 * LpIterations()**2 - 3 * IsDone()
89+
4.0 * LpIterations() ** 2 - 3 * IsDone()
9090

9191
which is especially powerful because in this normally it would *not* be possible to pass both
9292
:py:class:`~ecole.reward.LpIterations` and :py:class:`~ecole.reward.IsDone` to the
@@ -96,7 +96,7 @@ All operations that are valid between scalars are valid between reward functions
9696

9797
.. testcode::
9898

99-
- IsDone() ** abs(LpIterations() // 4)
99+
-IsDone() ** abs(LpIterations() // 4)
100100

101101
In addition, not all commonly used mathematical operations have a dedicated Python operator: to
102102
accomodate this, Ecole implements a number of other operations as methods of reward functions.
@@ -110,7 +110,7 @@ This also works with rewards functions created from arithmetic expressions.
110110

111111
.. testcode::
112112

113-
(3 - 2*LpIterations()).exp()
113+
(3 - 2 * LpIterations()).exp()
114114

115115
Finally, reward functions have an ``apply`` method to compose rewards with any
116116
function.

python/src/ecole/core/instance.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ void bind_submodule(py::module const& m) {
158158
def_generate_instance(independent_set_gen, independent_set_params, R"(
159159
Generate an independent set MILP problem instance.
160160
161-
Given an undireted graph, the problem is to find a maximum subset of nodes such that no pair of nodes are connected.
162-
There are one variable per node in the underlying graph.
163-
Instead of adding one constraint per edge, a greedy algorithm is run to replace these inequalities when clique is
164-
found.
165-
The maximization problem is unwheighted, that is all objective coefficients are equal to one.
161+
Given an undireted graph, the problem is to find a maximum subset of nodes such that no pair of nodes are
162+
connected. There are one variable per node in the underlying graph. Instead of adding one constraint per edge, a
163+
greedy algorithm is run to replace these inequalities when clique is found. The maximization problem is
164+
unwheighted, that is all objective coefficients are equal to one.
166165
167166
The problem are generated using the procedure from [Bergman2016]_, and the graphs are sampled following
168167
[Erdos1959]_ and [Barabasi1999]_.
@@ -173,15 +172,15 @@ void bind_submodule(py::module const& m) {
173172
The number of nodes in the graph, and therefore of variable.
174173
graph_type:
175174
The method used in which to generate graphs.
176-
One of "barabasi_albert" or "erdos_renyi"
175+
One of ``"barabasi_albert"`` or ``"erdos_renyi"``.
177176
edge_probability:
178177
The probability of generating each edge.
179178
This parameter must be in the range [0, 1].
180-
This parameter will only be used if `graph_type == "erdos_renyi"`.
179+
This parameter will only be used if ``graph_type == "erdos_renyi"``.
181180
affinity:
182181
The number of nodes each new node will be attached to, in the sampling scheme.
183182
This parameter must be an integer >= 1.
184-
This parameter will only be used if `graph_type == "barabasi_albert"`.
183+
This parameter will only be used if ``graph_type == "barabasi_albert"``.
185184
random_engine:
186185
The random number generator used to peform all sampling.
187186

0 commit comments

Comments
 (0)