def start_tick(self): """Start the next tick.""" config = get_config() lid_rank = config.lid_rank pid_prog_rank = config.pid_prog_rank visit_schema = config.visit_schema state_schema = config.state_schema current_state_df = self.behavior_model.next_state_df visit_df = self.behavior_model.next_visit_df LOG.debug("BehaviorActor: Sending out visit batches to LocationActor") df_scatter( visit_df, "lid", lid_rank, asys.ranks(), visit_schema, LOC_AID, "visit", ) LOG.debug( "BehaviorActor: Sending out current state batches to ProgressionActor" ) df_scatter( current_state_df, "pid", pid_prog_rank, asys.ranks(), state_schema, PROG_AID, "current_state", )
def try_run_behavior_model(self): """Try running the behavior model.""" if len(self.visit_output_batches) < len(asys.ranks()): return if len(self.new_state_batches) < len(asys.ranks()): return LOG.debug("BehaviorActor: Running behavior model") self.run_behavior_model()
def pong(self): self.workers_done += 1 if self.workers_done == len(xa.ranks()): self.end = time() print("n_ranks: %d" % len(xa.ranks())) print("n_nodes: %d" % len(xa.nodes())) runtime = (self.end - self.start) print("runtime: %e" % runtime) xa.stop()
def maybe_stop(self): if self.num_consumer_done == len(xa.ranks()): self.end = time() print("n_sent: %d" % self.objects_sent) print("n_received: %d" % self.objects_received) print("n_ranks: %d" % len(xa.ranks())) print("n_nodes: %d" % len(xa.nodes())) runtime = (self.end - self.start) print("runtime: %e" % runtime) xa.stop()
def __init__(self, store_proxies, coordinator_aid, runner_aid): """Initialize the runner. Parameters ---------- store_proxies : dict [str -> ActorProxy] Actor proxy objects to stores coordinator_aid : str ID of the coordinator actor runner_aid : str ID of the runner actors """ self.local_agents = {} self.store_proxies = store_proxies self.coordinator_proxy = asys.ActorProxy(asys.MASTER_RANK, coordinator_aid) self.every_runner_proxy = asys.ActorProxy(asys.EVERY_RANK, runner_aid) self.runner_proxies = [ asys.ActorProxy(rank, runner_aid) for rank in asys.ranks() ] # Step variables self.timestep = None self.flag_create_agent_done = None self.flag_move_agents_done = None self.num_receive_agent_done = None self._prepare_for_next_step()
def try_compute_prgression_output(self): """Try to run compute_progression_output.""" if len(self.current_state_batches) < len(self.behav_ranks): return if len(self.visit_output_batches) < len(asys.ranks()): return self.compute_progression_output()
def __init__(self, per_node_behavior, java_behavior): """Initialize.""" nodes = list(asys.nodes()) current_rank = asys.current_rank() current_node = [ node for node in nodes if current_rank in asys.node_ranks(node) ] current_node = current_node[0] current_node_index = nodes.index(current_node) os.environ["CURRENT_NODE"] = str(current_node_index) self.per_node_behavior = per_node_behavior self.java_behavior = java_behavior self.seed = int(os.environ["SEED"]) self.tick_time = int(os.environ["TICK_TIME"]) self.attr_names = os.environ["VISUAL_ATTRIBUTES"].strip().split(",") self.disease_model = DiseaseModel(os.environ["DISEASE_MODEL_FILE"]) self.visit_schema = make_visit_schema(self.attr_names) self.visit_output_schema = make_visit_output_schema(self.attr_names) self.state_schema = make_state_schema() self.empty_visit_df = self.visit_schema.empty_table().to_pandas() self.empty_visit_output_df = self.visit_output_schema.empty_table( ).to_pandas() self.empty_state_df = self.state_schema.empty_table().to_pandas() lid_part_file = os.environ["LID_PARTITION"] pid_part_file = os.environ["PID_PARTITION"] lid_part_df = pd.read_csv(lid_part_file) pid_part_df = pd.read_csv(pid_part_file) self.lid_rank = {} for lid, node, cpu in lid_part_df.itertuples(index=False, name=None): self.lid_rank[lid] = node_rank(node, cpu) self.pid_prog_rank = {} self.pid_behav_rank = {} for pid, node, cpu in pid_part_df.itertuples(index=False, name=None): self.pid_prog_rank[pid] = node_rank(node, cpu) if per_node_behavior: self.pid_behav_rank[pid] = node_rank(node, 0) else: self.pid_behav_rank[pid] = node_rank(node, cpu) if per_node_behavior: self.behav_ranks = [ asys.node_ranks(node)[0] for node in asys.nodes() ] else: self.behav_ranks = asys.ranks()
def main(self): # Create a greeter on very rank. greeter_id = "greeter" for rank in xa.ranks(): xa.create_actor(rank, greeter_id, Greeter) # Send the greeters the greet message. every_greeter = xa.ActorProxy(xa.EVERY_RANK, greeter_id) every_greeter.greet("world", send_immediate=True) # We are done now. xa.stop()
def main(self): source_rank = 0 sink_rank = 1 shape = (100, 100) source = xa.ActorProxy(source_rank, "source") sink = xa.ActorProxy(sink_rank, "sink") workers = {r: xa.ActorProxy(r, "worker") for r in xa.ranks() if r > 1} n = len(workers) source.create_actor_(Source, n, shape, workers) sink.create_actor_(Sink, n) for worker in workers.values(): worker.create_actor_(Worker, source, sink)
def produce(self): objects_sent = 0 n_messages = random.randint(MIN_NUM, MAX_NUM) for _ in range(n_messages): rank = random.choice(xa.ranks()) msg_size = random.randint(MIN_SIZE, MAX_SIZE) objects_sent += msg_size msg = list(range(msg_size)) self.consumer[rank].consume(msg) #print("Sent %d objects to %d" % (len(msg), rank)) self.every_consumer.producer_done() self.main.producer_done(objects_sent)
def main(self): """Run the simulation.""" for rank in asys.ranks(): asys.create_actor( rank, CONFIG_AID, ConfigActor, per_node_behavior=self.per_node_behavior, java_behavior=self.java_behavior, ) asys.create_actor(rank, LOC_AID, LocationActor) asys.create_actor(rank, PROG_AID, ProgressionActor) for rank in self.behav_ranks: asys.create_actor(rank, BEHAV_AID, BehaviorActor) LOG.info("MainActor: Starting tick %d", self.cur_tick) for rank in self.behav_ranks: asys.ActorProxy(rank, BEHAV_AID).start_tick()
def __init__(self): """Initialize.""" self.num_ticks = int(os.environ["NUM_TICKS"]) self.output_file = os.environ["OUTPUT_FILE"] self.per_node_behavior = bool( int(os.environ.get("PER_NODE_BEHAVIOR", "0"))) self.java_behavior = int(os.environ.get("JAVA_BEHAVIOR", "0")) if self.java_behavior: self.per_node_behavior = True self.epicurve_parts = [] self.cur_tick = 0 self.tick_epicurve = [] if self.per_node_behavior: self.behav_ranks = [ asys.node_ranks(node)[0] for node in asys.nodes() ] else: self.behav_ranks = asys.ranks()
def compute_visit_output(self): """Compute the visit outputs.""" config = get_config() disease_model = config.disease_model attr_names = config.attr_names pid_prog_rank = config.pid_prog_rank visit_output_schema = config.visit_output_schema visit_df = [ unserialize_df(batch) for batch in self.visit_batches if batch is not None ] if visit_df: visit_df = pd.concat(visit_df, axis=0) else: visit_df = get_config().empty_visit_df visit_outputs = defaultdict(list) for lid, group in visit_df.groupby("lid"): visit_output = disease_model.compute_visit_output( group, attr_names, lid) for k, v in visit_output.items(): visit_outputs[k].append(v) visit_outputs.default_factory = None visit_outputs = {k: np.hstack(vs) for k, vs in visit_outputs.items()} visit_output_df = pd.DataFrame(visit_outputs) LOG.debug("LocationActor: Sending visit output to ProgressionActor") df_scatter( visit_output_df, "pid", pid_prog_rank, asys.ranks(), visit_output_schema, PROG_AID, "visit_output", ) self.visit_batches = []
def __init__(self, balancer, simulator_aid, runner_aid, summary_writer_aid=None): """Initialize. Parameters ---------- balancer: LoadBalancer The agent load balancer simulator_aid : str The ID of the simulator actor runner_aid : str The ID of the runner actors summary_writer_aid : str The ID of the local summary writer actor """ self.balancer = balancer self.simulator_proxy = asys.ActorProxy(asys.MASTER_RANK, simulator_aid) self.runner_proxies = [ asys.ActorProxy(rank, runner_aid) for rank in asys.ranks() ] self.every_runner_proxy = asys.ActorProxy(asys.EVERY_RANK, runner_aid) self.summary_writer_aid = summary_writer_aid self.num_agents_created = 0 self.num_agents_died = 0 # Step variables self.timestep = None self.agent_constructor = None self.flag_create_agent_done = None self.num_agent_step_profile_done = None self.rank_step_time = None self.rank_memory_usage = None self.rank_n_updates = None self.agent_step_time = None self.agent_memory_usage = None self.agent_n_updates = None self.balancing_time = None self._prepare_for_next_step()
def main(): if len(xa.ranks()) != 2: print("This program must be run with exactly 2 ranks.") sys.exit(1) xa.start("main", Main)
def __init__(self): self.main = xa.ActorProxy(xa.MASTER_RANK, "main") self.consumer = [ xa.ActorProxy(rank, "consumer") for rank in xa.ranks() ] self.every_consumer = xa.ActorProxy(xa.EVERY_RANK, "consumer")
def main(): if len(xa.ranks()) < 3: print("This program must be run with 3 or more ranks.") sys.exit(1) xa.start("main", Main)
"""The Matrix ABM.""" import logging import xactor as asys INFO_FINE = logging.INFO - 1 WORLD_SIZE = len(asys.ranks()) from .datatypes import Timestep, Constructor, StateUpdate from .agent import Agent, AgentPopulation from .simulator import Simulator from .coordinator import Coordinator from .runner import Runner from .timestep_generator import TimestepGenerator, RangeTimestepGenerator from .state_store import StateStore, SQLite3Store from .load_balancer import RandomLoadBalancer, GreedyLoadBalancer from .resource_manager import SQLite3Manager, TensorboardWriter