Exemplo n.º 1
0
    def move_agent_done(self):
        """Respond to move agents done message from coordinator."""
        assert not self.flag_move_agents_done
        self.flag_move_agents_done = True

        self.every_runner_proxy.receive_agent_done(asys.current_rank())
        self._try_start_step()
Exemplo n.º 2
0
    def do_step(self):
        """Do the actual stepping through over local agents to produce updates."""
        dead_agents = []

        # Step through the agents
        for agent_id, agent in self.local_agents.items():
            start_time = perf_counter()

            # Step through the agent
            updates = agent.step(self.timestep)
            memory_usage = agent.memory_usage()
            is_alive = agent.is_alive()
            if not is_alive:
                dead_agents.append(agent_id)

            # Send out the updates
            for update in updates:
                store_name = update.store_name
                store = self.store_proxies[store_name]
                store.handle_update(update, buffer_=True)
            end_time = perf_counter()

            # Inform the coordinator
            self.coordinator_proxy.agent_step_profile(
                asys.current_rank(),
                agent_id=agent_id,
                step_time=(end_time - start_time),
                memory_usage=memory_usage,
                n_updates=len(updates),
                is_alive=is_alive,
                buffer_=True)

        # Tell stores that we are done for this step
        for store in self.store_proxies.values():
            store.handle_update_done(asys.current_rank())

        # Tell the coordinator we are done
        self.coordinator_proxy.agent_step_profile_done(asys.current_rank())

        # Delete any dead agents
        for agent_id in dead_agents:
            del self.local_agents[agent_id]
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    def _try_flush(self):
        """Apply the cached updates to the state store."""
        self.log.log(
            INFO_FINE,
            "Can flush? (NHUD=%d/%d)",
            self.num_handle_update_done,
            WORLD_SIZE,
        )
        if self.num_handle_update_done < WORLD_SIZE:
            return

        start_time = perf_counter()
        self.flush()
        flush_time = perf_counter() - start_time

        self.simulator_proxy.store_flush_done(
            self.store_name, asys.current_rank(), flush_time,
        )

        self.num_handle_update_done = 0
Exemplo n.º 5
0
    def __init__(self):
        self.visit_output_batches = []
        self.new_state_batches = []

        config = get_config()
        pid_behav_rank = config.pid_behav_rank

        if config.java_behavior == 1:
            LOG.info("BehaviorActor: Using Java behavior model")
            self.behavior_model = SimpleJavaBehaviorModel()
        elif config.java_behavior == 2:
            LOG.info(
                "BehaviorActor: Using SimpleBehaviorContSeedModel behavior model"
            )
            self.behavior_model = SimpleBehaviorContSeedModel()
        else:
            myrank = asys.current_rank()
            pids = [
                pid for pid, rank in pid_behav_rank.items() if rank == myrank
            ]
            seed = config.seed + myrank

            self.behavior_model = SimpleBehaviorModel(seed=seed, pids=pids)
Exemplo n.º 6
0
    def __init__(self, source, sink):
        self.source = source
        self.sink = sink
        self.rank = xa.current_rank()

        self.source.ready(self.rank)
Exemplo n.º 7
0
 def greet(self, name):
     print("Greetings to %s from rank %s" % (name, xa.current_rank()))