Environment Execution
An environment episode can be manually executed using it’s reset()
and
step()
methods. See the simple example below that runs through a single complete
episode, using random actions sampled from the agent’s action spaces and prints out the
evaluated actions and observations:
env = SupplyChainEnv()
observations = env.reset()
while not env.is_terminated() or env.is_truncated():
actions = {
agent.id: agent.action_space.sample()
for agent in env.strategic_agents
}
observations = env.step(actions).observations
If this method is used, any supertypes must manually be passed to the agent’s
__init__()
method or manually set as the supertype
property of the
agent before the reset()
method is called:
env = SupplyChainEnv()
env["SHOP"].supertype = ShopAgent.Supertype(...)
Enabling Telemetry
Phantom includes a powerful tool for aiding the development and debugging of environments called Telemetry. There are two output destinations for the output: print logging (to the terminal) and file logging:
ph.telemetry.logger.configure_print_logging(enable=True)
ph.telemetry.logger.configure_file_logging(file_path="log.json", append=False)
env = SupplyChainEnv()
observations = env.reset()
while not env.is_terminated() or env.is_truncated():
actions = {
agent.id: agent.action_space.sample()
for agent in env.strategic_agents
}
observations = env.step(actions).observations
There are many options to configure what will be logged for both functions, see the Telemetry Logger page for full details.
Warning
This feature is only designed for single-process execution. Using this with multiple processes/workers may lead to invalid output.
The following is an example of what the print logging looks like:
Phantom also comes with a handy easy to use web viewer for log files:
This can be opened by running:
streamlit run scripts/view_telemetry.py <log_file>
Once started, navigate to http://localhost:8501
in your browser.