Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder step 1 #45

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/
ui/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
build/
#build/
develop-eggs/
dist/
downloads/
Expand Down
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM continuumio/miniconda3
LABEL Author, S. Kunath
LABEL version="0.9"

RUN apt-get update && apt-get install -y procps vim
ENV APP_HOME /mtree
WORKDIR $APP_HOME
COPY . $APP_HOME
#COPY ../mTree $APP_HOME/mTree

#---------------- Prepare the envirennment
RUN conda update --name base conda
RUN python /mtree/setup.py develop

# need to fix to use correct profile as well...
# switch here makes startup of the CLI from docker decsktop easier
RUN mv /bin/sh /bin/osh && ln -s /bin/bash /bin/sh

# expose port 5000 for flask service
EXPOSE 5000/tcp

SHELL ["/bin/bash"]
WORKDIR /auctions
ENTRYPOINT ["mTree_developer"]

# basic build:
# docker build -t mtree/mtree:0.9 .

# Pulling:
# docker pull mtree/mtree

# running
# docker run -v /Users/Shared/repos/mTree_auction_examples:/auctions -t -i mtree/mtree:latest
# cd /auctions/sealed_bid_common_value_auction
# mTree_runner -i ./config/basic_simulation.json
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Documentation can be found [here](http://mtree.readthedocs.io/en/latest/).


mTree can be installed using the `pip` installer.

```
Expand Down Expand Up @@ -50,3 +51,20 @@ import mTree
If there are no error messages, the build was successful.
You can now access mTree as you would any other python package.


Thespian Logging notes:

THESPLOG_FILE
THESPLOG_FILE_MAXSIZE
export THESPLOG_FILE="/tmp/thespian.log"
export THESPLOG_THRESHOLD="DEBUG"

export THESPLOG_FILE="./thespian.log"
export THESPLOG_THRESHOLD="DEBUG"

Checking for python processes in powershell:
ps *python*

kill all python processes in powershell:
Stop-Process -Name "python" -Force

61 changes: 56 additions & 5 deletions bin/mTree_developer
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#! /usr/bin/python

from mTree.development.development_server import DevelopmentServer, MTreeController
from mTree.development.development_server import DevelopmentServer#, MTreeController
from mTree.server.admin import admin_area
from mTree.microeconomic_system.agent import Agent
import pyfiglet


import importlib
import inspectf
#import inspectf
import os
import glob

Expand All @@ -22,6 +22,18 @@ print(ascii_banner)




import atexit

# @atexit.register
# def goodbye():
# actor_system = ActorSystemStartup()
# actor_system.shutdown()
# print("mTree finished shutting down")




def import_plugins(plugins_package_directory_path, base_class=None, create_instance=True, filter_abstract=True):


Expand Down Expand Up @@ -72,6 +84,11 @@ def import_plugins(plugins_package_directory_path, base_class=None, create_insta
yield value() if create_instance else value
'''

#os.environ['THESPLOG_THRESHOLD'] = 'DEBUG'
#os.environ['THESPLOG_FILE'] = os.path.join(os.getcwd(), "THESPIAN_OUT.LOG")
#os.environ['THESPLOG_THRESHOLD'] = 'DEBUG'


SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
#SCRIPT_DIR = "/repos/mTree_dev_folder"
plugins_directory_path = os.path.join(SCRIPT_DIR, 'components')
Expand Down Expand Up @@ -106,15 +123,49 @@ plugins_directory_path = os.path.join(SCRIPT_DIR, 'components')
# plugin.foo()


print("mTree is launching")
server = DevelopmentServer()

#mtree_controller = MTreeController()
#mtree_controller.run()



#server.attach_experiment(InformationCascades)
server.run_server()

#server.register_blueprint(admin_area)
#server.list_rules()
#server.run()


# load browser...
import random, threading, webbrowser

port = 5000
url = "http://127.0.0.1:{0}".format(port)

threading.Timer(2, lambda: webbrowser.open(url) ).start()
from mTree.server.actor_system_startup import ActorSystemStartup

# from threading import Thread
# def start_thespian():
# print("STARTING THESPIAN")
# #actor_system = ActorSystemStartup()
# actor_system = ActorSystem('multiprocQueueBase') #,logDefs=logcfg)
# thread = Thread(target=start_thespian)
# thread.start()


#actor_system = ActorSystem('multiprocTCPBase')

print("mTree - Background starting up...")
import sys
from subprocess import Popen, PIPE
background_actor_py = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "mTree", "server", "background_actor_system.py")

process = Popen([sys.executable, background_actor_py]) #, stdout=PIPE, stderr=PIPE)
#stdout, stderr = process.communicate()
#print(stdout)


print("mTree is launching")
server = DevelopmentServer()
server.run_server()
19 changes: 19 additions & 0 deletions bin/mTree_runner
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ ascii_banner = pyfiglet.figlet_format("mTree")
print(ascii_banner)

from mTree.runner.runner import Runner
import time
import sys
from subprocess import Popen, PIPE
import subprocess



def main(argv):
inputfile = ''
Expand All @@ -36,6 +42,19 @@ def main(argv):
inputfile = arg


os.environ['THESPLOG_FILE'] = os.path.join(os.getcwd(), "thespian.log")
os.environ['THESPLOG_THRESHOLD'] = "INFO"

print("mTree - Background starting up...")
background_actor_py = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "mTree", "server", "background_actor_system.py")

#with open(os.devnull, 'w') as DEVNULL:
import subprocess
# creationflags=subprocess.CREATE_NO_WINDOW|subprocess.DETACHED_PROCESS|subprocess.HIGH_PRIORITY_CLASS
process = Popen([sys.executable, background_actor_py]) #, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) #, stdout=PIPE, stderr=PIPE)
#process = subprocess.run([sys.executable, background_actor_py], stdout=DEVNULL, stderr=DEVNULL) #, stdout=PIPE, stderr=PIPE)
print("Background should have started....")

print("mTree Runner")

mtree_runner = Runner(inputfile, multi_simulation=list_simulation)
Expand Down
92 changes: 40 additions & 52 deletions bin/mTree_server
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,50 @@ import sys
# For illustrative purposes.
import tokenize

import logging
import pythonjsonlogger

import sys
from datetime import timedelta
import os
import glob
import time
import traceback
from threading import Thread
from mTree.server.actor_system_startup import ActorSystemStartup

#import signal
#from blessed import Terminal

#term = Terminal()

#def on_resize(sig, action):
# print(f'height={term.height}, width={term.width}')


import signal
from mTree.components import *


#signal.signal(signal.SIGWINCH, on_resize)
import atexit
from thespian.actors import *

# wait for keypress
#term.inkey()

@atexit.register
def goodbye():
ActorSystem('multiprocQueueBase').shutdown()
time.sleep(2)


def exit_gracefully(signum, frame):
# restore the original signal handler as otherwise evil things will happen
# in raw_input when CTRL+C is pressed, and our signal handler is not re-entrant
signal.signal(signal.SIGINT, original_sigint)
ActorSystem('multiprocQueueBase').shutdown()
try:
if raw_input("\nReally quit? (y/n)> ").lower().startswith('y'):
sys.exit(1)

except KeyboardInterrupt:
print("Ok ok, quitting")
sys.exit(1)

# restore the exit gracefully handler here
signal.signal(signal.SIGINT, exit_gracefully)

original_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, exit_gracefully)

ascii_banner = pyfiglet.figlet_format("mTree - Control")
print(ascii_banner)
Expand Down Expand Up @@ -125,57 +146,24 @@ def import_plugins(plugins_package_directory_path, base_class=None, create_insta
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
#SCRIPT_DIR = "/repos/mTree_dev_folder"
plugins_directory_path = os.path.join(SCRIPT_DIR, 'components')
print("PLUGINS DIRECTORY")
print(plugins_directory_path)
print(os.getcwd())
#plugins = import_plugins(plugins_directory_path, base_class=Agent)
plugins = import_plugins(os.path.join(os.getcwd(), 'mes'), base_class=Agent)
print("\t --> ", plugins)

file_path = "/repos/mTree_dev_folder/components/basic_agent.py"
module_name = "mTree.components"
print("aslkfj")
print(file_path)
print(module_name)


####
#spec = importlib.util.spec_from_file_location(module_name, file_path)
#module = importlib.util.module_from_spec(spec)
#spec.loader.exec_module(module)
# Optional; only necessary if you want to be able to import the module
# by name later.
#sys.modules[module_name] = module

print("module list")
#print(sys.modules)

from mTree.components import *
#t = BasicAgent()

#importlib.import_module(".components.base_agent", package='packageser')

#import_plugins("/repos/mTree_dev_folder/components")

#SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
#plugins_directory_path = os.path.join(SCRIPT_DIR, 'plugins')
plugins = import_plugins(plugins_directory_path, base_class=Agent)
print("\t 2 - --> ", plugins)

#for plugin in plugins:
# plugin.foo()

#def start_thespian():
# actor_system = ActorSystemStartup()
# #actor_system = ActorSystem('multiprocQueueBase',logDefs=logcfg)

print("mTree is launching")
server = Server()
#mtree_controller = MTreeController()
#mtree_controller.run()
#thread = Thread(target=start_thespian)
#thread.start()



#server.attach_experiment(InformationCascades)
print("mTree is launching")
server = Server()
server.run_server()
server.register_blueprint(admin_area)
#server.list_rules()
#server.run()
print("thinking")
13 changes: 13 additions & 0 deletions bin/mTree_server_backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

import time
from mTree.server.actor_system_startup import ActorSystemStartup
from thespian.actors import *
import sys

print("mTree Server Backend Starting Up....")

if sys.argv[1] == "startup":
ActorSystem("multiprocTCPBase")
elif sys.argv[1] == "shutdown":
ActorSystem("multiprocTCPBase").shutdown()
Loading