mirror of
https://github.com/gsi-upm/soil
synced 2025-09-14 12:12:21 +00:00
Compare commits
5 Commits
0.20.0
...
0.20.2.pos
Author | SHA1 | Date | |
---|---|---|---|
|
cab9a3440b | ||
|
db505da49c | ||
|
8eb8eb16eb | ||
|
3fc5ca8c08 | ||
|
c02e6ea2e8 |
@@ -1,9 +1,10 @@
|
||||
stages:
|
||||
- test
|
||||
- build
|
||||
- publish
|
||||
- check_published
|
||||
|
||||
build:
|
||||
stage: build
|
||||
docker:
|
||||
stage: publish
|
||||
image:
|
||||
name: gcr.io/kaniko-project/executor:debug
|
||||
entrypoint: [""]
|
||||
@@ -16,13 +17,34 @@ build:
|
||||
only:
|
||||
- tags
|
||||
|
||||
|
||||
test:
|
||||
except:
|
||||
- tags # Avoid running tests for tags, because they are already run for the branch
|
||||
tags:
|
||||
- docker
|
||||
image: python:3.7
|
||||
stage: test
|
||||
script:
|
||||
- python setup.py test
|
||||
- pip install -r requirements.txt -r test-requirements.txt
|
||||
- python setup.py test
|
||||
|
||||
push_pypi:
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
image: python:3.7
|
||||
stage: publish
|
||||
script:
|
||||
- echo $CI_COMMIT_TAG > soil/VERSION
|
||||
- pip install twine
|
||||
- python setup.py sdist bdist_wheel
|
||||
- TWINE_PASSWORD=$PYPI_PASSWORD TWINE_USERNAME=$PYPI_USERNAME python -m twine upload dist/*
|
||||
|
||||
check_pypi:
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
image: python:3.7
|
||||
stage: check_published
|
||||
script:
|
||||
- pip install soil==$CI_COMMIT_TAG
|
||||
|
@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.20.2]
|
||||
### Fixed
|
||||
* CI/CD testing issues
|
||||
## [0.20.1]
|
||||
### Fixed
|
||||
* Agents would run another step after dying.
|
||||
## [0.20.0]
|
||||
### Added
|
||||
* Integration with MESA
|
||||
|
@@ -4,20 +4,34 @@ Example of a fully programmatic simulation, without definition files.
|
||||
'''
|
||||
from soil import Simulation, agents
|
||||
from soil.time import Delta
|
||||
from networkx import Graph
|
||||
from random import expovariate
|
||||
import logging
|
||||
|
||||
|
||||
|
||||
class MyAgent(agents.FSM):
|
||||
'''
|
||||
An agent that first does a ping
|
||||
'''
|
||||
|
||||
defaults = {'pong_counts': 2}
|
||||
|
||||
@agents.default_state
|
||||
@agents.state
|
||||
def neutral(self):
|
||||
self.info('I am running')
|
||||
def ping(self):
|
||||
self.info('Ping')
|
||||
return self.pong, Delta(expovariate(1/16))
|
||||
|
||||
@agents.state
|
||||
def pong(self):
|
||||
self.info('Pong')
|
||||
self.pong_counts -= 1
|
||||
self.info(str(self.pong_counts))
|
||||
if self.pong_counts < 1:
|
||||
return self.die()
|
||||
return None, Delta(expovariate(1/16))
|
||||
|
||||
|
||||
s = Simulation(name='Programmatic',
|
||||
network_agents=[{'agent_type': MyAgent, 'id': 0}],
|
||||
topology={'nodes': [{'id': 0}], 'links': []},
|
||||
|
@@ -1 +1 @@
|
||||
0.20.0
|
||||
0.20.1
|
@@ -20,6 +20,10 @@ def as_node(agent):
|
||||
|
||||
IGNORED_FIELDS = ('model', 'logger')
|
||||
|
||||
|
||||
class DeadAgent(Exception):
|
||||
pass
|
||||
|
||||
class BaseAgent(Agent):
|
||||
"""
|
||||
A special Agent that keeps track of its state history.
|
||||
@@ -129,13 +133,14 @@ class BaseAgent(Agent):
|
||||
return None
|
||||
|
||||
def die(self, remove=False):
|
||||
self.info(f'agent {self.unique_id} is dying')
|
||||
self.alive = False
|
||||
if remove:
|
||||
self.remove_node(self.id)
|
||||
|
||||
def step(self):
|
||||
if not self.alive:
|
||||
return time.When('inf')
|
||||
raise DeadAgent(self.unique_id)
|
||||
return super().step() or time.Delta(self.interval)
|
||||
|
||||
def log(self, message, *args, level=logging.INFO, **kwargs):
|
||||
@@ -300,7 +305,10 @@ class FSM(NetworkAgent, metaclass=MetaFSM):
|
||||
|
||||
def step(self):
|
||||
self.debug(f'Agent {self.unique_id} @ state {self.state_id}')
|
||||
interval = super().step()
|
||||
try:
|
||||
interval = super().step()
|
||||
except DeadAgent:
|
||||
return time.When('inf')
|
||||
if 'id' not in self.state:
|
||||
# if 'id' in self.state:
|
||||
# self.set_state(self.state['id'])
|
||||
|
Reference in New Issue
Block a user