PCTExamples class

Class to run hierarchy configurations.

PCTExamples Class

The PCTExamples class is designed to load a PCTHierarchy configuration file and provide various methods to interact with the hierarchy.


source

PCTExamples

 PCTExamples (config_file, min=True, early_termination=False,
              history=False, additional_props=None, render=False,
              video_params=None)

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.

Usage Examples for PCTExamples.run_example

Below are several usage examples demonstrating the new keyword-argument-based interface for run_example.

# Basic run with MountainCar config
result_basic = PCTExamples.run_example('testfiles/MountainCar/MountainCar-cdf7cc1497ad143c0b04a3d9e72ab783.properties')
result_basic

# Full featured run
result_full = PCTExamples.run_example(
    config_file='testfiles/MountainCar/MountainCar-cdf7cc1497ad143c0b04a3d9e72ab783.properties',
    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

# Just create image and get config
result_image = PCTExamples.run_example(
    config_file='testfiles/MountainCar/MountainCar-cdf7cc1497ad143c0b04a3d9e72ab783.properties',
    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 help
PCTExamples.run_example('', display_usage=True)
=== Hierarchy Summary ===
**************************
pcthierarchy PCTHierarchy [2, 1] 276b0d6d-6be5-11f0-82b6-5c879c15de65
--------------------------
PRE: MountainCarContinuousV0 MountainCarContinuousV0 | 0 | links  Action1 
IP IndexedParameter | index 0 | 0.0 | links  MountainCarContinuousV0 
IV IndexedParameter | index 1 | 0.0 | links  MountainCarContinuousV0 
Level 0 Cols 2
L0C0 PCTNode 276b0d6d-6be5-11f0-82b6-5c879c15de65
----------------------------
REF: RL0C0 SmoothWeightedSum | weights [3.67] smooth 0.17 | -0.0 | links  OL1C0 
PER: PL0C0 SmoothWeightedSum | weights [1] smooth 0.04 | 0.0 | links  IV 
COM: CL0C0 Subtract | -0.0 | links  RL0C0 PL0C0 
OUT: OL0C0 SmoothWeightedSum | weights [-0.68] smooth 0.01 | 0.0 | links  CL0C0 
----------------------------
L0C1 PCTNode 276b0d6d-6be5-11f0-82b6-5c879c15de65
----------------------------
REF: RL0C1 SmoothWeightedSum | weights [2.24] smooth 0.79 | -0.0 | links  OL1C0 
PER: PL0C1 SmoothWeightedSum | weights [1] smooth 0.24 | 0.0 | links  IV 
COM: CL0C1 Subtract | -0.0 | links  RL0C1 PL0C1 
OUT: OL0C1 SmoothWeightedSum | weights [1.76] smooth 0.84 | -0.0 | links  CL0C1 
----------------------------
Level 1 Cols 1
L1C0 PCTNode 276b0d6d-6be5-11f0-82b6-5c879c15de65
----------------------------
REF: RL1C0 Constant | 0.45 
PER: PL1C0 SmoothWeightedSum | weights [1] smooth 0.76 | 0.0 | links  IP 
COM: CL1C0 Subtract | -0.0 | links  RL1C0 PL1C0 
OUT: OL1C0 SmoothWeightedSum | weights [1.29] smooth 0.54 | -0.0 | links  CL1C0 
----------------------------
POST: Action1 WeightedSum | weights [1, 1] | 0 | links  OL0C0 OL0C1 
**************************
=== Configuration Retrieved ===
=== Creating Hierarchy Image ===
C:\Users\ruper\Versioning\python\nbdev\pct\pct\hierarchy.py:323: UserWarning:

This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
Hierarchy image saved as: /tmp/MountainCar-cdf7cc1497ad143c0b04a3d9e72ab783_hierarchy.png
=== Running Hierarchy ===
[0] -0.568 0.000 0.632 -0.0 False False Error: Continuous_MountainCarEnv.render() got an unexpected keyword argument 'mode'
=== Hierarchy Summary ===
**************************
pcthierarchy PCTHierarchy [2, 1] 27a2eb26-6be5-11f0-a833-5c879c15de65
--------------------------
PRE: MountainCarContinuousV0 MountainCarContinuousV0 | 0 | links  Action1 
IP IndexedParameter | index 0 | 0.0 | links  MountainCarContinuousV0 
IV IndexedParameter | index 1 | 0.0 | links  MountainCarContinuousV0 
Level 0 Cols 2
L0C0 PCTNode 27a2eb26-6be5-11f0-a833-5c879c15de65
----------------------------
REF: RL0C0 SmoothWeightedSum | weights [3.67] smooth 0.17 | -0.0 | links  OL1C0 
PER: PL0C0 SmoothWeightedSum | weights [1] smooth 0.04 | 0.0 | links  IV 
COM: CL0C0 Subtract | -0.0 | links  RL0C0 PL0C0 
OUT: OL0C0 SmoothWeightedSum | weights [-0.68] smooth 0.01 | 0.0 | links  CL0C0 
----------------------------
L0C1 PCTNode 27a2eb26-6be5-11f0-a833-5c879c15de65
----------------------------
REF: RL0C1 SmoothWeightedSum | weights [2.24] smooth 0.79 | -0.0 | links  OL1C0 
PER: PL0C1 SmoothWeightedSum | weights [1] smooth 0.24 | 0.0 | links  IV 
COM: CL0C1 Subtract | -0.0 | links  RL0C1 PL0C1 
OUT: OL0C1 SmoothWeightedSum | weights [1.76] smooth 0.84 | -0.0 | links  CL0C1 
----------------------------
Level 1 Cols 1
L1C0 PCTNode 27a2eb26-6be5-11f0-a833-5c879c15de65
----------------------------
REF: RL1C0 Constant | 0.45 
PER: PL1C0 SmoothWeightedSum | weights [1] smooth 0.76 | 0.0 | links  IP 
COM: CL1C0 Subtract | -0.0 | links  RL1C0 PL1C0 
OUT: OL1C0 SmoothWeightedSum | weights [1.29] smooth 0.54 | -0.0 | links  CL1C0 
----------------------------
POST: Action1 WeightedSum | weights [1, 1] | 0 | links  OL0C0 OL0C1 
**************************

            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.
            
{'success': False, 'error': "[Errno 2] No such file or directory: ''"}