Skip to content

Commit da354f0

Browse files
committed
docs and compatibility
1 parent fde45c7 commit da354f0

21 files changed

+217
-62
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
# LODA Python Module
1+
# LODA Python
22

3-
This Python module contains an implementation of the [LODA Language](https://loda-lang.org/). You can use it to read, write and evaluate LODA programs to integer sequences, and to use machine learning to find new programs.
3+
This Python package contains an implementation of the [LODA Language](https://loda-lang.org/):
4+
an assembly language and computational model for finding integer sequence programs.
5+
6+
This Python package allows you to read and write LODA programs, to evaluate
7+
them to integer sequences, to search for matches in the
8+
[OEIS](https://www.oeis.org/) database,
9+
and to use machine learning tools from [Tensorflow](https://www.tensorflow.org/)
10+
to find new integer sequence programs.
411

512
## Getting Started
613

7-
Install the dependencies for the LODA Python module:
14+
You need Python 3.7 or higher. To install the dependencies for LODA, run these commands:
815

916
```bash
1017
python3 -m venv env
@@ -18,4 +25,4 @@ To execute the tests, run the following command:
1825
nose2 tests -v
1926
```
2027

21-
Check out [sample.py](sample.py) and the [documentation](https://loda-lang.org/loda-python/) to find out how to use the LODA Python module.
28+
Check out [sample.py](sample.py) and the [documentation](https://loda-lang.org/loda-python/) to find out how to use the LODA Python package.

fibonacci.asm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; A000045: Fibonacci numbers.
2+
mov $3,1
3+
lpb $0
4+
sub $0,1
5+
mov $2,$1
6+
add $1,$3
7+
mov $3,$2
8+
lpe
9+
mov $0,$1

loda/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
"""Python implementation of the [LODA Language](https://loda-lang.org/):
2-
an assembly language and computational model for finding integer sequence programs.
1+
"""
2+
Python implementation of the [LODA Language](https://loda-lang.org/):
3+
an assembly language and computational model for integer sequences.
34
4-
This Python package allows you to read and write LODA programs, to evaluate
5-
them to integer sequences, to search for matches in the
6-
[On-Line Encyclopedia of Integer Sequences®](https://www.oeis.org/) (OEIS®),
7-
and to use machine learning from [Tensorflow](https://www.tensorflow.org/)
8-
to find new integer sequence programs.
5+
.. include:: ./documentation.md
96
"""

loda/documentation.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
This Python package allows you to read and write LODA programs, to evaluate
2+
them to integer sequences, to search for matches in the
3+
[OEIS](https://www.oeis.org/) database,
4+
and to use machine learning from [Tensorflow](https://www.tensorflow.org/)
5+
to generate new integer sequence programs.
6+
7+
## Installation
8+
9+
You need Python 3.7 or higher. To install the dependencies for LODA, run these commands:
10+
11+
```bash
12+
python3 -m venv env
13+
source env/bin/activate
14+
pip install -r requirements.txt
15+
```
16+
17+
## Getting Started
18+
19+
LODA programs are stored in `*.asm` files. Below you can find the example program `fibonacci.asm` which
20+
computes the Fibonacci numbers. For a comprehensive overview of the language, see the [LODA Language Specification](https://loda-lang.org/spec/).
21+
22+
```asm
23+
; A000045: Fibonacci numbers.
24+
mov $3,1
25+
lpb $0
26+
sub $0,1
27+
mov $2,$1
28+
add $1,$3
29+
mov $3,$2
30+
lpe
31+
mov $0,$1
32+
```
33+
34+
Check out the [sub-modules](#header-submodules) for working with LODA programs.
35+
36+
## Development
37+
38+
To execute the tests, run the following command:
39+
40+
```bash
41+
nose2 tests -v
42+
```

loda/lang/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
"""LODA Language core. Model and (de-)serialization of programs.
1+
"""
2+
Load and save programs.
3+
4+
This module contains the in-memory representation of LODA programs. You can use it to load and save programs,
5+
and to inspect and manipulate their structure programmatically. You can load a program from an `*.asm` file
6+
as follows:
7+
8+
>>> from loda.lang import Program
9+
>>>
10+
>>> with open("fibonacci.asm", "r") as file:
11+
>>> program = Program(file.read())
12+
>>> print(program)
13+
14+
To save it, just write the string representation of the program to another file.
15+
To inspect and manipulate programs, see the `loda.lang.program.Program` class.
216
"""
317

418
from .operand import Operand

loda/lang/operand.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22

3+
"""Operand model and serialization."""
4+
35
from enum import Enum
46

57

68
class Operand:
7-
"""Operand model and (de-)serialization.
8-
9+
"""
910
Operands consist of two members: `type` (enum) and `value` (int).
1011
The operand's type can be either `CONSTANT`, `DIRECT` memory access,
1112
or `INDIRECT` memory access. Constants are plain integers. Direct

loda/lang/operation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
22

3+
"""Operation model and serialization."""
4+
35
from enum import Enum
46
from .operand import Operand
57

68

79
class Operation:
8-
"""Operation model and (de-)serialization.
9-
10+
"""
1011
Operations have the following structure: `<type> <target>,<source> ; <comment>`
1112
where the operation type is an enum consisting of three-letter operation names, and
1213
target and source are `loda.lang.operand.Operand`s. Depending on their type,

loda/lang/program.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# -*- coding: utf-8 -*-
22

3+
"""Program model and serialization."""
4+
35
from .operation import Operation
46

57

68
class Program:
7-
"""Program model and (de-)serialization.
9+
"""
10+
Programs are essentially a list of `Operation`s.
811
912
>>> # Constructing programs from operations:
1013
>>> p1 = Program()
@@ -21,7 +24,7 @@ class Program:
2124
div $0,$2
2225
"""
2326

24-
operations: list[Operation]
27+
operations: list
2528
"""Operations of this program."""
2629

2730
def __init__(self, program_str=None):

loda/ml/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
"""Machine learning integration for LODA using Tensorflow/Keras."""
1+
"""
2+
Machine learning integration.
3+
"""

loda/ml/keras.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class Model(tf.keras.Model):
1111

12-
def __init__(self, vocabulary: list[str],
12+
def __init__(self, vocabulary: list,
1313
embedding_dim: int = 256, num_rnn_units: int = 1024):
1414

1515
super().__init__(self)
@@ -75,10 +75,10 @@ def __init__(self, model: Model, temperature: float = 1.0):
7575
dense_shape=[model.get_vocab_size()])
7676
self.prediction_mask = tf.sparse.to_dense(sparse_mask)
7777

78-
def ids_to_tokens_str(self, ids) -> list[str]:
78+
def ids_to_tokens_str(self, ids) -> list:
7979
return [t.numpy().decode("utf-8") for t in self.model.ids_to_tokens(ids)]
8080

81-
def ids_to_programs(self, ids) -> list[Program]:
81+
def ids_to_programs(self, ids) -> list:
8282
return util.split_program(util.tokens_to_program(self.ids_to_tokens_str(ids)))
8383

8484
def program_to_input_ids(self, program: Program, num_lanes: int = 1):

0 commit comments

Comments
 (0)