コード例 #1
0
ファイル: TapiocaBot.py プロジェクト: h3nnn4n/h3nnn4n-sc2-ai
    def __init__(self, verbose=False, visual_debug=False):
        self.verbose = verbose
        self.visual_debug = visual_debug

        ipdb.launch_ipdb_on_exception()

        # Control Stuff
        self.researched_warpgate = False  # Remove me later

        # Managers and controllers
        self.worker_controller = WorkerController(bot=self,
                                                  verbose=self.verbose)
        self.army_controller = ArmyController(bot=self, verbose=self.verbose)
        self.scouting_controller = ScoutingController(bot=self,
                                                      verbose=self.verbose)
        self.upgrades_controller = UpgradesController(bot=self,
                                                      verbose=self.verbose)
        self.robotics_facility_controller = RoboticsFacilitiyController(
            bot=self,
            verbose=self.verbose,
        )
        self.gateway_controller = GatewayController(
            bot=self, verbose=self.verbose, auto_morph_to_warpgate=True)
        self.building_controller = BuildingController(bot=self,
                                                      verbose=self.verbose)
        self.event_manager = EventManager()
        self.build_order_controller = BuildOrderController(
            verbose=self.verbose, bot=self)
        self.coordinator = Coordinator(bot=self,
                                       verbose=self.verbose,
                                       build_order='three_gate_blink_all_in')

        self.order_queue = []
コード例 #2
0
ファイル: testing_helpers.py プロジェクト: ianzhou1/anonrep
def create_coordinator(port=None):
    if port is None:
        port = get_free_port()
    co = Coordinator('localhost', port)
    config.COORDINATOR_ADDR = co.addr
    Thread(target=co.run, daemon=True).start()
    return co
コード例 #3
0
def test4():
    D, radius = 1, 0.005
    edge_lengths = Real3(1, 1, 1)

    with species_attributes():
        A1 | A2 | B1 | B2 | B3 | C1 | C2 | C3 | {
            "D": str(D),
            "radius": str(radius)
        }

    with reaction_rules():
        A1 + B1_ > B2 | 0.04483455086786913 > A1 + B1 | 1.35
        B2 > A2 + B1 | 1.5
        A2 + B1_ > B3 | 0.09299017957780264 > A2 + B1 | 1.73
        B3 > A3 + B1 | 15.0

        A3 + C1 > C2 | 0.04483455086786913 > A3 + C1 | 1.35
        C2 > A2 + C1 | 1.5
        A2 + C1 > C3 | 0.09299017957780264 > A2 + C1 | 1.73
        C3 > A1 + C1 | 15.0

    m = get_model()

    w1 = meso.MesoscopicWorld(edge_lengths, Integer3(9, 9, 9))
    w1.bind_to(m)
    sim1 = meso.MesoscopicSimulator(w1)

    w2 = spatiocyte.SpatiocyteWorld(edge_lengths, radius)
    w2.bind_to(m)
    sim2 = spatiocyte.SpatiocyteSimulator(w2)
    # w2 = egfrd.EGFRDWorld(edge_lengths, Integer3(4, 4, 4))
    # w2.bind_to(m)
    # sim2 = egfrd.EGFRDSimulator(w2)

    owner = Coordinator()
    ev1 = simulator_event(sim1)
    ev1.add(('A1', 'A2', 'A3'))
    ev1.add(('C1', 'C2', 'C3'))
    ev1.borrow('B1', 'B1_')
    owner.add_event(ev1)
    owner.add_event(simulator_event(sim2)).add(('B1', 'B2', 'B3'))
    owner.set_value(Species("A1"), 120)
    owner.set_value(Species("B1"), 30)
    owner.set_value(Species("C1"), 30)
    owner.initialize()

    logger = Logger(owner,
                    ("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"))
    logger.add("B1_", w1)

    logger.log()
    while owner.step(1):
        if owner.last_event.event_kind == EventKind.REACTION_EVENT:
            logger.log()
    logger.log()

    logger.savefig()
    logger.savetxt()
コード例 #4
0
def main():
    """
    Configure starting_gate and run races
    """

    config = Config("/home/pi/config/starting_gate.json")
    display = Display(config)
    device = DeviceIO()
    coordinator = Coordinator(config)
    socket = None
    poller = None
    global finish_line_connected #pylint: disable=global-statement

    reset_starting_gate(config)

    # Main loop to iterate over successive race configurations
    while True:

        # Reset aborted state
        global race_aborted #pylint: disable=global-statement
        race_aborted = False

        # De-register with race coordinator.
        coordinator.deregister()

        # Display the main menu and wait for race selection
        display.wait_menu()

        device.push_key_handlers(key_pressed, key_pressed, key_pressed,
                                 deviceio.default_joystick_handler)

        # Establish Bluetooth connection to Finish Line
        if not finish_line_connected:
            display.wait_finish_line()
            socket = connect_to_finish_line(config.finish_line_name)
            poller = select.poll()
            poller.register(socket, READ_ONLY)

        # Register with the race coordinator if multi-track race selected in menu
        if config.multi_track:
            display.wait_remote_registration()
            coordinator.register()
            display.remote_registration_done()

        while not race_aborted:
            try:
                run_race(config, coordinator, display, socket, poller)
            except bluetooth.btcommon.BluetoothError:
                print("Bluetooth exception caught.  Reconnecting...")
                finish_line_connected = False
                socket = connect_to_finish_line("FinishLine")
            except Exception as exc: #pylint: disable=broad-except
                print("Unexpected exception caught", exc)
                traceback.print_exc()
                break # Go back to main menu on unhandled exception within a race

        device.pop_key_handlers()
コード例 #5
0
def test3():
    D, radius = 1, 0.005
    edge_lengths = Real3(1, 1, 1)

    with species_attributes():
        A1 | A2 | B1 | B2 | B3 | {"D": str(D), "radius": str(radius)}

    with reaction_rules():
        A1 == A2 | (1.0, 1.0)
        B1 == B2 | (1.0, 1.0)

        A2 + B2_ > B3 | 1.0 / 30.0
        B3 > A2 + B2 | 1.0

    m = get_model()

    w1 = gillespie.GillespieWorld(edge_lengths)
    w1.bind_to(m)
    sim1 = gillespie.GillespieSimulator(w1)

    # w2 = meso.MesoscopicWorld(edge_lengths, Integer3(9, 9, 9))
    # w2.bind_to(m)
    # sim2 = meso.MesoscopicSimulator(w2)
    # w2 = spatiocyte.SpatiocyteWorld(edge_lengths, radius)
    # w2.bind_to(m)
    # sim2 = spatiocyte.SpatiocyteSimulator(w2)
    # w2 = egfrd.EGFRDWorld(edge_lengths, Integer3(4, 4, 4))
    # w2.bind_to(m)
    # sim2 = egfrd.EGFRDSimulator(w2)
    w2 = ode.ODEWorld(edge_lengths)
    w2.bind_to(m)
    sim2 = ode.ODESimulator(w2)
    sim2.set_dt(0.01)

    owner = Coordinator()
    ev1 = simulator_event(sim1)
    ev1.add(('A1', 'A2'))
    ev1.borrow('B2', 'B2_')
    owner.add_event(ev1)
    owner.add_event(simulator_event(sim2)).add(('B1', 'B2', 'B3'))
    owner.set_value(Species("A1"), 60)
    owner.set_value(Species("B1"), 60)
    owner.initialize()

    logger = Logger(owner, ("A1", "A2", "B1", "B2", "B3"))
    logger.add("B2_", w1)

    logger.log()
    while owner.step(10):
        # while owner.step(50):
        if owner.last_event.event_kind == EventKind.REACTION_EVENT:
            logger.log()
    logger.log()

    logger.savefig()
    logger.savetxt()
コード例 #6
0
 def setUp(self):
     print("test setup begins")
     self.coordinator = Coordinator(3)
     self.cohort1 = Cohort(COHORT1_ID, COHORT1_PORT)
     self.cohort2 = Cohort(COHORT2_ID, COHORT2_PORT)
     self.cohort3 = Cohort(COHORT3_ID, COHORT3_PORT)
     self.coordinator.start()
     self.coordinator.channel.queue_purge(queue = 'coordinatorQueue')
     self.coordinator.channel.queue_purge(queue='queue0')
     self.coordinator.channel.queue_purge(queue='queue1')
     self.coordinator.channel.queue_purge(queue='queue2')
     print("test setup successful")
コード例 #7
0
ファイル: main.py プロジェクト: eugypalu/kademlia-Simulator
def main():
    n = input("Inserisci il numero di nodi ")
    m = input("inserisci il numero di bit")
    c = Coordinator(int(n),int(m)) #istanzia la classe coordinator
    ng = NxGra() #istanzia la classe nxGraph
    g = Graph() #istanzia la classe graph
    c.main() 
    ng.mainGraph()
    ng.snapshotGraph()
    g.inDegreeBarplot()
    g.outDegreeBarplot()
    g.clusteringBarplot(ng.getClusteringCoeff())
コード例 #8
0
def main():
    # argument parser to specify hyperparameters
    parser = argparse.ArgumentParser()
    parser.add_argument("--train", help="training run", action="store_true")
    parser.add_argument("--test", help="test run", action="store_true")
    parser.add_argument("--network_type",
                        default="mlp",
                        help="""type of the policy network ["mlp", "gru"]""",
                        type=str)
    parser.add_argument(
        "--num_agents",
        default=8,
        help="number of environments and agents running in parallel",
        type=int)
    parser.add_argument(
        "--num_steps",
        default=32,
        help="number of steps on each environment for every update",
        type=int)
    parser.add_argument("--environment",
                        default="LunarLanderContinuous-v2",
                        help="gym environment type",
                        type=str)
    args = parser.parse_args()

    # Launch tensorboard
    tb = program.TensorBoard()
    tb.configure(argv=[None, '--logdir', './logs'])
    tb.launch()

    # Initialize ray
    ray.init(memory=1024 * 512 * 200, object_store_memory=1024 * 1024 * 1000)

    if args.train:
        # start training run with given hyperparameters
        coord = Coordinator(num_agents=args.num_agents,
                            network=args.network_type,
                            env_name=args.environment,
                            num_steps=args.num_steps)
        coord.train()

    if args.test:
        # start run with latest model checkpoint
        from test import test_run
        test_run(network=args.network_type, environment=args.environment)

    ray.shutdown()
コード例 #9
0
def test4():
    D, radius = 1, 0.005
    edge_lengths = Real3(1, 1, 1)

    with species_attributes():
        A1 | A2 | B1 | B2 | {"D": str(D), "radius": str(radius)}

    with reaction_rules():
        A1 + B1_ > B2 | 0.04483455086786913 > B1 + A2 | 1.35
        B2 > B1 + A1 | 1.5

    m = get_model()

    w1 = meso.MesoscopicWorld(edge_lengths, Integer3(9, 9, 9))
    w1.bind_to(m)
    sim1 = meso.MesoscopicSimulator(w1)

    # w2 = spatiocyte.SpatiocyteWorld(edge_lengths, radius)
    # w2.bind_to(m)
    # sim2 = spatiocyte.SpatiocyteSimulator(w2)
    w2 = egfrd.EGFRDWorld(edge_lengths, Integer3(4, 4, 4))
    w2.bind_to(m)
    sim2 = egfrd.EGFRDSimulator(w2)

    w1.add_molecules(Species("A1"), 120)
    w2.add_molecules(Species("B1"), 60)

    owner = Coordinator()
    ev1 = simulator_event(sim1)
    ev1.add(('A1', 'A2'))
    ev1.borrow('B1', 'B1_')
    owner.add_event(ev1)
    owner.add_event(simulator_event(sim2)).add(('B1', 'B2'))
    owner.initialize()

    logger = Logger(owner, ("A1", "A2", "B1", "B2"))
    logger.add("B1_", w1)

    logger.log()
    while owner.step(1):
        if owner.last_event.event_kind == EventKind.REACTION_EVENT:
            logger.log()
    logger.log()

    logger.savefig()
    logger.savetxt()
コード例 #10
0
def main():

    coordinator = Coordinator(GENERATOR, MODULO, "127.0.0.1", 5003)
    thread1 = threading.Thread(target=coordinator.listenAndCoordinate)
    thread1.daemon = True
    thread1.start()

    while True:
        try:
            command = input("> ")
        except KeyboardInterrupt:
            print("quitting")
            quit()

        args = command.split()

        if args[0] == "next_round":
            coordinator.startNextRound()
コード例 #11
0
def test5():
    edge_lengths = Real3(1, 1, 1)

    with reaction_rules():
        A1 == A2 | (1.0, 1.0)
        B1 == B2 | (1.0, 1.0)
        A1 == B1 | (1.0, 1.0)

        A2 + B2_ > C1 | 1.0 / 30.0
        C1 > A2 + B2 | 1.0

    m = get_model()

    w1 = meso.MesoscopicWorld(edge_lengths, Integer3(3, 3, 3))
    w1.bind_to(m)
    sim1 = meso.MesoscopicSimulator(w1)

    w2 = meso.MesoscopicWorld(edge_lengths, Integer3(9, 9, 9))
    w2.bind_to(m)
    sim2 = meso.MesoscopicSimulator(w2)

    owner = Coordinator()
    ev1 = simulator_event(sim1)
    ev1.add(('A1', 'A2', 'C1'))
    ev1.borrow('B2', 'B2_')
    owner.add_event(ev1)
    owner.add_event(simulator_event(sim2)).add(('B1', 'B2'))
    owner.set_value(Species("A1"), 120)
    # owner.set_value(Species("A1"), 60)
    # owner.set_value(Species("B1"), 60)
    owner.initialize()

    logger = Logger(owner, ("A1", "A2", "C1", "B1", "B2"))
    logger.add('B2_', w1)

    logger.log()
    while owner.step(5):
        if owner.last_event.event_kind == EventKind.REACTION_EVENT:
            logger.log()

    logger.savefig()
    logger.savetxt()
コード例 #12
0
ファイル: hypertune.py プロジェクト: antaressgzz/SURF_2018
def train_one(tuning_params):
    start = time.time()
    if FEE:
        config = tuned_config
    else:
        config = get_config(FEE)
    config = construct_config(config, tuning_params)
    ################### To Do ################
    # coo = Coordinator(config, [name, ''])
    # coo.restore_price_predictor('-5.28-80000-')
    coo = Coordinator(config, 'search')
    ##########################################
    val_rewards, tr_rs = coo.evaluate()
    loss = -1 * np.mean(np.sort(val_rewards)[-int(len(val_rewards) * 0.4):])
    eval_time = time.time() - start
    log_training(config, val_rewards, tr_rs, loss, eval_time)
    result = {
        'loss': loss,
        'status': STATUS_OK,
        'val': val_rewards,
        'train': tr_rs,
    }
    return result
コード例 #13
0
ファイル: app.py プロジェクト: jhoogstraat/EdgeAI
def main(args):
    global coordinator

    if args.detector == 'pycoral':
        print("Loading PyCoral Detector")
        from detectors.pycoral_detector import PyCoralDetector as Detector
    elif args.detector == 'tf2':
        print("Loading TF2 Detector")
        from detectors.tf2_detector import TF2Detector as Detector
    elif args.detector == 'ms-tflite':
        print("Loading MS TFLite-Detector")
        from detectors.ms_detector import MSTFLiteDetector as Detector
    elif args.detector == 'ms-tf2':
        print("Loading MS TF-Detector")
        from detectors.ms_detector import MSTFDetector as Detector

    camera = Camera(videoSource=args.video)
    detector = Detector(args.model)
    usecase = CheckSetUseCase(detector.labels)
    coordinator = Coordinator(camera, detector, usecase)

    print('[INFO] Starting server at http://localhost:5000')
    socketio.run(app=app, host='0.0.0.0', port=5000)
コード例 #14
0
def test2():
    edge_lengths = Real3(1, 1, 1)

    with reaction_rules():
        A1 == A2 | (1.0, 1.0)
        E1 == E2 | (1.0, 1.0)
        A1 == E1 | (1.0, 1.0)

    m = get_model()

    w1 = gillespie.GillespieWorld(edge_lengths)
    w1.bind_to(m)
    sim1 = gillespie.GillespieSimulator(w1)

    w2 = ode.ODEWorld(edge_lengths)
    w2.bind_to(m)
    sim2 = ode.ODESimulator(w2)

    owner = Coordinator()
    owner.add_event(simulator_event(sim1)).add(('A1', 'A2'))
    owner.add_event(ODEEvent(sim2, 0.01)).add(('E1', 'E2'))
    owner.set_value(Species("A1"), 120)
    # owner.set_value(Species("A1"), 60)
    # owner.set_value(Species("E1"), 60)
    owner.initialize()

    logger = Logger(owner, ("A1", "A2", "E1", "E2"))
    logger.add("A1", w2)

    logger.log()
    while owner.step(50):
        if owner.last_event.event_kind == EventKind.REACTION_EVENT:
            logger.log()

    logger.savefig()
    logger.savetxt()
コード例 #15
0
ファイル: main.py プロジェクト: antaressgzz/SURF_2018
import os
import sys

current_path = os.getcwd()
sys.path.append(current_path)
from hypertune import start_commander, start_workers
from coordinator import Coordinator
from config import mode, number_workers, tuned_config, fix_random_seed
import numpy as np

if fix_random_seed:
    np.random.seed(123)

# %matplotlib inline

if mode == 'parallel':
    start_commander()
    workers = start_workers(number_workers)
else:
    model = Coordinator(tuned_config, '2900')
    #################### to do ####################
    # model = Coordinator(tuned_config, '-5.28')
    # model.restore_price_predictor('-5.28-80000-')
    ##############################################
    model.train('single', True)
    model.back_test('test', 2500, True)
コード例 #16
0
def test1():
    D, radius = 1, 0.005
    edge_lengths = Real3(1, 1, 1)

    with species_attributes():
        A1 | A2 | B1 | B2 | C1 | C2 | D1 | D2 | E1 | E2 | {
            "D": str(D),
            "radius": str(radius)
        }

    with reaction_rules():
        A1 == A2 | (1.0, 1.0)
        B1 == B2 | (1.0, 1.0)
        C1 == C2 | (1.0, 1.0)
        D1 == D2 | (1.0, 1.0)
        E1 == E2 | (1.0, 1.0)

        A1 == B1 | (1.0, 1.0)
        A1 == C1 | (1.0, 1.0)
        A1 == D1 | (1.0, 1.0)
        A1 == E1 | (1.0, 1.0)
        B1 == C1 | (1.0, 1.0)
        B1 == D1 | (1.0, 1.0)
        B1 == E1 | (1.0, 1.0)
        C1 == D1 | (1.0, 1.0)
        C1 == E1 | (1.0, 1.0)
        D1 == E1 | (1.0, 1.0)

    m = get_model()

    w1 = gillespie.GillespieWorld(edge_lengths)
    w1.bind_to(m)
    sim1 = gillespie.GillespieSimulator(w1)

    w2 = meso.MesoscopicWorld(edge_lengths, Integer3(9, 9, 9))
    w2.bind_to(m)
    sim2 = meso.MesoscopicSimulator(w2)

    w3 = spatiocyte.SpatiocyteWorld(edge_lengths, radius)
    w3.bind_to(m)
    sim3 = spatiocyte.SpatiocyteSimulator(w3)

    w4 = egfrd.EGFRDWorld(edge_lengths, Integer3(4, 4, 4))
    w4.bind_to(m)
    sim4 = egfrd.EGFRDSimulator(m, w4)

    w5 = ode.ODEWorld(edge_lengths)
    w5.bind_to(m)
    sim5 = ode.ODESimulator(w5)
    sim5.set_dt(0.01)

    owner = Coordinator()
    owner.add_event(simulator_event(sim1)).add(('A1', 'A2'))
    owner.add_event(simulator_event(sim2)).add(('B1', 'B2'))
    owner.add_event(simulator_event(sim3)).add(('C1', 'C2'))
    owner.add_event(simulator_event(sim4)).add(('D1', 'D2'))
    owner.add_event(simulator_event(sim5)).add(('E1', 'E2'))

    owner.set_value(Species("A1"), 300)
    # owner.set_value(Species("A1"), 60)
    # owner.set_value(Species("B1"), 60)
    # owner.set_value(Species("C1"), 60)
    # owner.set_value(Species("D1"), 60)
    # owner.set_value(Species("E1"), 60)

    owner.initialize()

    logger = Logger(
        owner, ("A1", "A2", "B1", "B2", "C1", "C2", "D1", "D2", "E1", "E2"))

    logger.log()
    while owner.step(3):
        if owner.last_event.event_kind == EventKind.REACTION_EVENT:
            logger.log()
    logger.log()

    logger.savefig()
    logger.savetxt()
コード例 #17
0
import slack
import specificvars
import re
import threading
import queue
from time import sleep

slack_events_adapter = SlackEventAdapter(specificvars.slack_signing_secret,
                                         endpoint="/slack/events")
webclient = slack.WebClient(token=specificvars.bot_user_token)
rtmclient = slack.RTMClient(token=specificvars.bot_user_token)

respond_msg_queue = queue.Queue()
output_queue = queue.Queue()

coord = Coordinator(output_queue)


@slack_events_adapter.on("app_mention")
def app_mention(event_data):
    event = event_data['event']
    text = event['text']
    clean_text = re.sub(r'<@.*>', '', text)
    event['text'] = clean_text
    event['dubious'] = False
    respond_msg_queue.put(event)


@slack.RTMClient.run_on(event='message')
def channel_msg(**payload):
    data = payload['data']
コード例 #18
0
from mpi4py import MPI
from coordinator import Coordinator
from worker import Worker
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
proc = comm.Get_size()
status = MPI.Status()
#print(rank, flush=True)
#print(proc, flush=True)
coordinator_rank = 0
tag_map = 1
tag_reduce = 2
tag_end = 3
json_path = "backlinks.json"
if rank == coordinator_rank:
	#print("boss found", flush=True)
	coord = Coordinator(json_path, tag_map, tag_reduce, tag_end, rank, comm, status)
	#print("boss starts to work", flush=True)
	coord.do_job()
else:
	worker = Worker(json_path, tag_map, tag_reduce, tag_end, rank, comm, status)	
	worker.do_job()

MPI.Finalize()	
コード例 #19
0
from coordinator import Coordinator
from failsafe_coordinator import FailSafeCoordinator
from participant import Participant

choice = int(
    input('''
1 : Main Coordinator.
2 : FailSafeCoordinator.
3 : Participant.
'''))

try:
    if choice == 1:
        num_of_participants = int(input('Enter number of participants : '))
        failsafe_address = input('Enter Failsafe ip address : ')
        main_coordinator = Coordinator(num_of_participants, failsafe_address)
        asyncio.run(main_coordinator.start_connections())

    if choice == 2:
        num_of_participants = int(input('Enter number of participants : '))
        failsafe_coordinator = FailSafeCoordinator(num_of_participants)
        asyncio.run(failsafe_coordinator.start_connections())

    if choice == 3:
        main_address_host = input('Enter Main Coordinator ip address :  ')
        failsafe_address = input('Enter Failsafe Coordinator ip address : ')
        participant = Participant(main_address_host, failsafe_address)
        asyncio.run(participant.perform_actions())

except KeyboardInterrupt:
    if choice == 1:
コード例 #20
0
ファイル: main.py プロジェクト: holtet/hub75-weather
    ief = IndoorEnvironmentFetcher(dataCollection)
    ief.run()
    ief_job = scheduler.add_job(ief.run,
                                trigger='interval',
                                seconds=2,
                                id=IEF_JOB_ID)
    joblist[IEF_JOB_ID] = Job(ief_job, 2, 2)

    nf = NewsFetcher(dataCollection, config)
    nf.run()
    nf_job = scheduler.add_job(nf.run,
                               trigger='interval',
                               seconds=3600,
                               id=NF_JOB_ID)
    joblist[NF_JOB_ID] = Job(nf_job, 3600, 600)

    scheduler.add_listener(
        Listener(joblist).job_done_listener,
        EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)

    scheduler.start()

    #    stopFlag = Event()

    cthread = Coordinator(dataCollection, config, scheduler)
    cthread.start()

    lthread = LedDisplayThread(dataCollection)
    lthread.start()
コード例 #21
0
        type='string',
        action='store',
        dest='filename',
        default='params.json',
        help='filename to set parameters; default parameters are in params.json'
    )

    (options, args) = parser.parse_args(sys.argv[1:])

    params = get_params(options.filename)

    # Setup logging directory
    shutil.rmtree('./logs')
    os.mkdir('./logs')

    c = Coordinator(params)

    nodes = np.empty(params['num_nodes'], dtype=Node)

    if 'topology' in params and 'locations' in params:
        num_nodes, locations, G = get_topology(params['locations'],
                                               params['topology'])
        if num_nodes != params['num_nodes']:
            print('Invalid number of nodes provided')
            sys.exit()
        # generate num_nodes nodes
        for node_id in range(0, num_nodes):
            n = Node(node_id, params['fork_choice_rule'],
                     params['transaction_schedule'], params['max_block_size'],
                     locations[node_id])
            nodes[node_id] = n
コード例 #22
0
ファイル: master.py プロジェクト: skandhgupta/rain
def create_logger(level=logging.INFO):
    logging.basicConfig(level=logging.INFO,
                        stream=sys.stderr,
                        format='%(asctime)s %(levelname)s %(message)s')
    return logging.getLogger()


if __name__ == '__main__':

    opt = option.parse(__doc__, ['port=', 'interface='], ['port'],
                       {'interface': ''})
    log = create_logger()

    log.info('hello')

    # TODO
    # pre-fork hub
    # http://groups.google.com/group/gevent/browse_thread/thread/44b756976698503b

    env = {'rain.log': log, 'rain.coordinator': Coordinator(log)}
    server = wsgi_httpserver.create(opt['interface'], opt['port'], log, env)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print
        log.info('recd KeyboardInterrupt; shutting down')
        server.stop()

    log.info('bye')
コード例 #23
0
ファイル: database.py プロジェクト: dhyani-001/CCS
    if password == "dept123":
        d = Department()
        name = input("Enter name of the department")
        project = input("Enter the name of the project")
        deptid = input("Enter the Department ID")
        d.add_department(name, project, deptid)

    else:
        print("You have Entered Wrong Password")

elif key == "3":
    password = input("Enter the password for Updating Database of coordinator")

    if password == "cod123":
        c = Coordinator()
        name = input("Enter Name of the Coordinator")
        cid = input("Enter your Coordinator Id")
        c.add_yourself(name, cid)

    else:
        print("Wrong Password Entered")

elif key == "4":
    password = input("Enter the Faculty Password")

    if password == "fac123":
        work = input(
            "Which type of faculty you want to enter 1:Permanent Faculty \n 2:Visiting Faculty"
        )
        f = Faculty()
コード例 #24
0
# Prepare Loop
# ====
loop = asyncio.get_event_loop()

# Create agents
# ====
# coordinator agents are the entities that can become coordinators.
etcd_config = EtcdConfig(etcd_ip, etcd_port)

# coordinator agent 1
uuid = "1"
coordinator_configuration = CoordinatorConfiguration(
    uuid, group_prefix, workers_subprefix, global_task_prefix,
    coordinator_subprefix, worker_queue_subprefix, coordinator_time_to_renew)
agent_one = Coordinator(coordinator_configuration, etcd_config, loop, logger)

# coordinator agent 2
uuid = "2"
coordinator_configuration = CoordinatorConfiguration(
    uuid, group_prefix, workers_subprefix, global_task_prefix,
    coordinator_subprefix, worker_queue_subprefix, coordinator_time_to_renew)
agent_two = Coordinator(coordinator_configuration, etcd_config, loop, logger)


def operation_on_task(etcd, task_id, operation):
    key = global_task_prefix + "." + task_id
    if operation == "delete":
        etcd.delete(key)
    elif operation == "put":
        etcd.put(key, task_id)
コード例 #25
0
        providers += [SSLVisionDataProvider()]

    if not NO_REFBOX:
        providers += [RefboxDataProvider()]

    if not NO_RADIO:
        providers += [Comms(HOME_TEAM)]
        if CONTROL_BOTH_TEAMS:
            providers += [Comms(AWAY_TEAM, True)]

    providers += [Strategy(HOME_TEAM, HOME_STRATEGY)]

    if CONTROL_BOTH_TEAMS:
        providers += [Strategy(AWAY_TEAM, AWAY_STRATEGY)]

    providers += [Visualizer()]

    # Pass the providers to the coordinator
    c = Coordinator(providers)

    # Setup the exit handler
    def stop_it(signum, frame):
        c.stop_game()
    signal.signal(signal.SIGINT, stop_it)

    # Start the game
    c.start_game()

    # Exit once game is over
    sys.exit()
コード例 #26
0
import sys

from ratelimitedapi import RateLimitedApi
from coordinator import Coordinator

if __name__ == "__main__":
    # Working dir needs to have config.json file at the root.  Coordinator will create subfolders for storing the
    # backtest results.
    working_dir = Path(r"path/to/data/dir")
    with (working_dir / "config.json").open() as f:
        config = json.load(f)

    loglevel = config.get("loglevel", logging.INFO)
    logging.basicConfig(  # configures root logger, more succinct than wiring up handlers on object directly
        level=loglevel,
        format="%(asctime)s %(name)s [%(threadName)s] [%(levelname)-5.5s]: %(message)s",
        stream=sys.stdout
    )
    logger = logging.getLogger()  # root logger
    logger.info(str(config))

    try:
        mod = importlib.import_module(config["module"])
        testset = getattr(mod, config["testset"])
        api = RateLimitedApi(config["user_id"], config["token"], debug=False)
        coordinator = Coordinator(testset, api, working_dir, config["project_name"], config["concurrency"])
        asyncio.run(coordinator.run(), debug=True)
    except Exception as e:
        logger.error("Unhandled error", exc_info=e)
        sys.exit(1)
コード例 #27
0
                  network_topology=network_config,
                  learning_rate_decay_step=int(total_training_step / 30),
                  update_tar_period=1000,
                  epsilon=1,
                  epsilon_Min=0.1,
                  epsilon_decay_period=total_training_step * replay_period / 5,
                  memory_size=500 * batch_size,
                  batch_size=batch_size,
                  history_length=window_length,
                  log_freq=50,
                  save_period=save_period,
                  save=save,
                  name=name,
                  GPU=GPU)

coo = Coordinator(agent)

env = PortfolioEnv(df_train,
                   steps=256,
                   trading_cost=0.00007,
                   window_length=window_length,
                   scale=False,
                   random_reset=False)

ob = env.reset()
for i in range(5):
    print(coo.action_values(ob))
    ob, a, r, ob_ = env.step(np.ones(5))

coo.train(env,
          total_training_step=total_training_step,
コード例 #28
0
        agent.hyper_parameters = best_coordinator.agents[i].hyper_parameters
        new_learning_rate = best_coordinator.agents[i].hyper_parameters['learning_rate'] * random.uniform(0.8, 1.2)
        agent.network.optimizer.learning_rate.assign(new_learning_rate)
        agent.hyper_parameters['learning_rate'] = new_learning_rate
        agent.hyper_parameters['entropy_coefficient'] = best_coordinator.agents[i].hyper_parameters[
                                                            'entropy_coefficient'] * random.uniform(0.8, 1.2)
        agent.hyper_parameters['critic_coefficient'] = best_coordinator.agents[i].hyper_parameters[
                                                           'critic_coefficient'] * random.uniform(0.8, 1.2)


coordinators = []
f = open('{}-PBT.csv'.format('Checkers-v0'), 'a')
f.write('Coordinator ID,Episode Number,Agent ID,Agent Reward,Agent Learning Rate,Agent Entropy, Agent Critic '
        'Coefficient,Total Reward\n')
f.close()
for i in range(16):
    coordinators.append(Coordinator('Checkers-v0',
                                    {'learning_rate': round(random.uniform(0.000025, 0.005), 4),
                                     'entropy_coefficient': round(random.uniform(0.00001, 0.001), 4),
                                     'critic_coefficient': round(random.uniform(0.1, 0.5), 4),
                                     'discount_factor': 0.99, 'unroll_length': 50,
                                     'minions_num': 5},
                                    coordinator_id=i))
for j in range(1, 1000):
    for coordinator in coordinators:
        coordinator.play()
        print(f'Coordinator {coordinator.id} Finished Episode {j}')
    if j % 200 == 0:
        print('***{} Episodes Have Passed. Initiating Exploitation***'.format(j))
        exploit(coordinators)
コード例 #29
0
    parser.set_defaults(kill=False)

    args, command_flags = parser.parse_known_args()

    notify = args.notify
    runs = args.runs
    name = args.name
    kill = args.kill
    pool = args.pool

    if kill != False:
        if kill == None:
            kill_all()
        else:
            kill_job(str(kill))
        sys.exit(0)

    command = " ".join(args.command + command_flags)

    print("Running remote command: {}".format(command))

    # Starting the coordinator
    coordinator = Coordinator(command=command,
                              times=runs,
                              name=name,
                              notify=notify,
                              pool=Pool(pool))

    coordinator.onDone(lambda: onDone(coordinator))
    coordinator.run()
コード例 #30
0
        test_x = make_image_scale(test_x)
        train_y = make_onehot(train_y)
        test_y = make_onehot(test_y)

    # Set model parameters
    model_parameter = ModelDNN(train_x=train_x,
                               train_y=train_y,
                               test_x=test_x,
                               test_y=test_y,
                               codec=codec,
                               psgd_type=arg.psgd,
                               server_codec=arg.server_codec,
                               learn_rate=arg.lr,
                               epoches=arg.epochs,
                               optimizer_type=arg.op)

    core = Coordinator(model_parameter, logger)

    with open(arg.workers, 'r') as f:
        workers = json.load(f)

    core.set_workers(workers, arg.n)

    try:
        if not arg.do_retrieve_only:
            core.resources_dispatch()
        else:
            core.require_client_log()
    except ConnectionAbortedError:
        print('All Done.')