Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #393 from fetchai/develop
Browse files Browse the repository at this point in the history
Release 0.1.7
Totoual authored Oct 7, 2019
2 parents be4d11f + d93d359 commit 7c34af9
Showing 33 changed files with 579 additions and 65 deletions.
27 changes: 27 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -29,3 +29,30 @@ _Put an `x` in the boxes that apply._
## Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

DELETE INCLUSIVE THIS AND BELOW FOR STANDARD PR
------

## Release summary

Version number: [e.g. 1.0.1]

## Release details

Describe in short the main changes with the new release.

## Checklist

_Put an `x` in the boxes that apply._

- [ ] I have read the [CONTRIBUTING](../master/CONTRIBUTING.rst) doc
- [ ] I am making a pull request against the `master` branch (left side), from `develop`
- [ ] Lint and unit tests pass locally
- [ ] I built the documentation and updated it with the latest changes
- [ ] I've added an item in `HISTORY.rst` for this release
- [ ] I bumped the version number in the `tac/__version__.py` file.
- [ ] I bumped the version number in every Docker image of the repo and published it. Also, I built and published them with tag `latest`

## Further comments

Write here any other comment about the release, if any.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -118,6 +118,11 @@ data/*
!data/oef-logs
data/oef-logs/*
!data/.gitkeep
!data/shared
data/shared/*
!data/shared/.gitkeep
scripts/data/*


notebooks/.ipynb_checkpoints

6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -46,3 +46,9 @@ Release History
- Adds versioning to TAC via `version_id`
- Ports `tac` protocol from aea repo
- Multiple small fixes

0.1.7 (2019-10-02)
-------------------

- Improves launcher gui
- Multiple small fixes
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -18,9 +18,23 @@ This repository contains submodules. Clone with recursive strategy:

The controller GUI at http://localhost:8097 provides real time insights.

## Option 2: Step by step:
## Option 2: Launcher GUI:

- [x] You have followed the steps under 'Dependencies' and 'Preliminaries' below
- [x] Follow the steps under 'Dependencies' and 'Preliminaries' below
- [x] Build the sandbox:

cd sandbox && docker-compose build && cd ..

- [x] Enter the virtual environment and start the launcher GUI. Then launch the sandbox with your prefered configs:

pipenv shell
python tac/gui/launcher/app.py

The controller GUI at http://localhost:8097 provides real time insights.

## Option 3: Step by step:

- [x] Follow the steps under 'Dependencies' and 'Preliminaries' below
- [x] In one terminal, build the sandbox and then launch it:

cd sandbox && docker-compose build
@@ -29,7 +43,7 @@ The controller GUI at http://localhost:8097 provides real time insights.
- [x] Optionally, in another terminal, enter the virtual environment and connect a template agent to the sandbox:

pipenv shell
python templates/v1/basic.py --name my_agent --dashboard
python templates/v1/basic.py --name my_agent --dashboard --expected-version-id tac_v1

The sandbox is starting up:
<p align="center">
Empty file added data/shared/.gitkeep
Empty file.
5 changes: 3 additions & 2 deletions sandbox/.env
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ SERVICES_INTERVAL=5
OEF_ADDR=172.28.1.1
OEF_PORT=10000
DATA_OUTPUT_DIR=data
VERSION_ID=1
VERSION_ID=tac_v1
LOWER_BOUND_FACTOR=0
UPPER_BOUND_FACTOR=0
TX_FEE=0.1
@@ -16,4 +16,5 @@ SEED=42
WHITELIST=
REGISTER_AS=both
SEARCH_FOR=both
PENDING_TRANSACTION_TIMEOUT=120
PENDING_TRANSACTION_TIMEOUT=120
SHARED_DIR="./../data/shared"
6 changes: 6 additions & 0 deletions sandbox/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -106,6 +106,12 @@ services:
- "${SEED}"
- "--whitelist-file"
- "${WHITELIST}"
- "--version-id"
- "${VERSION_ID}"
volumes:
- type: bind
source: ${SHARED_DIR}
target: /build/data/shared
networks:
main_net:
ipam:
2 changes: 1 addition & 1 deletion sandbox/playground.py
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
from tac.agents.participant.v1.examples.strategy import BaselineStrategy
from tac.platform.game.base import GameData

CUR_PATH = inspect.getfile(inspect.currentframe())
CUR_PATH = inspect.getfile(inspect.currentframe()) # type: ignore
ROOT_DIR = os.path.join(os.path.dirname(CUR_PATH), "..")


2 changes: 1 addition & 1 deletion sandbox/run_iterated_games.py
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@

from tac.platform.game.stats import GameStats

OUR_DIRECTORY = os.path.dirname(inspect.getfile(inspect.currentframe()))
OUR_DIRECTORY = os.path.dirname(inspect.getfile(inspect.currentframe())) # type: ignore
ROOT_DIR = os.path.join(OUR_DIRECTORY, "..")

logging.basicConfig(level=logging.INFO)
10 changes: 7 additions & 3 deletions scripts/launch.py
Original file line number Diff line number Diff line change
@@ -30,8 +30,9 @@
import docker

from tac.agents.participant.v1.examples.baseline import main as participant_agent_main
from tac.platform.shared_sim_status import register_shared_dir, get_shared_dir

CUR_PATH = inspect.getfile(inspect.currentframe())
CUR_PATH = inspect.getfile(inspect.currentframe()) # type: ignore
ROOT_DIR = os.path.join(os.path.dirname(CUR_PATH), "..")


@@ -59,6 +60,9 @@ def __enter__(self):
self._stop_oef_search_images()
self._build_sandbox()

register_shared_dir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/shared'))
os.environ['SHARED_DIR'] = get_shared_dir()

print("Launching sandbox...")
self.sandbox_process = subprocess.Popen(["docker-compose", "up", "--abort-on-container-exit"],
env=os.environ,
@@ -80,11 +84,11 @@ def wait_for_oef():
":"
], env=os.environ, cwd=ROOT_DIR)

wait_for_oef.wait(30)
wait_for_oef.wait(60)


if __name__ == '__main__':

with Sandbox():
wait_for_oef()
participant_agent_main(name="my_agent", dashboard=True)
participant_agent_main(name="my_agent", dashboard=True, expected_version_id='tac_v1')
9 changes: 7 additions & 2 deletions scripts/launch_alt.py
Original file line number Diff line number Diff line change
@@ -33,9 +33,10 @@

import tac
from tac.platform.oef_health_check import OEFHealthCheck
from tac.platform.shared_sim_status import register_shared_dir, get_shared_dir
from tac.platform.simulation import parse_arguments, build_simulation_parameters

CUR_PATH = inspect.getfile(inspect.currentframe())
CUR_PATH = inspect.getfile(inspect.currentframe()) # type: ignore
ROOT_DIR = os.path.join(os.path.dirname(CUR_PATH), "..")
stack_tracer = importlib.import_module("stack_tracer", package=CUR_PATH)

@@ -83,6 +84,10 @@ def __enter__(self):
self._stop_oef_search_images()
script_path = os.path.join("scripts", "oef", "launch.py")
configuration_file_path = os.path.join("scripts", "oef", "launch_config.json")

register_shared_dir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/shared'))
os.environ['SHARED_DIR'] = get_shared_dir()

print("Launching new OEF Node...")
self.oef_process = subprocess.Popen(["python3", script_path, "-c", configuration_file_path, "--background"],
stdout=subprocess.PIPE, env=os.environ, cwd=ROOT_DIR)
@@ -103,7 +108,7 @@ def _get_image_id(self):


if __name__ == '__main__':
sys.argv += ['--dashboard']
sys.argv += ['--dashboard', '--version-id', 'tac_v1']
args = parse_arguments()
simulation_params = build_simulation_parameters(args)

2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -80,9 +80,11 @@
+ glob.glob("sandbox/*.py")
+ glob.glob("sandbox/*.sh")),
("templates/v1", glob.glob("templates/v1/*.py")),
("scripts/oef", glob.glob("scripts/oef/*.json")),
("simulation/v1", glob.glob("simulation/v1/*")),
("oef_search_pluto_scripts", glob.glob("oef_search_pluto_scripts/*.py") + glob.glob("oef_search_pluto_scripts/*.json"))
],
license=about['__license__'],
)


4 changes: 4 additions & 0 deletions simulation/v1/tac_agent_spawner.py
Original file line number Diff line number Diff line change
@@ -19,10 +19,14 @@
# ------------------------------------------------------------------------------

"""Spawn several TAC agents."""
import os
from tac.platform.shared_sim_status import register_shared_dir

from tac.platform.simulation import parse_arguments, build_simulation_parameters, run

if __name__ == '__main__':
register_shared_dir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../data/shared'))

arguments = parse_arguments()
simulation_parameters = build_simulation_parameters(arguments)
run(simulation_parameters)
2 changes: 1 addition & 1 deletion tac/__init__.py
Original file line number Diff line number Diff line change
@@ -36,5 +36,5 @@
logger.addHandler(handler)
logger.propagate = False

ROOT_DIR = os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), "..")
ROOT_DIR = os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), "..") # type: ignore

2 changes: 1 addition & 1 deletion tac/__version__.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
__title__ = 'tac'
__description__ = 'Trading Agent Competition agents'
__url__ = 'https://github.com/fetchai/agents-tac.git'
__version__ = '0.1.6'
__version__ = '0.1.7'
__author__ = 'Fetch.AI Limited'
__license__ = 'Apache 2.0'
__copyright__ = '2019 Fetch.AI Limited'
16 changes: 14 additions & 2 deletions tac/agents/controller/agent.py
Original file line number Diff line number Diff line change
@@ -20,23 +20,24 @@
# ------------------------------------------------------------------------------

"""This module contains the ControllerAgent."""

import argparse
import datetime
import dateutil.parser
import logging
import pprint
import random
import time
from typing import Optional

import dateutil.parser

from aea.agent import Agent
from aea.channels.oef.connection import OEFMailBox
from aea.mail.base import Envelope

from tac.agents.controller.base.handlers import OEFHandler, GameHandler, AgentMessageDispatcher
from tac.agents.controller.base.tac_parameters import TACParameters
from tac.platform.game.base import GamePhase
from tac.platform.shared_sim_status import set_controller_state, ControllerAgentState
from tac.gui.monitor import Monitor, NullMonitor, VisdomMonitor

if __name__ != "__main__":
@@ -82,6 +83,7 @@ def __init__(self, name: str,
self.last_activity = datetime.datetime.now()

logger.debug("[{}]: Initialized myself as Controller Agent :\n{}".format(self.name, pprint.pformat(vars())))
set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.STARTING)

def act(self) -> None:
"""
@@ -96,10 +98,14 @@ def act(self) -> None:
logger.debug("[{}]: waiting for starting the competition: start_time={}, current_time={}, timedelta ={}s"
.format(self.name, str(self.game_handler.tac_parameters.start_time), str(now), seconds_to_wait))
self.game_handler.competition_start = now + datetime.timedelta(seconds=seconds_to_wait + self.game_handler.tac_parameters.registration_timedelta.seconds)

time.sleep(seconds_to_wait)
logger.debug("[{}]: Register competition with parameters: {}"
.format(self.name, pprint.pformat(self.game_handler.tac_parameters.__dict__)))
self.oef_handler.register_tac()

set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.REGISTRATION_OPEN)

self.game_handler._game_phase = GamePhase.GAME_SETUP
elif self.game_handler.game_phase == GamePhase.GAME_SETUP:
assert self.game_handler.competition_start is not None, "No competition start time set!"
@@ -108,24 +114,30 @@ def act(self) -> None:
logger.debug("[{}]: Checking if we can start the competition.".format(self.name))
min_nb_agents = self.game_handler.tac_parameters.min_nb_agents
nb_reg_agents = len(self.game_handler.registered_agents)

set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.RUNNING)

if nb_reg_agents >= min_nb_agents:
logger.debug("[{}]: Start competition. Registered agents: {}, minimum number of agents: {}."
.format(self.name, nb_reg_agents, min_nb_agents))
self.game_handler.start_competition()
else:
logger.debug("[{}]: Not enough agents to start TAC. Registered agents: {}, minimum number of agents: {}."
.format(self.name, nb_reg_agents, min_nb_agents))
set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.STOPPING_UNSUFFICIENT_AGENTS)
self.stop()
return
elif self.game_handler.game_phase == GamePhase.GAME:
current_time = datetime.datetime.now()
inactivity_duration = current_time - self.last_activity
if inactivity_duration > self.game_handler.tac_parameters.inactivity_timedelta:
logger.debug("[{}]: Inactivity timeout expired. Terminating...".format(self.name))
set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.FINISHED_INACTIVITY)
self.stop()
return
elif current_time > self.game_handler.tac_parameters.end_time:
logger.debug("[{}]: Competition timeout expired. Terminating...".format(self.name))
set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.FINISHED_GAME_TIMEOUT)
self.stop()
return

2 changes: 1 addition & 1 deletion tac/gui/dashboards/agent.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
from tac.gui.dashboards.helpers import generate_html_table_from_dict, escape_html
from tac.platform.game.base import Transaction

CUR_PATH = inspect.getfile(inspect.currentframe())
CUR_PATH = inspect.getfile(inspect.currentframe()) # type: ignore
CUR_DIR = os.path.dirname(CUR_PATH)
ROOT_PATH = os.path.join(CUR_DIR, "..", "..")

2 changes: 1 addition & 1 deletion tac/gui/dashboards/base.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@

from visdom import Visdom

CUR_PATH = inspect.getfile(inspect.currentframe())
CUR_PATH = inspect.getfile(inspect.currentframe()) # type: ignore
CUR_DIR = os.path.dirname(CUR_PATH)


5 changes: 4 additions & 1 deletion tac/gui/launcher/api/__init__.py
Original file line number Diff line number Diff line change
@@ -17,12 +17,13 @@
# limitations under the License.
#
# ------------------------------------------------------------------------------
"""Register the resources with flask and set up the shared status file."""

"""Define the REST APIs for the launcher app."""
from flask_restful import Api

from .resources.sandboxes import SandboxList, Sandbox
from .resources.agents import Agent
from tac.platform.shared_sim_status import clear_temp_dir


def create_api(app):
@@ -32,3 +33,5 @@ def create_api(app):
api.add_resource(SandboxList, "/sandboxes")
api.add_resource(Sandbox, "/sandboxes/<int:sandbox_id>")
api.add_resource(Agent, "/agent")

clear_temp_dir()
Loading

0 comments on commit 7c34af9

Please sign in to comment.