Skip to content

Commit ec46fb7

Browse files
committed
REFACT(doctest): Ελληνικα sumbols in formulas
1 parent 51a1a62 commit ec46fb7

File tree

5 files changed

+72
-67
lines changed

5 files changed

+72
-67
lines changed

README.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,46 +108,47 @@ OR with various "extras" dependencies, such as, for plotting::
108108
like *all*
109109

110110
Let's build a *graphtik* computation graph that produces x3 outputs
111-
out of 2 inputs `a` and `b`:
111+
out of 2 inputs `α` and `β`:
112112

113-
- `a x b`
114-
- `a - a x b`
115-
- `|a - a x b| ^ 3`
113+
- `α x β`
114+
- `α - αxβ`
115+
- `|α - αxβ| ^ 3`
116116

117117
..
118118
119119
>>> from graphtik import compose, operation
120120
>>> from operator import mul, sub
121121

122122
>>> @operation(name="abs qubed",
123-
... needs=["a-ab"],
124-
... provides=["|a-ab"])
123+
... needs=["α-α×β"],
124+
... provides=["|α-α×β"])
125125
... def abs_qubed(a):
126126
... return abs(a) ** 3
127127

128128
Compose the ``abspow`` function along the ``mul`` & ``sub`` built-ins
129129
into a computation graph:
130130

131131
>>> graphop = compose("graphop",
132-
... operation(needs=["a", "b"], provides=["ab"])(mul),
133-
... operation(needs=["a", "ab"], provides=["a-ab"])(sub),
132+
... operation(needs=["α", "β"], provides=["α×β"])(mul),
133+
... operation(needs=["α", "α×β"], provides=["α-α×β"])(sub),
134134
... abs_qubed,
135135
... )
136136
>>> graphop
137-
Pipeline('graphop', needs=['a', 'b', 'ab', 'a-ab'],
138-
provides=['ab', 'a-ab', '|a-ab|³'],
137+
Pipeline('graphop', needs=['α', 'β', 'α×β', 'α-α×β'],
138+
provides=['α×β', 'α-α×β', '|α-α×β|³'],
139139
x3 ops: mul, sub, abs qubed)
140140

141-
Run the graph and request all of the outputs:
141+
Run the graph and request all of the outputs
142+
(notice that unicode characters work also as Python identifiers):
142143

143-
>>> graphop(a=2, b=5)
144-
{'a': 2, 'b': 5, 'ab': 10, 'a-ab': -8, '|a-ab|³': 512}
144+
>>> graphop(α=2, β=5)
145+
{'α': 2, 'β': 5, 'α×β': 10, 'α-α×β': -8, '|α-α×β|³': 512}
145146

146147
... or request a subset of outputs:
147148

148-
>>> solution = graphop.compute({'a': 2, 'b': 5}, outputs=["a-ab"])
149+
>>> solution = graphop.compute({'α': 2, 'β': 5}, outputs=["α-α×β"])
149150
>>> solution
150-
{'a-ab': -8}
151+
{'α-α×β': -8}
151152

152153
... and plot the results (if in *jupyter*, no need to create the file):
153154

docs/source/index.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,44 @@ separately with your OS tools)::
8080

8181

8282
Let's build a *graphtik* computation :term:`pipeline` that produces the following
83-
x3 :term:`outputs` out of x2 :term:`inputs` (`a` and `b`):
83+
x3 :term:`outputs` out of x2 :term:`inputs` (`α` and `β`):
8484

8585
.. math::
8686
:label: sample-formula
8787
88-
a \times b
88+
α \times β
8989
90-
a - a \times b
90+
α - α \times β
9191
92-
|a - a \times b| ^ 3
92+
|α - α \times β| ^ 3
9393
9494
..
9595
9696
>>> from graphtik import compose, operation
9797
>>> from operator import mul, sub
9898

9999
>>> @operation(name="abs qubed",
100-
... needs=["a-ab"],
101-
... provides=["|a-ab"])
100+
... needs=["α-α×β"],
101+
... provides=["|α-α×β"])
102102
... def abs_qubed(a):
103103
... return abs(a) ** 3
104104

105+
.. hint::
106+
Notice that *graphtik* has not problem working in unicode chars
107+
for :term:`dependency` names.
108+
105109
Compose the ``abspow`` function along with ``mul`` & ``sub`` built-ins
106110
into a computation :term:`graph`:
107111

108112
>>> graphop = compose("graphop",
109-
... operation(mul, needs=["a", "b"], provides=["ab"]),
110-
... operation(sub, needs=["a", "ab"], provides=["a-ab"]),
113+
... operation(mul, needs=["α", "β"], provides=["α×β"]),
114+
... operation(sub, needs=["α", "α×β"], provides=["α-α×β"]),
111115
... abs_qubed,
112116
... )
113117
>>> graphop
114-
Pipeline('graphop', needs=['a', 'b', 'ab', 'a-ab'],
115-
provides=['ab', 'a-ab', '|a-ab|³'],
116-
x3 ops: mul, sub, abs qubed)
118+
Pipeline('graphop', needs=['α', 'β', 'α×β', 'α-α×β'],
119+
provides=['α×β', 'α-α×β', '|α-α×β|³'],
120+
x3 ops: mul, sub, abs qubed)
117121

118122
You may plot the function graph in a file like this
119123
(if in *jupyter*, no need to specify the file, see :ref:`jupyter_rendering`):
@@ -127,9 +131,9 @@ even ones imported from system modules.
127131

128132
Run the graph-operation and request all of the outputs:
129133

130-
>>> sol = graphop(**{'a': 2, 'b': 5})
134+
>>> sol = graphop(**{'α': 2, 'β': 5})
131135
>>> sol
132-
{'a': 2, 'b': 5, 'ab': 10, 'a-ab': -8, '|a-ab|³': 512}
136+
{'α': 2, 'β': 5, 'α×β': 10, 'α-α×β': -8, '|α-α×β|³': 512}
133137

134138
:term:`Solutions <solution>` are :term:`plottable` as well:
135139

@@ -139,9 +143,9 @@ Run the graph-operation and request all of the outputs:
139143

140144
Run the graph-operation and request a subset of the outputs:
141145

142-
>>> solution = graphop.compute({'a': 2, 'b': 5}, outputs=["a-ab"])
146+
>>> solution = graphop.compute({'α': 2, 'β': 5}, outputs=["α-α×β"])
143147
>>> solution
144-
{'a-ab': -8}
148+
{'α-α×β': -8}
145149

146150
.. graphtik::
147151

docs/source/operations.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,21 @@ the sample formula :eq:`sample-formula` in :ref:`quick-start` section:
245245

246246
>>> # Compose the mul, sub, and abspow operations into a computation graph.
247247
>>> graphop = compose("graphop",
248-
... operation(mul, needs=["a", "b"], provides=["ab"]),
249-
... operation(sub, needs=["a", "ab"], provides=["a-ab"]),
250-
... operation(name="abspow1", needs=["a-ab"], provides=["|a-ab"])
248+
... operation(mul, needs=["α", "β"], provides=["α×β"]),
249+
... operation(sub, needs=["α", "α×β"], provides=["α-α×β"]),
250+
... operation(name="abspow1", needs=["α-α×β"], provides=["|α-α×β"])
251251
... (partial(abspow, p=3))
252252
... )
253253
>>> graphop
254254
Pipeline('graphop',
255-
needs=['a', 'b', 'ab', 'a-ab'],
256-
provides=['ab', 'a-ab', '|a-ab|³'],
255+
needs=['α', 'β', 'α×β', 'α-α×β'],
256+
provides=['α×β', 'α-α×β', '|α-α×β|³'],
257257
x3 ops: mul, sub, abspow1)
258258

259259

260260
- Notice the use of :func:`functools.partial()` to set parameter ``p`` to a constant value.
261-
- And this is done by calling once more the returned "decorator* from :func:`operation()`,
262-
when called without a functions.
261+
- And this is done by calling once more the returned "decorator" from :func:`operation()`,
262+
when called without a function.
263263

264264
The ``needs`` and ``provides`` arguments to the operations in this script define
265265
a computation graph that looks like this:

docs/source/pipelines.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ The call here to ``compose()`` yields a runnable computation graph that looks li
2525

2626
>>> # Compose the mul, sub, and abspow operations into a computation graph.
2727
>>> formula = compose("maths",
28-
... operation(name="mul1", needs=["a", "b"], provides=["ab"])(mul),
29-
... operation(name="sub1", needs=["a", "ab"], provides=["a-ab"])(sub),
30-
... operation(name="abspow1", needs=["a-ab"], provides=["|a-ab"])
28+
... operation(name="mul1", needs=["α", "β"], provides=["α×β"])(mul),
29+
... operation(name="sub1", needs=["α", "α×β"], provides=["α-α×β"])(sub),
30+
... operation(name="abspow1", needs=["α-α×β"], provides=["|α-α×β"])
3131
... (partial(abspow, p=3))
3232
... )
3333

@@ -49,9 +49,9 @@ with keys corresponding to the named :term:`dependencies <dependency>` (`needs`
4949
`provides`):
5050

5151
>>> # Run the graph and request all of the outputs.
52-
>>> out = formula(a=2, b=5)
52+
>>> out = formula(α=2, β=5)
5353
>>> out
54-
{'a': 2, 'b': 5, 'ab': 10, 'a-ab': -8, '|a-ab|³': 512}
54+
{'α': 2, 'β': 5, 'α×β': 10, 'α-α×β': -8, '|α-α×β|³': 512}
5555

5656
You may plot the solution:
5757

@@ -66,11 +66,11 @@ the pipeline, to see which operations will be included in the :term:`graph`
6666
(assuming the graph is solvable at all), based on the given :term:`inputs`/:term:`outputs`
6767
combination:
6868

69-
>>> plan = formula.compile(inputs=['a', 'b'], outputs='a-ab')
69+
>>> plan = formula.compile(inputs=['α', 'β'], outputs='α-α×β')
7070
>>> plan
71-
ExecutionPlan(needs=['a', 'b'],
72-
provides=['a-ab'],
73-
x5 steps: mul1, b, sub1, a, ab)
71+
ExecutionPlan(needs=['α', 'β'],
72+
provides=['α-α×β'],
73+
x5 steps: mul1, β, sub1, α, α×β)
7474
>>> plan.validate() # all fine
7575

7676
.. _pruned-explanations:
@@ -91,15 +91,15 @@ of execution:
9191
But if an impossible combination of `inputs` & `outputs`
9292
is asked, the plan comes out empty:
9393

94-
>>> plan = formula.compile(inputs='a', outputs="a-ab")
94+
>>> plan = formula.compile(inputs='α', outputs="α-α×β")
9595
>>> plan
9696
ExecutionPlan(needs=[], provides=[], x0 steps: )
9797
>>> plan.validate()
9898
Traceback (most recent call last):
9999
ValueError: Unsolvable graph:
100100
+--Network(x8 nodes, x3 ops: mul1, sub1, abspow1)
101-
+--possible inputs: ['a', 'b', 'ab', 'a-ab']
102-
+--possible outputs: ['ab', 'a-ab', '|a-ab|³']
101+
+--possible inputs: ['α', 'β', 'α×β', 'α-α×β']
102+
+--possible outputs: ['α×β', 'α-α×β', '|α-α×β|³']
103103

104104
Evictions: producing a subset of outputs
105105
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -110,9 +110,9 @@ You can use the ``outputs`` parameter to request only a subset.
110110
For example, if ``formula`` is as above:
111111

112112
>>> # Run the graph-operation and request a subset of the outputs.
113-
>>> out = formula.compute({'a': 2, 'b': 5}, outputs="a-ab")
113+
>>> out = formula.compute({'α': 2, 'β': 5}, outputs="α-α×β")
114114
>>> out
115-
{'a-ab': -8}
115+
{'α-α×β': -8}
116116

117117
.. graphtik::
118118

@@ -141,12 +141,12 @@ Short-circuiting a pipeline
141141
You can short-circuit a graph computation, making certain inputs unnecessary,
142142
by providing a value in the graph that is further downstream in the graph than those inputs.
143143
For example, in the graph-operation we've been working with, you could provide
144-
the value of ``a-ab`` to make the inputs ``a`` and ``b`` unnecessary:
144+
the value of ``α-α×β`` to make the inputs ``α`` and ``β`` unnecessary:
145145

146146
>>> # Run the graph-operation and request a subset of the outputs.
147-
>>> out = formula.compute({"a-ab": -8})
147+
>>> out = formula.compute({"α-α×β": -8})
148148
>>> out
149-
{'a-ab': -8, '|a-ab|³': 512}
149+
{'α-α×β': -8, '|α-α×β|³': 512}
150150

151151
.. graphtik::
152152

@@ -172,22 +172,22 @@ unexpectedly, fail with ``Unsolvable graph`` error -- all :term:`dependencies <d
172172
have already values, therefore any operations producing them are :term:`prune`\d out,
173173
till no operation remains:
174174

175-
>>> new_inp = formula.compute({"a": 2, "b": 5})
176-
>>> new_inp["a"] = 20
175+
>>> new_inp = formula.compute({"α": 2, "β": 5})
176+
>>> new_inp["α"] = 20
177177
>>> formula.compute(new_inp)
178178
Traceback (most recent call last):
179179
ValueError: Unsolvable graph:
180180
+--Network(x8 nodes, x3 ops: mul1, sub1, abspow1)
181-
+--possible inputs: ['a', 'b', 'ab', 'a-ab']
182-
+--possible outputs: ['ab', 'a-ab', '|a-ab|³']
181+
+--possible inputs: ['α', 'β', 'α×β', 'α-α×β']
182+
+--possible outputs: ['α×β', 'α-α×β', '|α-α×β|³']
183183

184184

185185
One way to proceed is to avoid recompiling, by executing directly the pre-compiled
186186
:term:`plan`, which will run all the original operations on the new values:
187187

188188
>>> sol = new_inp.plan.execute(new_inp)
189189
>>> sol
190-
{'a': 20, 'b': 5, 'ab': 100, 'a-ab': -80, '|a-ab|³': 512000}
190+
{'α': 20, 'β': 5, 'α×β': 100, 'α-α×β': -80, '|α-α×β|³': 512000}
191191
>>> [op.name for op in sol.executed]
192192
['mul1', 'sub1', 'abspow1']
193193

@@ -198,17 +198,17 @@ One way to proceed is to avoid recompiling, by executing directly the pre-compil
198198
But that trick wouldn't work if the modified value is an inner dependency
199199
of the :term:`graph` -- in that case, the operations upstream would simply overwrite it:
200200

201-
>>> new_inp["a-ab"] = 123
201+
>>> new_inp["α-α×β"] = 123
202202
>>> sol = new_inp.plan.execute(new_inp)
203-
>>> sol["a-ab"] # should have been 123!
203+
>>> sol["α-α×β"] # should have been 123!
204204
-80
205205

206206
You can still do that using the ``recompute_from`` argument of :meth:`.Pipeline.compute()`.
207207
It accepts a string/list of dependencies to :term:`recompute`, *downstream*:
208208

209-
>>> sol = formula.compute(new_inp, recompute_from="a-ab")
209+
>>> sol = formula.compute(new_inp, recompute_from="α-α×β")
210210
>>> sol
211-
{'a': 20, 'b': 5, 'ab': 10, 'a-ab': 123, '|a-ab|³': 1860867}
211+
{'α': 20, 'β': 5, 'α×β': 10, 'α-α×β': 123, '|α-α×β|³': 1860867}
212212
>>> [op.name for op in sol.executed]
213213
['abspow1']
214214

@@ -218,7 +218,7 @@ The old values are retained, although the operations producing them
218218
have been pruned from the plan.
219219

220220
.. Note::
221-
The value of ``a-ab`` is no longer *the correct result* of ``sub1`` operation,
221+
The value of ``α-α×β`` is no longer *the correct result* of ``sub1`` operation,
222222
above it (hover to see ``sub1`` inputs & output).
223223

224224

docs/source/plotting.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ The following directive renders a diagram of its doctest code, beneath it:
442442
>>> from graphtik import compose, operation
443443
>>> addmul = compose(
444444
... "addmul",
445-
... operation(name="add", needs="abc".split(), provides="ab")(lambda a, b, c: (a + b) * c)
445+
... operation(name="add", needs="abc".split(), provides="(a+b)×c")(lambda a, b, c: (a + b) * c)
446446
... )
447447
448448
.. graphtik::
@@ -454,7 +454,7 @@ The following directive renders a diagram of its doctest code, beneath it:
454454

455455
>>> addmul = compose(
456456
... "addmul",
457-
... operation(name="add", needs="abc".split(), provides="ab")(lambda a, b, c: (a + b) * c)
457+
... operation(name="add", needs="abc".split(), provides="(a+b)×c")(lambda a, b, c: (a + b) * c)
458458
... )
459459

460460
which you may :graphtik:`reference <addmul-operation>` with this syntax:
@@ -478,7 +478,7 @@ which you may :graphtik:`reference <addmul-operation>` with this syntax:
478478
>>> from graphtik import compose, operation
479479
>>> addmul = compose(
480480
... "addmul",
481-
... operation(name="add", needs="abc".split(), provides="ab")(lambda a, b, c: (a + b) * c)
481+
... operation(name="add", needs="abc".split(), provides="(a+b)×c")(lambda a, b, c: (a + b) * c)
482482
... )
483483
484484
.. graphtik::

0 commit comments

Comments
 (0)