GitLab maintenance scheduled for Tomorrow, 2020-01-30, from 17:00 to 18:00 CT - Services will be unavailable during this time.

Commit fa56e024 authored by Valentin Reis's avatar Valentin Reis

[fix] bandit fixes and options

parent 37029d12
......@@ -5,12 +5,14 @@ Usage:
daemon bandit
[-k <k> | --discretization=<k>] [-l <watts> | --lowerboundwatts=<watts>]
[-e <eps> | --epsilon=<eps>] [-o <k> | --log_power=<log>]
daemon enforce <policy>
[-p <period> | --period=<period>]
daemon enforce <enforce>
[-k <k> | --discretization <k>] [-l <watts> | --lowerboundwatts <watts>]
[-o <k> | --log_power=<log>]
[-o <n> | --log_power=<log>]
[-p <period> | --period=<period>]
Arguments:
<policy> The powercontrol policy to enforce. [default: None]
<enforce> The powercontrol policy to enforce. [default: None]
Options:
-h --help Show this screen.
......@@ -20,6 +22,7 @@ Options:
-e <eps> --epsilon=<eps> The exploration constant for bandit powercontrol.
[default: 0.1]
-o <log> --log_power=<log> The log file for power use.
-p <period> --period=<period> The period for power control.
Try: daemon bandit -k 4 -l 100 -e 0.1
daemon bandit -k 4 -l 100 -e 1 #random bandit
......@@ -35,9 +38,12 @@ if __name__ == "__main__":
arguments = docopt(__doc__, version='Naval Fate 2.0')
print(arguments)
if arguments["enforce"]:
arguments["<policy>"]=int(arguments["<policy>"])
arguments["<enforce>"]=int(arguments["<enforce>"])
if arguments["--period"] is not None:
arguments["--period"]=int(arguments["--period"])
nrm.daemon.runner(power_discretization=int(arguments["--discretization"]),
enforce_powerpolicy=arguments["<policy>"],
enforce_powerpolicy=arguments["<enforce>"],
exploration_constant=float(arguments["--epsilon"]),
lowerboundwatts=int(arguments["--lowerboundwatts"]),
log_power=arguments["--log_power"])
log_power=arguments["--log_power"],
period=arguments["--period"])
......@@ -22,7 +22,7 @@ class Application(object):
def __init__(self, uuid, container, progress, threads):
self.uuid = uuid
self.container_uuid = container
self.progress = progress
self.progress = 1
self.threads = threads
self.thread_state = 'stable'
......@@ -59,7 +59,7 @@ class Application(object):
"""Update the progress tracking."""
self.progress = self.progress + float(msg['payload'])
def reset_progress(self, msg):
def reset_progress(self):
"""Update the progress tracking."""
self.progress = 0
......
......@@ -147,7 +147,7 @@ class BanditController(object):
self.enforce=enforce
self.log_power=log_power
if self.log_power is not None:
self.log_power.write("progress power loss a desc")
self.log_power.write("progress power loss a desc\n")
def planify(self, target, machineinfo, applications):
"""Plan the next action for the control loop."""
......@@ -155,6 +155,9 @@ class BanditController(object):
return([],[])
self.n=self.n+1
total_progress = sum([a.progress for a in applications.values()])
for a in applications.values():
a.reset_progress()
logger.info("Controller: applications %r" %applications.values())
total_power = float(machineinfo['energy']['power']['p0'])
logger.info("Controller: Reading machineinfo %s." %(str(machineinfo)))
logger.info("Controller: Reading progress %s and power %s."
......@@ -164,7 +167,7 @@ class BanditController(object):
if self.enforce is not None:
logger.info("Controller: enforced action.")
a=self.enforce
if self.n>self.initialization_rounds:
elif self.n>self.initialization_rounds:
logger.info("Controller: playing bandit.")
a=self.bandit.next(loss)
else:
......
......@@ -22,9 +22,11 @@ class Daemon(object):
enforce_powerpolicy=False,
lowerboundwatts=100,
exploration_constant=0.1,
log_power=None):
log_power=None,
period=5000):
self.target = 100.0
self.log_power = log_power
self.period = period
self.k = power_discretization
self.eps = exploration_constant
self.enforce = enforce_powerpolicy
......@@ -237,10 +239,10 @@ class Daemon(object):
self.machine_info = self.sensor_manager.do_update()
# setup periodic sensor updates
self.sensor_cb = ioloop.PeriodicCallback(self.do_sensor, 1000)
self.sensor_cb = ioloop.PeriodicCallback(self.do_sensor, self.period)
self.sensor_cb.start()
self.control = ioloop.PeriodicCallback(self.do_control, 1000)
self.control = ioloop.PeriodicCallback(self.do_control, self.period)
self.control.start()
# take care of signals
......@@ -254,10 +256,11 @@ def runner(power_discretization=4,
enforce_powerpolicy=False,
lowerboundwatts=100,
exploration_constant=0.1,
log_power=None):
log_power=None,
period=5000):
ioloop.install()
logging.basicConfig(level=logging.DEBUG)
if log_power is not None: log_power=open(log_power,'r')
if log_power is not None: log_power=open(log_power,'w',0)
try:
daemon = Daemon(power_discretization=power_discretization,
enforce_powerpolicy=enforce_powerpolicy,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment