bptk-py
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: BPTK-Py | ||
| Version: 1.8.0 | ||
| Version: 1.9.0 | ||
| Summary: A python simulation engine for System Dynamics & Agent based models | ||
@@ -56,4 +56,9 @@ Home-page: https://www.transentis.com/business-prototyping-toolkit/en | ||
| ### 1.9.0 | ||
| * BPTKServer: `run` endpoint now also works for agent-based models | ||
| * Model: Add `configure_agent`, `configure_properties` and `delete_agent(s)` methods | ||
| * Bump versions of key dependencies | ||
| ### 1.8.0 | ||
| * BPTKServer: Add new endpoint start-instances that starts multiple instances in one goo | ||
| * BPTKServer: Add new endpoint `start-instances` that starts multiple instances in one goo | ||
@@ -60,0 +65,0 @@ ### 1.7.6 |
@@ -1,16 +0,16 @@ | ||
| pandas==1.5.3 | ||
| matplotlib==3.7.0 | ||
| scipy==1.10.1 | ||
| numpy==1.24.2 | ||
| ipywidgets==8.0.4 | ||
| pyyaml==6.0 | ||
| xlsxwriter==3.0.8 | ||
| pandas==2.1.3 | ||
| matplotlib==3.8.2 | ||
| scipy==1.11.4 | ||
| numpy==1.26.2 | ||
| ipywidgets==8.1.1 | ||
| pyyaml==6.0.1 | ||
| xlsxwriter==3.1.9 | ||
| parsimonious==0.10.0 | ||
| xmltodict==0.12.0 | ||
| jinja2==3.1.2 | ||
| sympy==1.11.1 | ||
| distlib==0.3.6 | ||
| cachetools==5.3.0 | ||
| requests==2.28.2 | ||
| flask==2.1.3 | ||
| jsonpickle==3.0.1 | ||
| sympy==1.12 | ||
| distlib==0.3.7 | ||
| cachetools==5.3.2 | ||
| requests==2.31.0 | ||
| flask==3.0.0 | ||
| jsonpickle==3.0.2 |
@@ -52,2 +52,3 @@ # /`- | ||
| self.agents = [] | ||
| self.next_agent_id=0 | ||
| self.name = name | ||
@@ -157,3 +158,3 @@ self.agent_type_map = {} | ||
| Retrieve one agent by its ID | ||
| Retrieve an agent by its ID | ||
@@ -167,7 +168,11 @@ Args: | ||
| """ | ||
| for agent in self.agents: | ||
| if agent.id==agent_id: | ||
| return agent | ||
| return self.agents[agent_id] | ||
| return None | ||
| def create_agents(self, agent_spec): | ||
| """Create agents according to the agent specificaction. | ||
| """Create agents according to the agent specification. | ||
@@ -200,4 +205,6 @@ The agent specification is a dictionary containing the agent name and properties. Internally, this method then uses the registered agent factories to actually create the agents. | ||
| agent = self.agent_factories[agent_type](len(self.agents), self, agent_properties) | ||
| agent = self.agent_factories[agent_type](self.next_agent_id, self, agent_properties) | ||
| self.next_agent_id += 1 | ||
| if not isinstance(agent,Agent): | ||
@@ -211,2 +218,26 @@ raise NotAnAgentException("{} is not an instance of BPTK_Py.Agent. Please only use subclasses of Agent".format(agent)) | ||
| def delete_agent(self,agent_id): | ||
| self.delete_agents([agent_id]) | ||
| def delete_agents(self,agent_ids): | ||
| temp_agents=[] | ||
| agent_types=[] | ||
| for agent in self.agents: | ||
| if agent.id not in agent_ids: | ||
| temp_agents.append(agent) | ||
| else: | ||
| agent_types.append(agent.agent_type) | ||
| self.agents=temp_agents | ||
| for agent_type in agent_types: | ||
| self.agent_type_map[agent_type]=[] | ||
| for agent in self.agents: | ||
| if agent.agent_type == agent_type: | ||
| self.agent_type_map[agent_type].append(agent.id) | ||
| def set_property(self, name, property_spec): | ||
@@ -480,3 +511,3 @@ """Configure a property of the model itself, as opposed to the properties of individual agents. | ||
| def random_agents(self, agent_type, num_agents): | ||
| """Retreive a number of random agents | ||
| """Retrieve a number of random agents | ||
@@ -542,7 +573,5 @@ Args: | ||
| def configure(self, config): | ||
| def configure_properties(self,properties): | ||
| """ | ||
| Called to configure the model using a dictionary. This method is called by the framework if you instantiate models from scenario files. But you can also call the method directly. | ||
| Called to configure model proerties using a dictionary. | ||
| Args: | ||
@@ -552,6 +581,3 @@ config: Dict. | ||
| """ | ||
| self.run_specs(config["runspecs"]["starttime"], config["runspecs"]["stoptime"], config["runspecs"]["dt"]) | ||
| properties = config["properties"] | ||
| if type(properties) == list: | ||
@@ -583,7 +609,40 @@ for property in properties: | ||
| agents = config["agents"] | ||
| for agent in agents: | ||
| def configure_agents(self,config): | ||
| """ | ||
| Called to configure agent proerties using a dictionary. This removes all agents first.1 | ||
| Args: | ||
| config: Dict. | ||
| Dictionary containing the config: {"runspecs":<dictionary of runspecs>,"properties":<dictionary of properties>,"agents":<list of agent-specs>}. | ||
| """ | ||
| for agent_type in self.agent_type_map: | ||
| self.agent_type_map[agent_type] = [] | ||
| self.agents = [] | ||
| for agent in config: | ||
| self.create_agents(agent) | ||
| def configure(self, config): | ||
| """ | ||
| Called to configure the model using a dictionary. This method is called by the framework if you instantiate models from scenario files. But you can also call the method directly. | ||
| Args: | ||
| config: Dict. | ||
| Dictionary containing the config: {"runspecs":<dictionary of runspecs>,"properties":<dictionary of properties>,"agents":<list of agent-specs>}. | ||
| """ | ||
| self.run_specs(config["runspecs"]["starttime"], config["runspecs"]["stoptime"], config["runspecs"]["dt"]) | ||
| properties = config["properties"] | ||
| self.configure_properties(properties) | ||
| agents = config["agents"] | ||
| self.configure_agents(agents) | ||
| def agent_count(self, agent_type): | ||
@@ -590,0 +649,0 @@ """Get count of agents of a given type. |
@@ -68,3 +68,3 @@ # /`- | ||
| else: | ||
| output[t] = series | ||
| output[t] = 0 #TODO: should do something about this | ||
| return output | ||
@@ -497,2 +497,2 @@ | ||
| return df | ||
| return df |
@@ -350,4 +350,4 @@ # /`- | ||
| if len(args) > 1: | ||
| return 'np.product([' + "+".join([str(parseExpression(x)) for x in args]) + '])' | ||
| return 'np.product(' + " , ".join([str(parseExpression(x)) for x in args]) + ')' | ||
| return 'np.prod([' + "+".join([str(parseExpression(x)) for x in args]) + '])' | ||
| return 'np.prod(' + " , ".join([str(parseExpression(x)) for x in args]) + ')' | ||
@@ -354,0 +354,0 @@ |
@@ -347,3 +347,5 @@ # /`- | ||
| for scenario_manager_name, scenario_manager_data in settings.items(): | ||
| for scenario_name, scenario_settings in scenario_manager_data.items(): | ||
| self._bptk.reset_scenario_cache(scenario_manager=scenario_manager_name,scenario=scenario_name) | ||
| scenario = self._bptk.get_scenario(scenario_manager_name,scenario_name) | ||
@@ -366,3 +368,8 @@ if "constants" in scenario_settings: | ||
| scenario.dt = runspecs["dt"] | ||
| self._bptk.reset_scenario_cache(scenario_manager=scenario_manager_name,scenario=scenario_name) | ||
| if "properties" in scenario_settings: | ||
| scenario.configure_properties(scenario_settings["properties"]) | ||
| if "agents" in scenario_settings: | ||
| scenario.configure_agents(scenario_settings["agents"]) | ||
| except KeyError: | ||
@@ -387,10 +394,27 @@ pass | ||
| try: | ||
| equations = content["equations"] | ||
| except KeyError: | ||
| resp = make_response('{"error": "expecting equations to be set"}', 500) | ||
| equations = [] | ||
| agents = [] | ||
| agent_states=[] | ||
| agent_properties=[] | ||
| agent_property_types=[] | ||
| if(not "agents" in content.keys() and not "equations" in content.keys()): | ||
| resp = make_response('{"error": "expecting either equations or agents to be set"}', 500) | ||
| resp.headers['Content-Type']='application/json' | ||
| resp.headers['Access-Control-Allow-Origin']='*' | ||
| return resp | ||
| if("agents" in content.keys()): | ||
| agents = content["agents"] | ||
| if("equations" in content.keys()): | ||
| equations = content["equations"] | ||
| if("agent_states" in content.keys()): | ||
| agent_states = content["agent_states"] | ||
| if("agent_properties" in content.keys()): | ||
| agent_properties = content["agent_properties"] | ||
| if("agent_property_types" in content.keys()): | ||
| agent_property_types = content["agent_property_types"] | ||
| result = self._bptk.run_scenarios( | ||
@@ -400,2 +424,6 @@ scenario_managers=scenario_managers, | ||
| equations=equations, | ||
| agents=agents, | ||
| agent_states=agent_states, | ||
| agent_properties=agent_properties, | ||
| agent_property_types=agent_property_types, | ||
| return_format="json" | ||
@@ -402,0 +430,0 @@ ) |
+7
-2
| Metadata-Version: 2.1 | ||
| Name: BPTK_Py | ||
| Version: 1.8.0 | ||
| Version: 1.9.0 | ||
| Summary: A python simulation engine for System Dynamics & Agent based models | ||
@@ -56,4 +56,9 @@ Home-page: https://www.transentis.com/business-prototyping-toolkit/en | ||
| ### 1.9.0 | ||
| * BPTKServer: `run` endpoint now also works for agent-based models | ||
| * Model: Add `configure_agent`, `configure_properties` and `delete_agent(s)` methods | ||
| * Bump versions of key dependencies | ||
| ### 1.8.0 | ||
| * BPTKServer: Add new endpoint start-instances that starts multiple instances in one goo | ||
| * BPTKServer: Add new endpoint `start-instances` that starts multiple instances in one goo | ||
@@ -60,0 +65,0 @@ ### 1.7.6 |
+6
-1
@@ -42,4 +42,9 @@ # Business Prototyping Toolkit for Python | ||
| ### 1.9.0 | ||
| * BPTKServer: `run` endpoint now also works for agent-based models | ||
| * Model: Add `configure_agent`, `configure_properties` and `delete_agent(s)` methods | ||
| * Bump versions of key dependencies | ||
| ### 1.8.0 | ||
| * BPTKServer: Add new endpoint start-instances that starts multiple instances in one goo | ||
| * BPTKServer: Add new endpoint `start-instances` that starts multiple instances in one goo | ||
@@ -46,0 +51,0 @@ ### 1.7.6 |
+31
-1
@@ -410,2 +410,32 @@ import pytest | ||
| expected_json = json.dumps(expected_json, indent=2) | ||
| assert results==expected_json | ||
| assert results==expected_json | ||
| def test_abm_delete_agent(abm_model): | ||
| model = abm_model.get_scenario(scenario_manager="testAbmManager",scenario="testScenario2") | ||
| assert len(model.agents)==5 | ||
| assert len(model.agent_type_map["agent_1"])==2 | ||
| assert len(model.agent_type_map["agent_2"])==3 | ||
| agentIds=[] | ||
| agents=[] | ||
| for agent in model.agents: | ||
| agents.append(agent) | ||
| agentIds.append(agent.id) | ||
| model.delete_agent(agentIds.pop(0)) | ||
| assert len(model.agents)==4 | ||
| assert len(model.agent_type_map["agent_1"])==1 | ||
| agentIds.pop(0) | ||
| agentIds.pop(0) | ||
| model.delete_agents(agentIds) | ||
| assert len(model.agents)==2 | ||
| assert len(model.agent_type_map["agent_1"])==1 | ||
| assert len(model.agent_type_map["agent_2"])==1 | ||
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
813373
0.53%15621
0.53%