Skip to content

Commit

Permalink
Merge pull request #5 from H-IAAC/memory_storage
Browse files Browse the repository at this point in the history
Memory storage
  • Loading branch information
EltonCN authored Dec 9, 2024
2 parents bff545e + f91088d commit 459faa5
Show file tree
Hide file tree
Showing 22 changed files with 2,121 additions and 210 deletions.
66 changes: 38 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,56 @@ on:
branches: [ dev, main ]

jobs:
test:

runs-on: ${{ matrix.os }}
test-linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12"]

services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps port 6379 on service container to the host
- 6379:6379

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
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]
- uses: actions/checkout@v2

- uses: ./.github/workflows/test_inner
with:
os: ubuntu-latest
python-version: ${{ matrix.python-version }}

- name: Tests
run: |
pytest --cov=cst_python --cov-report json
shell: bash

- if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'}}
name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage_report
path: coverage.json
test-windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2

- uses: ./.github/workflows/test_inner
with:
os: windows-latest
python-version: ${{ matrix.python-version }}

coverage-check:
runs-on: ubuntu-latest
needs:
- test
- test-linux

steps:
- uses: actions/checkout@v2
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test_inner/action.yml
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

199 changes: 199 additions & 0 deletions dev/LogicalTime.ipynb
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
}
Loading

0 comments on commit 459faa5

Please sign in to comment.