inets-kernel 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inets-kernel
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A Jupyter kernel for interaction nets: write a table of rules, draw a net, and watch it reduce
5
5
  Author: N. E. Davis
6
6
  License-Expression: MIT
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3
13
13
  Requires-Python: >=3.10
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
- Requires-Dist: inets>=0.1.0
16
+ Requires-Dist: inets>=0.1.1
17
17
  Requires-Dist: ipykernel>=6
18
18
  Requires-Dist: jupyter_client>=7
19
19
  Provides-Extra: test
@@ -28,14 +28,15 @@ A Jupyter kernel for interaction nets, built on [inets](https://github.com/sigil
28
28
  Write a table of rules, draw a net, and watch it reduce.
29
29
 
30
30
  ```sh
31
- pip install inets-kernel
32
- python -m inets_kernel.install --sys-prefix # into this Python environment; or --user
31
+ pip install inets-kernel jupyterlab # or any other Jupyter front end
32
+ python -m inets_kernel.install --sys-prefix # into this Python environment; or --user, or --prefix PATH
33
33
  jupyter lab
34
34
  ```
35
35
 
36
36
  Choose "Interaction nets" for a notebook. `jupyter kernelspec uninstall inets` removes the
37
- kernel again. The pictures need Graphviz's `dot` program; without it a cell shows the
38
- Graphviz text instead.
37
+ kernel again. The pictures need Graphviz's `dot` program; without it, or if it fails, a cell shows the
38
+ Graphviz text instead. The kernel is registered with the full path of the Python that
39
+ installed it, so run the install step again if that environment moves.
39
40
 
40
41
  ## A cell is one of three things
41
42
 
@@ -47,11 +48,13 @@ con (a b) = dup (era era)
47
48
 
48
49
  `con (a b)` is a node and stands for its principal port. A name that is not an agent is a
49
50
  wire if it occurs twice and a free port if it occurs once. An agent with a parameter takes
50
- it after its name, as in `atom 3`. The net is drawn, reduced by the current schedule, and
51
- drawn again, with why it stopped and what it cost. The kernel starts with the table of the
52
- symmetric interaction combinators (`con`, `dup`, `era`).
51
+ it after its name, as in `atom 3`. Equations are separated by `;` or new lines, and `#`
52
+ starts a comment. The net is drawn, reduced by the current schedule, and drawn again, with
53
+ why it stopped and what it cost. The kernel starts with the table of the symmetric
54
+ interaction combinators (`con`, `dup`, `era`).
53
55
 
54
- **A table.** Lines beginning `agent` or `rule` are added to the current table, in
56
+ **A table.** Lines beginning `agent` or `rule` are added to the current table (which is
57
+ the combinators' at the start: `%system new` gives an empty one), in
55
58
  [the format of `inets`](https://github.com/sigilante/inets/blob/master/src/inets/system.py),
56
59
  and the table is checked:
57
60
 
@@ -69,16 +72,16 @@ rule add (y r) >< zero
69
72
 
70
73
  | Command | Does |
71
74
  |---|---|
72
- | `%system NAME` | start from a bundled table (`combinators`, `ski`, `lazy`), or `new` for none |
75
+ | `%system NAME` | start from a bundled table (`combinators`, which is also what no name gives; `ski`; `lazy`), or `new` for none |
73
76
  | `%table`, `%check`, `%rules` | show the current table; check it; list its rules, marking those that are not local |
74
77
  | `%schedule HOW` | `stack` (the default), `queue`, `random`, `rounds`, or `need PORT`: by need for the free port named PORT (default `out`), in a table with signs |
75
78
  | `%cap N` | stop a run after N interactions (default 10000) |
76
- | `%trace on` / `off` | with `rounds`, draw the net after each round, up to twelve |
79
+ | `%trace on` / `off` | with `rounds`, draw the net after each round, up to twelve rounds (later ones are not drawn); the last drawing stands for what is left |
77
80
  | `%ski TERM [--rounds \| --lazy]` | reduce a term of S, K and I in prefix form, by need unless said |
78
81
  | `%demo` | one term, K I Ω, reduced three ways |
79
82
  | `%help` | this list |
80
83
 
81
- A net of more than 80 nodes is described, not drawn.
84
+ A net of more than 80 nodes, free ports included, is described, not drawn.
82
85
 
83
86
  ## Notebooks
84
87
 
@@ -93,7 +96,7 @@ pip install -e '.[test]' # in kernel/, with inets installed
93
96
  pytest
94
97
  ```
95
98
 
96
- The tests run what a cell means without Jupyter, and one notebook through the kernel
99
+ The tests run what a cell means without Jupyter, and one small notebook through the kernel
97
100
  itself.
98
101
 
99
102
  ## Licence
@@ -4,14 +4,15 @@ A Jupyter kernel for interaction nets, built on [inets](https://github.com/sigil
4
4
  Write a table of rules, draw a net, and watch it reduce.
5
5
 
6
6
  ```sh
7
- pip install inets-kernel
8
- python -m inets_kernel.install --sys-prefix # into this Python environment; or --user
7
+ pip install inets-kernel jupyterlab # or any other Jupyter front end
8
+ python -m inets_kernel.install --sys-prefix # into this Python environment; or --user, or --prefix PATH
9
9
  jupyter lab
10
10
  ```
11
11
 
12
12
  Choose "Interaction nets" for a notebook. `jupyter kernelspec uninstall inets` removes the
13
- kernel again. The pictures need Graphviz's `dot` program; without it a cell shows the
14
- Graphviz text instead.
13
+ kernel again. The pictures need Graphviz's `dot` program; without it, or if it fails, a cell shows the
14
+ Graphviz text instead. The kernel is registered with the full path of the Python that
15
+ installed it, so run the install step again if that environment moves.
15
16
 
16
17
  ## A cell is one of three things
17
18
 
@@ -23,11 +24,13 @@ con (a b) = dup (era era)
23
24
 
24
25
  `con (a b)` is a node and stands for its principal port. A name that is not an agent is a
25
26
  wire if it occurs twice and a free port if it occurs once. An agent with a parameter takes
26
- it after its name, as in `atom 3`. The net is drawn, reduced by the current schedule, and
27
- drawn again, with why it stopped and what it cost. The kernel starts with the table of the
28
- symmetric interaction combinators (`con`, `dup`, `era`).
27
+ it after its name, as in `atom 3`. Equations are separated by `;` or new lines, and `#`
28
+ starts a comment. The net is drawn, reduced by the current schedule, and drawn again, with
29
+ why it stopped and what it cost. The kernel starts with the table of the symmetric
30
+ interaction combinators (`con`, `dup`, `era`).
29
31
 
30
- **A table.** Lines beginning `agent` or `rule` are added to the current table, in
32
+ **A table.** Lines beginning `agent` or `rule` are added to the current table (which is
33
+ the combinators' at the start: `%system new` gives an empty one), in
31
34
  [the format of `inets`](https://github.com/sigilante/inets/blob/master/src/inets/system.py),
32
35
  and the table is checked:
33
36
 
@@ -45,16 +48,16 @@ rule add (y r) >< zero
45
48
 
46
49
  | Command | Does |
47
50
  |---|---|
48
- | `%system NAME` | start from a bundled table (`combinators`, `ski`, `lazy`), or `new` for none |
51
+ | `%system NAME` | start from a bundled table (`combinators`, which is also what no name gives; `ski`; `lazy`), or `new` for none |
49
52
  | `%table`, `%check`, `%rules` | show the current table; check it; list its rules, marking those that are not local |
50
53
  | `%schedule HOW` | `stack` (the default), `queue`, `random`, `rounds`, or `need PORT`: by need for the free port named PORT (default `out`), in a table with signs |
51
54
  | `%cap N` | stop a run after N interactions (default 10000) |
52
- | `%trace on` / `off` | with `rounds`, draw the net after each round, up to twelve |
55
+ | `%trace on` / `off` | with `rounds`, draw the net after each round, up to twelve rounds (later ones are not drawn); the last drawing stands for what is left |
53
56
  | `%ski TERM [--rounds \| --lazy]` | reduce a term of S, K and I in prefix form, by need unless said |
54
57
  | `%demo` | one term, K I Ω, reduced three ways |
55
58
  | `%help` | this list |
56
59
 
57
- A net of more than 80 nodes is described, not drawn.
60
+ A net of more than 80 nodes, free ports included, is described, not drawn.
58
61
 
59
62
  ## Notebooks
60
63
 
@@ -69,7 +72,7 @@ pip install -e '.[test]' # in kernel/, with inets installed
69
72
  pytest
70
73
  ```
71
74
 
72
- The tests run what a cell means without Jupyter, and one notebook through the kernel
75
+ The tests run what a cell means without Jupyter, and one small notebook through the kernel
73
76
  itself.
74
77
 
75
78
  ## Licence
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "inets-kernel"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "A Jupyter kernel for interaction nets: write a table of rules, draw a net, and watch it reduce"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -18,7 +18,7 @@ classifiers = [
18
18
  "Intended Audience :: Education",
19
19
  "Programming Language :: Python :: 3",
20
20
  ]
21
- dependencies = ["inets>=0.1.0", "ipykernel>=6", "jupyter_client>=7"]
21
+ dependencies = ["inets>=0.1.1", "ipykernel>=6", "jupyter_client>=7"]
22
22
 
23
23
  [project.optional-dependencies]
24
24
  test = ["pytest", "nbclient", "nbformat"]
@@ -3,4 +3,4 @@
3
3
  Install the kernel into Jupyter with ``python -m inets_kernel.install``, then choose
4
4
  "Interaction nets" for a notebook. What a cell means is in :mod:`inets_kernel.session`.
5
5
  """
6
- __version__ = "0.1.0"
6
+ __version__ = "0.1.1"
@@ -19,14 +19,16 @@ cost.
19
19
 
20
20
  **Commands**, one to a line, beginning ``%``:
21
21
 
22
- %system NAME start from a bundled table (combinators, ski, lazy), or `new` for none
22
+ %system NAME start from a bundled table (combinators, the default; ski; lazy), or
23
+ `new` for none
23
24
  %table show the current table
24
25
  %check check it
25
26
  %rules list its rules, marking those that are not local
26
27
  %schedule HOW stack (default), queue, random, rounds, or `need PORT`: by need for
27
28
  the free port named PORT (default out), in a table with signs
28
29
  %cap N stop a run after N interactions (default 10000)
29
- %trace on|off with `rounds`, draw the net before each round (off by default)
30
+ %trace on|off with `rounds`, draw the net after each round, up to twelve rounds
31
+ (off by default)
30
32
  %ski TERM [--rounds | --lazy]
31
33
  reduce a term of S, K and I in prefix form, by need unless said
32
34
  %demo one term, K I Ω, reduced three ways
@@ -189,6 +191,8 @@ class Session:
189
191
  seen[name] = port
190
192
 
191
193
  def term(toks):
194
+ if not toks:
195
+ raise CellError("an equation is PORT = PORT, and one side is missing")
192
196
  head = toks.pop(0)
193
197
  if head in ("(", ")", "=", ";"):
194
198
  raise CellError(f"expected a node or a wire, not {head}")
@@ -250,17 +254,18 @@ class Session:
250
254
  return [Output("text", f"{title}: {len(net.kind)} nodes (too many to draw)")]
251
255
  svg = _svg(net.dot(names))
252
256
  if svg is None:
253
- return [Output("text", f"{title} (no `dot` program was found, so here is the Graphviz text):\n{net.dot(names)}")]
257
+ return [Output("text", f"{title} (Graphviz's `dot` program is missing or did not draw it, so here is the Graphviz text):\n{net.dot(names)}")]
254
258
  return [Output("text", title + ":"), Output("svg", svg)]
255
259
 
256
260
  @staticmethod
257
261
  def says(result):
258
- extra = f", in {result.rounds} rounds, the widest of {result.widest}" if result.rounds else ""
262
+ some = lambda n, word: f"{n} {word}" + ("" if n == 1 else "s")
263
+ extra = f", in {some(result.rounds, 'round')}, the widest of {result.widest}" if result.rounds else ""
259
264
  counts = ", ".join(f"{k} {v}" for k, v in sorted(result.counts.items()))
260
265
  why = {"normal": "no active pair is left", "wanted": "the value wanted is there",
261
266
  "interactions": "the cap was reached"}[result.reason]
262
- return (f"stopped: {why} ({result.reason}); {result.interactions} interactions{extra}; "
263
- f"{result.active_left} active pairs left" + (f"; {counts}" if counts else ""))
267
+ return (f"stopped: {why} ({result.reason}); {some(result.interactions, 'interaction')}{extra}; "
268
+ f"{some(result.active_left, 'active pair')} left" + (f"; {counts}" if counts else ""))
264
269
 
265
270
  def net(self, text):
266
271
  if not self.system.agents:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inets-kernel
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A Jupyter kernel for interaction nets: write a table of rules, draw a net, and watch it reduce
5
5
  Author: N. E. Davis
6
6
  License-Expression: MIT
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3
13
13
  Requires-Python: >=3.10
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
- Requires-Dist: inets>=0.1.0
16
+ Requires-Dist: inets>=0.1.1
17
17
  Requires-Dist: ipykernel>=6
18
18
  Requires-Dist: jupyter_client>=7
19
19
  Provides-Extra: test
@@ -28,14 +28,15 @@ A Jupyter kernel for interaction nets, built on [inets](https://github.com/sigil
28
28
  Write a table of rules, draw a net, and watch it reduce.
29
29
 
30
30
  ```sh
31
- pip install inets-kernel
32
- python -m inets_kernel.install --sys-prefix # into this Python environment; or --user
31
+ pip install inets-kernel jupyterlab # or any other Jupyter front end
32
+ python -m inets_kernel.install --sys-prefix # into this Python environment; or --user, or --prefix PATH
33
33
  jupyter lab
34
34
  ```
35
35
 
36
36
  Choose "Interaction nets" for a notebook. `jupyter kernelspec uninstall inets` removes the
37
- kernel again. The pictures need Graphviz's `dot` program; without it a cell shows the
38
- Graphviz text instead.
37
+ kernel again. The pictures need Graphviz's `dot` program; without it, or if it fails, a cell shows the
38
+ Graphviz text instead. The kernel is registered with the full path of the Python that
39
+ installed it, so run the install step again if that environment moves.
39
40
 
40
41
  ## A cell is one of three things
41
42
 
@@ -47,11 +48,13 @@ con (a b) = dup (era era)
47
48
 
48
49
  `con (a b)` is a node and stands for its principal port. A name that is not an agent is a
49
50
  wire if it occurs twice and a free port if it occurs once. An agent with a parameter takes
50
- it after its name, as in `atom 3`. The net is drawn, reduced by the current schedule, and
51
- drawn again, with why it stopped and what it cost. The kernel starts with the table of the
52
- symmetric interaction combinators (`con`, `dup`, `era`).
51
+ it after its name, as in `atom 3`. Equations are separated by `;` or new lines, and `#`
52
+ starts a comment. The net is drawn, reduced by the current schedule, and drawn again, with
53
+ why it stopped and what it cost. The kernel starts with the table of the symmetric
54
+ interaction combinators (`con`, `dup`, `era`).
53
55
 
54
- **A table.** Lines beginning `agent` or `rule` are added to the current table, in
56
+ **A table.** Lines beginning `agent` or `rule` are added to the current table (which is
57
+ the combinators' at the start: `%system new` gives an empty one), in
55
58
  [the format of `inets`](https://github.com/sigilante/inets/blob/master/src/inets/system.py),
56
59
  and the table is checked:
57
60
 
@@ -69,16 +72,16 @@ rule add (y r) >< zero
69
72
 
70
73
  | Command | Does |
71
74
  |---|---|
72
- | `%system NAME` | start from a bundled table (`combinators`, `ski`, `lazy`), or `new` for none |
75
+ | `%system NAME` | start from a bundled table (`combinators`, which is also what no name gives; `ski`; `lazy`), or `new` for none |
73
76
  | `%table`, `%check`, `%rules` | show the current table; check it; list its rules, marking those that are not local |
74
77
  | `%schedule HOW` | `stack` (the default), `queue`, `random`, `rounds`, or `need PORT`: by need for the free port named PORT (default `out`), in a table with signs |
75
78
  | `%cap N` | stop a run after N interactions (default 10000) |
76
- | `%trace on` / `off` | with `rounds`, draw the net after each round, up to twelve |
79
+ | `%trace on` / `off` | with `rounds`, draw the net after each round, up to twelve rounds (later ones are not drawn); the last drawing stands for what is left |
77
80
  | `%ski TERM [--rounds \| --lazy]` | reduce a term of S, K and I in prefix form, by need unless said |
78
81
  | `%demo` | one term, K I Ω, reduced three ways |
79
82
  | `%help` | this list |
80
83
 
81
- A net of more than 80 nodes is described, not drawn.
84
+ A net of more than 80 nodes, free ports included, is described, not drawn.
82
85
 
83
86
  ## Notebooks
84
87
 
@@ -93,7 +96,7 @@ pip install -e '.[test]' # in kernel/, with inets installed
93
96
  pytest
94
97
  ```
95
98
 
96
- The tests run what a cell means without Jupyter, and one notebook through the kernel
99
+ The tests run what a cell means without Jupyter, and one small notebook through the kernel
97
100
  itself.
98
101
 
99
102
  ## Licence
@@ -1,4 +1,4 @@
1
- inets>=0.1.0
1
+ inets>=0.1.1
2
2
  ipykernel>=6
3
3
  jupyter_client>=7
4
4
 
@@ -25,6 +25,16 @@ def test_a_net_is_drawn_reduced_and_drawn_again():
25
25
  assert "Graphviz text" in texts(out)
26
26
 
27
27
 
28
+ def test_without_a_working_dot_the_text_is_shown(monkeypatch, tmp_path):
29
+ fake = tmp_path / "dot"
30
+ fake.write_text("#!/bin/sh\nexit 1\n")
31
+ fake.chmod(0o755)
32
+ monkeypatch.setenv("PATH", str(tmp_path))
33
+ out = Session().execute("con (a b) = dup (era era)")
34
+ assert "svg" not in kinds(out) and "missing or did not draw it" in texts(out)
35
+ assert "graph net {" in texts(out) and "3 interactions" in texts(out)
36
+
37
+
28
38
  def test_free_ports_are_the_names_used_once():
29
39
  s = Session()
30
40
  net, free = s.build("con (a b) = con (c d)")
@@ -68,6 +78,9 @@ def test_a_table_that_cannot_be_read_changes_nothing():
68
78
  ("%system ivm", "no table ivm"),
69
79
  ("%cap many", "whole number"),
70
80
  ("%schedule need\ncon (out b) = era", "needs a table with signs"),
81
+ ("con (a b) =", "one side is missing"),
82
+ ("= era", "expected a node or a wire"),
83
+ ("%system lazy\n%schedule need b\nI = S2 (atom 1 stuck (y S2 (app (x b) I)))", "input is joined to an input"),
71
84
  ])
72
85
  def test_mistakes_are_reported_in_words(cell, phrase):
73
86
  out = Session().execute(cell)
File without changes
File without changes