pgmicrograd 0.1.0__py3-none-any.whl
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.
- pgmicrograd/__init__.py +12 -0
- pgmicrograd/neuralNet.py +68 -0
- pgmicrograd/py.typed +0 -0
- pgmicrograd/valueClass.py +117 -0
- pgmicrograd/visualizeGraph.py +43 -0
- pgmicrograd-0.1.0.dist-info/METADATA +205 -0
- pgmicrograd-0.1.0.dist-info/RECORD +9 -0
- pgmicrograd-0.1.0.dist-info/WHEEL +4 -0
- pgmicrograd-0.1.0.dist-info/licenses/LICENSE +21 -0
pgmicrograd/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""pgmicrograd: a scalar autograd engine (Value) and a small neural network library
|
|
2
|
+
(Neuron, Layer, MLP), packaged from github.com/Pushkal-Gupta/micrograd.
|
|
3
|
+
|
|
4
|
+
The drawing helper needs the optional extra: `pip install "pgmicrograd[viz]"`, then
|
|
5
|
+
`from pgmicrograd.visualizeGraph import draw_dot`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pgmicrograd.neuralNet import MLP, Layer, Neuron
|
|
9
|
+
from pgmicrograd.valueClass import Value
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
__all__ = ["MLP", "Layer", "Neuron", "Value", "__version__"]
|
pgmicrograd/neuralNet.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from pgmicrograd.valueClass import Value
|
|
7
|
+
class Neuron:
|
|
8
|
+
|
|
9
|
+
def __init__(self,nin: int) -> None: #nin -> (n)umber of (in)puts
|
|
10
|
+
#Creating nin Value objects as weights with random value between -1 and 1
|
|
11
|
+
self.w = [Value(random.uniform(-1,1)) for _ in range(nin)]
|
|
12
|
+
|
|
13
|
+
#Creating a bias for the neuron
|
|
14
|
+
self.b = Value(random.uniform(-1,1))
|
|
15
|
+
|
|
16
|
+
def __call__(self,x: Any) -> Value:
|
|
17
|
+
# ∑w*x + b
|
|
18
|
+
act = sum((wi*xi for wi,xi in zip(self.w,x)),self.b)
|
|
19
|
+
output = act.tanh()
|
|
20
|
+
return output
|
|
21
|
+
|
|
22
|
+
def parameters(self) -> list[Value]:
|
|
23
|
+
return self.w + [self.b]
|
|
24
|
+
|
|
25
|
+
class Layer:
|
|
26
|
+
|
|
27
|
+
def __init__(self,nin: int,nout: int) -> None: #nout -> (n)umber of (out)puts
|
|
28
|
+
#Creating nout number of neurons per layer
|
|
29
|
+
self.neurons = [Neuron(nin) for _ in range(nout)]
|
|
30
|
+
|
|
31
|
+
def __call__(self,x: Any) -> Any:
|
|
32
|
+
#Initializing the neurons as done earlier
|
|
33
|
+
outputs = [n(x) for n in self.neurons]
|
|
34
|
+
return outputs[0] if len(outputs)==1 else outputs
|
|
35
|
+
|
|
36
|
+
def parameters(self) -> list[Value]:
|
|
37
|
+
params = []
|
|
38
|
+
for neuron in self.neurons:
|
|
39
|
+
ps = neuron.parameters()
|
|
40
|
+
params.extend(ps)
|
|
41
|
+
return params
|
|
42
|
+
|
|
43
|
+
class MLP:
|
|
44
|
+
|
|
45
|
+
def __init__(self,nin: int,nouts: list[int]) -> None: #nouts -> number of outputs per layer(is an array)
|
|
46
|
+
#Adding input layer size also
|
|
47
|
+
sz = [nin]+nouts
|
|
48
|
+
|
|
49
|
+
#Creates layer by layer, taking sizes one by one
|
|
50
|
+
self.layers = [Layer(sz[i],sz[i+1]) for i in range(len(nouts))]
|
|
51
|
+
|
|
52
|
+
def __call__(self,x: Any) -> Any:
|
|
53
|
+
#Calling these layers sequentially
|
|
54
|
+
for layer in self.layers:
|
|
55
|
+
x = layer(x)
|
|
56
|
+
return x
|
|
57
|
+
|
|
58
|
+
def parameters(self) -> list[Value]:
|
|
59
|
+
params = []
|
|
60
|
+
for layer in self.layers:
|
|
61
|
+
ps = layer.parameters()
|
|
62
|
+
params.extend(ps)
|
|
63
|
+
return params
|
|
64
|
+
|
|
65
|
+
#Resetting the gradients otherwise they keep accumulating
|
|
66
|
+
def zero_grad(self) -> None:
|
|
67
|
+
for p in self.parameters():
|
|
68
|
+
p.grad = 0.0
|
pgmicrograd/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
from typing import Any, Callable
|
|
5
|
+
|
|
6
|
+
class Value:
|
|
7
|
+
|
|
8
|
+
def __init__(self,data: Any,_children: tuple[Value, ...] = (), _op: str = '',label: str = '') -> None:
|
|
9
|
+
self.data = data
|
|
10
|
+
self.grad = 0.0
|
|
11
|
+
self._backward: Callable[[], None] = lambda : None
|
|
12
|
+
self._prev = set(_children)
|
|
13
|
+
self._op = _op
|
|
14
|
+
self.label = label
|
|
15
|
+
|
|
16
|
+
def __repr__(self) -> str:
|
|
17
|
+
return f"Value(data = {self.data})"
|
|
18
|
+
|
|
19
|
+
#Adding Operations allowed by micrograd
|
|
20
|
+
|
|
21
|
+
def __add__(self,otherVar: Any) -> Value:
|
|
22
|
+
otherVar = otherVar if isinstance(otherVar,Value) else Value(otherVar)
|
|
23
|
+
output = Value(self.data + otherVar.data, (self,otherVar),'+')
|
|
24
|
+
|
|
25
|
+
def _backward() -> None:
|
|
26
|
+
self.grad += 1.0 * output.grad
|
|
27
|
+
otherVar.grad += 1.0 * output.grad
|
|
28
|
+
output._backward = _backward
|
|
29
|
+
|
|
30
|
+
return output
|
|
31
|
+
|
|
32
|
+
def __radd__(self,otherVar: Any) -> Value: #otherVar + self
|
|
33
|
+
return self + otherVar # type: ignore[no-any-return] # mypy reads Value op Any as Any
|
|
34
|
+
|
|
35
|
+
def __neg__(self) -> Value:
|
|
36
|
+
return self * -1
|
|
37
|
+
|
|
38
|
+
def __sub__(self,otherVar: Any) -> Value:
|
|
39
|
+
return self + (-otherVar) # type: ignore[no-any-return] # mypy reads Value op Any as Any
|
|
40
|
+
|
|
41
|
+
def __rsub__(self,otherVar: Any) -> Value: #OtherVar - self
|
|
42
|
+
return otherVar + (-self) # type: ignore[no-any-return]
|
|
43
|
+
|
|
44
|
+
def __mul__(self,otherVar: Any) -> Value:
|
|
45
|
+
otherVar = otherVar if isinstance(otherVar,Value) else Value(otherVar)
|
|
46
|
+
output = Value(self.data * otherVar.data,(self,otherVar),'*')
|
|
47
|
+
|
|
48
|
+
def _backward() -> None:
|
|
49
|
+
self.grad += otherVar.data * output.grad
|
|
50
|
+
otherVar.grad += self.data * output.grad
|
|
51
|
+
output._backward = _backward
|
|
52
|
+
|
|
53
|
+
return output
|
|
54
|
+
|
|
55
|
+
def __rmul__(self,otherVar: Any) -> Value: #OtherVar * self
|
|
56
|
+
return self * otherVar # type: ignore[no-any-return] # mypy reads Value op Any as Any
|
|
57
|
+
|
|
58
|
+
def __truediv__(self,otherVar: Any) -> Value: # self/otherVar
|
|
59
|
+
return self * (otherVar ** -1) # type: ignore[no-any-return] # mypy reads Value op Any as Any
|
|
60
|
+
|
|
61
|
+
def __rtruediv__(self,otherVar: Any) -> Value: #otherVar/self
|
|
62
|
+
return (self ** -1) * (otherVar) # type: ignore[no-any-return] # mypy reads Value op Any as Any
|
|
63
|
+
|
|
64
|
+
def tanh(self) -> Value:
|
|
65
|
+
x = self.data
|
|
66
|
+
t = ((math.exp(2*x)-1)/(math.exp(2*x)+1))
|
|
67
|
+
output = Value(t,(self,),'tanh')
|
|
68
|
+
|
|
69
|
+
def _backward() -> None:
|
|
70
|
+
self.grad += (1 - (t**2)) * output.grad
|
|
71
|
+
output._backward = _backward
|
|
72
|
+
|
|
73
|
+
return output
|
|
74
|
+
|
|
75
|
+
def relu(self) -> Value:
|
|
76
|
+
out = Value(0 if self.data < 0 else self.data, (self,), 'ReLU')
|
|
77
|
+
|
|
78
|
+
def _backward() -> None:
|
|
79
|
+
self.grad += (out.data > 0) * out.grad
|
|
80
|
+
out._backward = _backward
|
|
81
|
+
|
|
82
|
+
return out
|
|
83
|
+
|
|
84
|
+
def exp(self) -> Value:
|
|
85
|
+
x = self.data
|
|
86
|
+
output = Value(math.exp(x),(self,),'exp')
|
|
87
|
+
|
|
88
|
+
def _backward() -> None:
|
|
89
|
+
self.grad += output.data * output.grad # output.data is just math.exp(x)
|
|
90
|
+
output._backward = _backward
|
|
91
|
+
|
|
92
|
+
return output
|
|
93
|
+
|
|
94
|
+
def __pow__(self,otherVar: Any) -> Value:
|
|
95
|
+
assert isinstance(otherVar,(int,float)) # Ensuring only int or float powers are given
|
|
96
|
+
output = Value(self.data**otherVar,(self,),f"**{otherVar}")
|
|
97
|
+
|
|
98
|
+
def _backward() -> None:
|
|
99
|
+
self.grad += otherVar * (self.data ** (otherVar - 1)) * output.grad
|
|
100
|
+
output._backward = _backward
|
|
101
|
+
|
|
102
|
+
return output
|
|
103
|
+
|
|
104
|
+
def backward(self) -> None:
|
|
105
|
+
self.grad = 1.0
|
|
106
|
+
topo: list[Value] = []
|
|
107
|
+
visited: set[Value] = set()
|
|
108
|
+
def build_topo(v: Value) -> None:
|
|
109
|
+
if v not in visited:
|
|
110
|
+
visited.add(v)
|
|
111
|
+
for child in v._prev:
|
|
112
|
+
build_topo(child)
|
|
113
|
+
topo.append(v)
|
|
114
|
+
build_topo(self)
|
|
115
|
+
|
|
116
|
+
for node in reversed(topo):
|
|
117
|
+
node._backward()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# brew install graphviz
|
|
2
|
+
# pip install graphviz
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from pgmicrograd.valueClass import Value
|
|
9
|
+
from graphviz import Digraph # type: ignore[import-untyped] # graphviz ships no type hints
|
|
10
|
+
|
|
11
|
+
def trace(root: Value) -> tuple[set[Value], set[tuple[Value, Value]]]:
|
|
12
|
+
# builds a set of all nodes and edges in a graph
|
|
13
|
+
nodes: set[Value]
|
|
14
|
+
edges: set[tuple[Value, Value]]
|
|
15
|
+
nodes, edges = set(), set()
|
|
16
|
+
def build(v: Value) -> None:
|
|
17
|
+
if v not in nodes:
|
|
18
|
+
nodes.add(v)
|
|
19
|
+
for child in v._prev:
|
|
20
|
+
edges.add((child, v))
|
|
21
|
+
build(child)
|
|
22
|
+
build(root)
|
|
23
|
+
return nodes, edges
|
|
24
|
+
|
|
25
|
+
def draw_dot(root: Value) -> Any:
|
|
26
|
+
dot = Digraph(format='svg', graph_attr={'rankdir': 'LR'}) # LR = left to right
|
|
27
|
+
|
|
28
|
+
nodes, edges = trace(root)
|
|
29
|
+
for n in nodes:
|
|
30
|
+
uid = str(id(n))
|
|
31
|
+
# for any value in the graph, create a rectangular ('record') node for it
|
|
32
|
+
dot.node(name = uid, label = "{ %s | data %.4f | grad %.4f }" % (n.label, n.data,n.grad), shape='record')
|
|
33
|
+
if n._op:
|
|
34
|
+
# if this value is a result of some operation, create an op node for it
|
|
35
|
+
dot.node(name = uid + n._op, label = n._op)
|
|
36
|
+
# and connect this node to it
|
|
37
|
+
dot.edge(uid + n._op, uid)
|
|
38
|
+
|
|
39
|
+
for n1, n2 in edges:
|
|
40
|
+
# connect n1 to the op node of n2
|
|
41
|
+
dot.edge(str(id(n1)), str(id(n2)) + n2._op)
|
|
42
|
+
|
|
43
|
+
return dot
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pgmicrograd
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A scalar autograd engine (Value) with a small neural network library (Neuron, Layer, MLP).
|
|
5
|
+
Project-URL: Repository, https://github.com/Pushkal-Gupta/pgmicrograd
|
|
6
|
+
Project-URL: Original, https://github.com/Pushkal-Gupta/micrograd
|
|
7
|
+
Project-URL: Changelog, https://github.com/Pushkal-Gupta/pgmicrograd/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Pushkal Gupta
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: autograd,backpropagation,education,micrograd,neural-network
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Provides-Extra: viz
|
|
25
|
+
Requires-Dist: graphviz>=0.20; extra == 'viz'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# pgmicrograd
|
|
29
|
+
|
|
30
|
+
A scalar autograd engine and a small neural network library: `Value` records the
|
|
31
|
+
operations done on it and computes every gradient with `backward()`, and `Neuron`,
|
|
32
|
+
`Layer` and `MLP` build networks out of `Value`s.
|
|
33
|
+
|
|
34
|
+
This is [micrograd by Pushkal Gupta](https://github.com/Pushkal-Gupta/micrograd)
|
|
35
|
+
(commit `a0e1b7a`), packaged so it can be installed with pip. The code is his, copied
|
|
36
|
+
as written: the only changes are the import paths (`from Code.valueClass import Value`
|
|
37
|
+
became `from pgmicrograd.valueClass import Value`) and type hints. A test
|
|
38
|
+
(`tests/test_unchanged.py`) checks that each module, with the hints taken out, has the
|
|
39
|
+
same syntax tree as the original file. The notebooks that explain how the engine is
|
|
40
|
+
built are in the original repository.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
Python 3.10 or newer, no dependencies:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pip install pgmicrograd
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The graph drawing helper needs the Python `graphviz` package, and the Graphviz program
|
|
51
|
+
(`dot`) to render an image:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pip install "pgmicrograd[viz]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Use it
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pgmicrograd import MLP, Value
|
|
61
|
+
|
|
62
|
+
# A neuron by hand: o = tanh(x1*w1 + x2*w2 + b)
|
|
63
|
+
x1, x2 = Value(2.0), Value(0.0)
|
|
64
|
+
w1, w2 = Value(-3.0), Value(1.0)
|
|
65
|
+
b = Value(6.8813735870195432)
|
|
66
|
+
o = (x1 * w1 + x2 * w2 + b).tanh()
|
|
67
|
+
o.backward()
|
|
68
|
+
assert round(o.data, 4) == 0.7071
|
|
69
|
+
assert round(x1.grad, 6) == -1.5 and round(w1.grad, 6) == 1.0
|
|
70
|
+
assert round(x2.grad, 6) == 0.5 and w2.grad == 0.0
|
|
71
|
+
|
|
72
|
+
# A network: 3 inputs, two hidden layers of 4, one output, trained for 50 steps
|
|
73
|
+
import random
|
|
74
|
+
|
|
75
|
+
random.seed(1337)
|
|
76
|
+
model = MLP(3, [4, 4, 1])
|
|
77
|
+
xs = [[2.0, 3.0, -1.0], [3.0, -1.0, 0.5], [0.5, 1.0, 1.0], [1.0, -1.0, -1.0]]
|
|
78
|
+
ys = [1.0, -1.0, -1.0, 1.0]
|
|
79
|
+
for step in range(50):
|
|
80
|
+
ypred = [model(x) for x in xs]
|
|
81
|
+
loss = sum((yout - ygt) ** 2 for ygt, yout in zip(ys, ypred))
|
|
82
|
+
model.zero_grad()
|
|
83
|
+
loss.backward()
|
|
84
|
+
for p in model.parameters():
|
|
85
|
+
p.data += -0.05 * p.grad
|
|
86
|
+
assert len(model.parameters()) == 41
|
|
87
|
+
assert loss.data < 0.02
|
|
88
|
+
assert [round(model(x).data, 2) for x in xs] == [0.95, -0.98, -0.93, 0.93]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`tests/test_readme.py` runs this block, so it stays true.
|
|
92
|
+
|
|
93
|
+
To draw a graph (with the `viz` extra):
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from pgmicrograd import Value
|
|
97
|
+
from pgmicrograd.visualizeGraph import draw_dot
|
|
98
|
+
|
|
99
|
+
a, b = Value(2.0, label="a"), Value(-3.0, label="b")
|
|
100
|
+
o = (a * b).tanh()
|
|
101
|
+
o.backward()
|
|
102
|
+
dot = draw_dot(o) # a graphviz.Digraph
|
|
103
|
+
assert "data -1.0000" in dot.source
|
|
104
|
+
# dot.render("graph") writes graph.svg; that needs the Graphviz program (dot)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## What it does, exactly
|
|
108
|
+
|
|
109
|
+
These follow from the original code and are kept as they are. Each one is checked by
|
|
110
|
+
the recorded calls in the Rust port's repository
|
|
111
|
+
([pgchangeling-micrograd-rs](https://github.com/Pushkal-Gupta/pgchangeling-micrograd-rs)).
|
|
112
|
+
|
|
113
|
+
- `relu()` of a negative number gives the int `0`, not `0.0`. Arithmetic between ints
|
|
114
|
+
stays exact, so `-relu(x)` is `0`, not `-0.0`.
|
|
115
|
+
- `tanh()` is computed as `(exp(2x) - 1) / (exp(2x) + 1)`, so `tanh()` of a number above
|
|
116
|
+
about 354.9 raises `OverflowError`, and of an infinite number gives `nan`.
|
|
117
|
+
- A negative number raised to a fractional power gives a Python complex number.
|
|
118
|
+
- The type check in `**` is an `assert`, so `python -O` skips it.
|
|
119
|
+
- `backward()` walks the graph recursively, so a graph about 1,000 nodes deep raises
|
|
120
|
+
`RecursionError`.
|
|
121
|
+
- A layer of one neuron returns a single `Value`, so an `MLP` with a hidden layer of
|
|
122
|
+
width 1 raises `TypeError` in the next layer.
|
|
123
|
+
- A neuron pairs weights and inputs with `zip`, so an input of the wrong length is cut to
|
|
124
|
+
the shorter of the two without an error.
|
|
125
|
+
- `backward()` adds to gradients that are already there: call `zero_grad()` (or set
|
|
126
|
+
`p.grad = 0.0`) before each step.
|
|
127
|
+
- A node keeps its inputs in a `set`, whose order follows memory addresses, and gradients
|
|
128
|
+
are summed in that order, so the last digits of a gradient can differ from one run to
|
|
129
|
+
the next, and in rare ill-conditioned graphs by more than that. This package keeps the
|
|
130
|
+
original's order; the tests compare such results within a tolerance (below).
|
|
131
|
+
|
|
132
|
+
## How it was tested
|
|
133
|
+
|
|
134
|
+
Before a release, 24 testing techniques run against this package and the original
|
|
135
|
+
repository as the oracle, and all 24 pass (`qa/REPORT.md`; `qa/run.sh` runs them and
|
|
136
|
+
`pgchangeling qa check` gates on them). `qa/run.sh` serves the package to the engine from
|
|
137
|
+
its own virtual environment, `qa/work/port`, which holds graphviz for the drawing calls:
|
|
138
|
+
the engine starts the adapter with a scrubbed environment, so the adapter must not rely on
|
|
139
|
+
the interpreter `uv run` sets up. In short:
|
|
140
|
+
|
|
141
|
+
- The same 31,267 recorded calls that prove the Rust port
|
|
142
|
+
([pgchangeling-micrograd-rs](https://github.com/Pushkal-Gupta/pgchangeling-micrograd-rs))
|
|
143
|
+
replay on the wheel installed in a fresh environment, on Python 3.10 and on the Python
|
|
144
|
+
the engine runs; every one gives the original's answer.
|
|
145
|
+
- Gradients summed in set order (see above) are compared the way the engine compares every
|
|
146
|
+
float, within a relative tolerance of 1e-9 (absolute 1e-12). Every tape call was replayed
|
|
147
|
+
in 4 shifted memory layouts, and each one whose answer moved at all in 20 more: apart
|
|
148
|
+
from the calls set aside below, the widest spread seen was under 1e-13 relative, far
|
|
149
|
+
inside that tolerance. Six calls whose answer
|
|
150
|
+
depends on the layout beyond it, or comes within 50 times of it, are in
|
|
151
|
+
`shadow/layouts/` with every answer the original gave, and the white-box replay accepts
|
|
152
|
+
any of them; the regression and artifact checks do not replay them. Two training runs
|
|
153
|
+
(100 points, 20 and 100 steps) take longer than the engine's 30 seconds per answer on a
|
|
154
|
+
busy machine and are in `shadow/long/`.
|
|
155
|
+
- Generated cases (equivalence classes, boundaries, a decision table, state machines, use
|
|
156
|
+
cases, error guesses, pairwise and orthogonal arrays, fuzzing, defect patterns from
|
|
157
|
+
`LOG.md`) run on the original and on this package, and agree.
|
|
158
|
+
- On the original: every line and branch of the three modules, every condition both ways
|
|
159
|
+
with a unique-cause MC/DC pair, 32 of 36 basis paths and 25 of 28 loop iteration
|
|
160
|
+
classes (the rest infeasible, each with its reason), every def-use pair.
|
|
161
|
+
- Mutation testing of this package's modules: 71 of 73 mutants killed and none
|
|
162
|
+
surviving (2 ran past the time limit).
|
|
163
|
+
- ruff and mypy at a strict setting, with each rule the original's style breaks
|
|
164
|
+
suppressed with its reason; pip-audit on the optional graphviz; a 10 MB input to every
|
|
165
|
+
parameter within the time and memory limits; no stray files in the wheel.
|
|
166
|
+
|
|
167
|
+
### Release testing
|
|
168
|
+
|
|
169
|
+
The 24 techniques, as `qa/report.json` records them on the last run:
|
|
170
|
+
|
|
171
|
+
| Technique | Cases | Result | Metric |
|
|
172
|
+
|---|---|---|---|
|
|
173
|
+
| Equivalence partitioning (`ep`) | 138 | pass | cases matching the original: 138 of 138 |
|
|
174
|
+
| Boundary values (`bva`) | 109 | pass | cases matching the original: 109 of 109 |
|
|
175
|
+
| Decision table (`decision`) | 14 | pass | cases matching the original: 14 of 14 |
|
|
176
|
+
| State transitions (`state`) | 19 | pass | transitions exercised: 7 of 7 |
|
|
177
|
+
| Use cases (`usecase`) | 9 | pass | cases matching the original: 9 of 9 |
|
|
178
|
+
| Error guessing (`errorguess`) | 181 | pass | cases matching the original: 181 of 181 |
|
|
179
|
+
| Pairwise (`pairwise`) | 151 | pass | value pairs covered by the rows: 922 of 922 |
|
|
180
|
+
| Fuzzing (`fuzz`) | 1,200 | pass | cases matching the original: 1,200 of 1,200 |
|
|
181
|
+
| Statement coverage (`statement`) | 33,353 | pass | lines of the ported functions run on the original: 110 of 110 |
|
|
182
|
+
| Branch coverage (`branch`) | 33,353 | pass | branches of the ported functions taken on the original: 24 of 24 |
|
|
183
|
+
| Basis paths (`path`) | 33,353 | pass | basis paths taken (V = cyclomatic complexity per function): 32 of 36 |
|
|
184
|
+
| Condition coverage (`condition`) | 33,353 | pass | condition outcomes seen (each atomic condition true and false): 12 of 12 |
|
|
185
|
+
| Multiple condition (`mcc`) | 33,353 | pass | condition combinations seen (short-circuit vectors, decisions with at most 4 conditions): 12 of 12 |
|
|
186
|
+
| MC/DC (`mcdc`) | 33,353 | pass | conditions shown to independently affect their decision: 6 of 6 |
|
|
187
|
+
| Loop testing (`loop`) | 33,353 | pass | loop iteration classes reached (0, 1, 2, many): 25 of 28 |
|
|
188
|
+
| Data flow (all-uses) (`dataflow`) | 33,353 | pass | def-use pairs exercised (all-uses: c-uses, and p-uses per branch): 116 of 116 |
|
|
189
|
+
| Mutation (`mutation`) | 73 | pass | mutants killed: 71 of 71 |
|
|
190
|
+
| Static analysis (`static`) | 2 | pass | open findings (of all findings): 0 of 59 |
|
|
191
|
+
| Risk matrix (`matrix`) | 6 | pass | functions at the depth their risk requires: 6 of 6 |
|
|
192
|
+
| Targeted regression (`regression`) | 33,347 | pass | calls matching on every tape: 33,347 of 33,347 |
|
|
193
|
+
| Defect patterns (`pattern`) | 178 | pass | cases matching the original: 178 of 178 |
|
|
194
|
+
| Orthogonal arrays (`oat`) | 81 | pass | cases matching the original: 81 of 81 |
|
|
195
|
+
| Installed artifact (`artifact`) | 33,349 | pass | tape calls and examples passing on the installed artifact: 33,349 of 33,349 |
|
|
196
|
+
| Security (`security`) | 38 | pass | security checks passed: 4 of 4 |
|
|
197
|
+
|
|
198
|
+
"On the original" in a white-box metric means the micrograd repository at `a0e1b7a`,
|
|
199
|
+
which this package copies; the basis paths and loop classes not reached are each listed
|
|
200
|
+
with the reason they cannot be (`qa/spec.toml`), and the 2 mutants that ran past the time
|
|
201
|
+
limit count as neither killed nor survived.
|
|
202
|
+
|
|
203
|
+
## Licence
|
|
204
|
+
|
|
205
|
+
MIT, as the original. See [LICENSE](https://github.com/Pushkal-Gupta/pgmicrograd/blob/main/LICENSE): the copyright is Pushkal Gupta's.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pgmicrograd/__init__.py,sha256=DDDrlA7gF1q9n_YqsT9xffT7V5K0xcObcqCWrqLT-t4,475
|
|
2
|
+
pgmicrograd/neuralNet.py,sha256=rhgd08Hco1hz0UIz4dJ4vnzfOCsrG0V8WO1cJB8FW9M,2097
|
|
3
|
+
pgmicrograd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pgmicrograd/valueClass.py,sha256=X71TmYFxGEXEqo8gnXORlfr7Ucc-_ZJZen7Jaspzy_c,3956
|
|
5
|
+
pgmicrograd/visualizeGraph.py,sha256=LR0KtlgzgupvvcoGHNhIrj-CmFmhrqMeN1skIhjQN2g,1473
|
|
6
|
+
pgmicrograd-0.1.0.dist-info/METADATA,sha256=HyBTTBF-xoGSWNYaWmIOEj04bPueamSZFQS2XAFcUT4,10566
|
|
7
|
+
pgmicrograd-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
8
|
+
pgmicrograd-0.1.0.dist-info/licenses/LICENSE,sha256=hSud3Y7OFGSOFwXIFdagfAyRlvZ2nnMxBdBOI2BuH3g,1070
|
|
9
|
+
pgmicrograd-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pushkal Gupta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|