Skip to content

Commit 1d6379e

Browse files
committed
Add black to documentation
1 parent 05485f2 commit 1d6379e

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ repos:
2323
rev: 19.10b0
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

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.

0 commit comments

Comments
 (0)