-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from H-IAAC/memory_storage
Memory storage
- Loading branch information
Showing
22 changed files
with
2,121 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Test inner | ||
|
||
inputs: | ||
os: | ||
required: true | ||
type: string | ||
python-version: | ||
required: true | ||
type: string | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{inputs.python-version}} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{inputs.python-version}} | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
python3 -m pip install pytest | ||
python3 -m pip install pytest-cov | ||
python3 -m pip install -e .[tests,gym,memory_storage] | ||
- name: Tests | ||
shell: bash | ||
run: | | ||
pytest --cov=cst_python --cov-report json | ||
- if: ${{inputs.os == 'ubuntu-latest' && inputs.python-version == '3.12'}} | ||
name: Upload coverage report | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage_report | ||
path: coverage.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 29, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import abc\n", | ||
"import functools\n", | ||
"\n", | ||
"from typing import Self" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 30, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import abc\n", | ||
"import functools\n", | ||
"\n", | ||
"from typing import Self\n", | ||
"\n", | ||
"class LogicalTime(abc.ABC):\n", | ||
"\n", | ||
" @abc.abstractmethod\n", | ||
" def increment(self) -> \"LogicalTime\":\n", | ||
" ...\n", | ||
"\n", | ||
"\n", | ||
" @abc.abstractmethod\n", | ||
" def __str__(self) -> str:\n", | ||
" ...\n", | ||
" \n", | ||
" @classmethod\n", | ||
" @abc.abstractmethod\n", | ||
" def from_str(cls, string:str) -> \"LogicalTime\":\n", | ||
" ...\n", | ||
"\n", | ||
" @classmethod\n", | ||
" @abc.abstractmethod\n", | ||
" def syncronize(cls, time0:Self, time1:Self) -> \"LogicalTime\":\n", | ||
" ...\n", | ||
"\n", | ||
" @abc.abstractmethod\n", | ||
" def __eq__(self, other) -> bool:\n", | ||
" ...\n", | ||
" \n", | ||
" @abc.abstractmethod\n", | ||
" def __lt__(self, other) -> bool:\n", | ||
" ...\n", | ||
"\n", | ||
" @abc.abstractmethod\n", | ||
" def __le__(self, other) -> bool:\n", | ||
" ...\n", | ||
"\n", | ||
" @abc.abstractmethod\n", | ||
" def __gt__(self, other) -> bool:\n", | ||
" ...\n", | ||
"\n", | ||
" @abc.abstractmethod\n", | ||
" def __ge__(self, other) -> bool:\n", | ||
" ...\n", | ||
"\n", | ||
"\n", | ||
"@functools.total_ordering\n", | ||
"class LamportTime(LogicalTime):\n", | ||
" __le__ = object.__lt__\n", | ||
" __gt__ = object.__gt__\n", | ||
" __ge__ = object.__ge__\n", | ||
"\n", | ||
"\n", | ||
" def __init__(self, initial_time:int=0):\n", | ||
" super().__init__()\n", | ||
" self._time = initial_time\n", | ||
"\n", | ||
" def increment(self) -> \"LamportTime\":\n", | ||
" return LamportTime(initial_time=self._time+1)\n", | ||
"\n", | ||
" def __eq__(self, other) -> bool:\n", | ||
" return self._time == other._time\n", | ||
"\n", | ||
" def __lt__(self, other) -> bool:\n", | ||
" return self._time < other._time \n", | ||
"\n", | ||
" def __str__(self) -> str:\n", | ||
" return str(self._time)\n", | ||
"\n", | ||
" @classmethod\n", | ||
" def from_str(cls, string:str) -> \"LamportTime\":\n", | ||
" return LamportTime(int(string))\n", | ||
"\n", | ||
" @classmethod\n", | ||
" def syncronize(cls, time0:Self, time1:Self) -> \"LamportTime\":\n", | ||
" new_time = 0\n", | ||
" if time0 < time1:\n", | ||
" new_time = time1._time\n", | ||
" else:\n", | ||
" new_time = time0._time\n", | ||
"\n", | ||
" new_time += 1\n", | ||
"\n", | ||
" return LamportTime(new_time)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 31, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"time0 = LamportTime()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(time0)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"time1 = time0.increment()\n", | ||
"print(time1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"2\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"time3 = LamportTime.syncronize(time0, time1)\n", | ||
"print(time3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.