PCTExamples class provides methods to load a PCT hierarchy from a configuration file, summarize the hierarchy, get the configuration, draw the hierarchy, run the hierarchy for a specified number of steps, and close the environment. Attributes: hierarchy (PCTHierarchy): The loaded PCT hierarchy. env (Environment): The environment associated with the PCT hierarchy.
Below are several usage examples demonstrating the new keyword-argument-based interface for run_example.
The class also provides model structure analysis capabilities:
The get_model_details() method returns information about the model’s structure in JSON format, including total node count and parameter count.
You can now use the get_model_details=True parameter in run_example() to include model statistics in the results without having to create a separate instance.
# Basic run with MountainCar configconfig_file='testfiles/MountainCar/MountainCar-cdf7cc.properties',result_basic = PCTExamples.run_example(config_file)result_basic# Full featured runresult_full = PCTExamples.run_example( config_file=config_file, run_hierarchy=True, render=True, early_termination=True, steps=5000, print_summary=True, return_config=True, verbose=True, image_params={'figsize': (16, 10), 'with_labels': True}, video_params={'fps': 60, 'filename': '/tmp/mountaincar_demo.mp4'}, plot_params={'plots_figsize': (14, 8), 'title_prefix': 'MountainCar_'})result_full# Show the model details from the resultsif'model_details'in result_full:print("Model Statistics:")print(f"Total nodes: {result_full['model_details']['total_nodes']}")print(f"Total parameters: {result_full['model_details']['total_parameters']}")# Just create image and get configresult_image = PCTExamples.run_example( config_file=config_file, run_hierarchy=False, return_config=True, print_summary=True, plot_params={'single_plot': True, 'plots': {'title': 'position_plot', 'plot_items': ['position']}})result_image# Display usage helpPCTExamples.run_example(display_usage=True)
=== Creating Video ===
Error: expected str, bytes or os.PathLike object, not tuple
PCTExamples.run_example() Usage:
Basic usage:
PCTExamples.run_example('testfiles/MountainCar/MountainCar-cdf7cc1497ad143c0b04a3d9e72ab783.properties')
With options:
PCTExamples.run_example(
config_file='testfiles/MountainCar/MountainCar-cdf7cc1497ad143c0b04a3d9e72ab783.properties',
run_hierarchy=True, # Run the hierarchy
render=True, # Render environment
image_params={...}, # Create hierarchy diagram if not None
video_params={...}, # Create video if not None
plot_params={...}, # Create plots if not None
early_termination=True, # Enable early termination
steps=1000, # Override step count
print_summary=True, # Print hierarchy summary
return_config=True, # Return configuration
verbose=True # Verbose output
)
Returns dictionary with results and any requested outputs.
{'usage_displayed': True}
# Example of using get_model_details to obtain model statistics# Create a PCTExamples instancefilename ='testfiles/MountainCar/MountainCar-cdf7cc.properties'example = PCTExamples(config_file=filename)# Get model details as a JSON objectmodel_details = example.get_model_details()print("Model Details:")print(json.dumps(model_details, indent=4))# Access specific informationprint(f"\nTotal nodes: {model_details['total_nodes']}")print(f"Total parameters: {model_details['total_parameters']}")# Clean upexample.close()
Model Details:
{
"total_nodes": 3,
"total_parameters": 13
}
Total nodes: 3
Total parameters: 13