=== Instruction 1 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving a robotic gripper interacting with a drawer. It begins by setting up the environment and resetting the task to its initial state. The simulation can optionally record video of the task execution. 

The function retrieves the positions of objects in the environment, specifically the positions for the drawers. It then executes a series of steps: rotating the gripper to a specific orientation, moving to the side position of the middle drawer, moving to the anchor position of the middle drawer, picking up the middle drawer, and finally pulling the drawer to open it. 

After each step, the function checks if the task has ended prematurely. Regardless of the outcome, it ensures that the environment is properly shut down at the end of the task. The overall behavior is to simulate the process of opening a drawer using a robotic gripper.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: TASK defines a domain and problem for a planning system to open a drawer, while CODE_FUNC describes a function that simulates the execution of that task.
2. **Structure**: TASK is structured in PDDL (Planning Domain Definition Language) format, defining actions, predicates, and initial conditions, whereas CODE_FUNC is a narrative description of a function's behavior in a programming context.
3. **Detail Level**: TASK provides detailed specifications of actions, preconditions, and effects, while CODE_FUNC summarizes the steps without detailing the underlying logic or conditions.
4. **Execution**: TASK is intended for use in a planning system to generate a plan for opening a drawer, while CODE_FUNC describes the actual execution of a simulation of that plan.
5. **Environment Setup**: TASK includes the definition of the environment and its components (drawers, gripper, positions), while CODE_FUNC mentions setting up the environment but does not specify how it is done in detail.
6. **Outcome Handling**: TASK does not address how to handle the outcome of actions, while CODE_FUNC explicitly mentions checking if the task has ended prematurely and ensuring proper shutdown of the environment.
7. **Recording**: CODE_FUNC mentions the option to record video of the task execution, which is not present in TASK.
8. **Action Sequence**: TASK defines a sequence of actions in a formal way, while CODE_FUNC describes the sequence in a more general narrative form without formal action definitions. 

Overall, the two serve different purposes: TASK is for planning and CODE_FUNC is for simulation execution.

Refined Code Generated:
-------------------
import numpy as np
from env import setup_environment, shutdown_environment
from skill_code import rotate, move, pick, pull
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define the positions for the drawers
        middle_anchor_pos = positions['middle_anchor_pos']
        side_pos_middle = positions['middle_side_pos']

        # === Execute the Plan ===
        # Step 1: Rotate the gripper to the correct orientation
        print("[Task] Rotating gripper to ninety degrees.")
        obs, _, done = rotate(env, task, target_quat=np.array([0, 0, 1, 0]), max_steps=100, threshold=0.05, timeout=10.0)
        if done:
            print("[Task] Task ended during rotation!")
            return

        # Step 2: Move to the side position of the middle drawer
        print("[Task] Moving to side position of the middle drawer.")
        obs, _, done = move(env, task, target_pos=side_pos_middle, max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Task ended during movement!")
            return

        # Step 3: Move to the anchor position of the middle drawer
        print("[Task] Moving to anchor position of the middle drawer.")
        obs, _, done = move(env, task, target_pos=middle_anchor_pos, max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Task ended during movement!")
            return

        # Step 4: Pick the middle drawer
        print("[Task] Picking the middle drawer.")
        obs, _, done = pick(env, task, target_pos=middle_anchor_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Task ended during picking!")
            return

        # Step 5: Pull the middle drawer to open it
        print("[Task] Pulling the middle drawer to open it.")
        obs, _, done = pull(env, task, pull_distance=0.1, pull_axis='y', max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Task ended during pulling!")
            return

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")
-------------------

=== Instruction 2 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving a robotic gripper interacting with a drawer. It begins by setting up the environment and resetting the task to its initial state. It optionally initializes video recording for the simulation. The function retrieves the positions of objects in the environment, specifically the positions of a middle drawer and its side. 

The task is executed in a series of steps: first, the gripper is rotated to a specified orientation, then it moves to the side position of the middle drawer, followed by moving to the anchor position of the drawer. Next, the gripper picks up the middle drawer and finally pulls it open by a specified distance. After each step, the function checks if the task is completed and prints appropriate messages. Regardless of the outcome, the environment is shut down at the end of the task.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Nature of Content**: TASK is a formal representation of a planning problem in PDDL, while CODE_FUNC is a description of a procedural function for simulating a task.
2. **Format**: TASK is structured in a domain-specific language (PDDL), whereas CODE_FUNC is written in natural language.
3. **Purpose**: TASK defines the rules and actions for a planning problem, while CODE_FUNC describes the implementation of a simulation task.
4. **Detail Level**: TASK includes specific predicates, actions, and preconditions, while CODE_FUNC provides a high-level overview of the steps involved in the simulation without detailing the underlying logic or conditions.
5. **Execution**: TASK is meant to be executed by a planner that interprets PDDL, while CODE_FUNC is intended to be executed as a program or script in a programming environment.
6. **Focus**: TASK focuses on the logical structure and requirements of the task, while CODE_FUNC emphasizes the procedural steps and flow of execution in a simulation context.
7. **State Representation**: TASK explicitly defines the initial state and conditions for actions, while CODE_FUNC describes the process without detailing the state representation.
8. **Outcome Handling**: TASK does not specify how to handle outcomes or results, while CODE_FUNC mentions checking for task completion and printing messages based on the outcome.

Overall, the two serve different purposes and are structured differently, reflecting their roles in planning versus simulation.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment
from skill_code import rotate, move, pick, pull
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define the positions for the drawers
        middle_anchor_pos = positions['middle_anchor_pos']
        side_pos_middle = positions['middle_side_pos']

        # === Execute the Plan ===
        # Step 1: Rotate the gripper to the correct orientation
        obs, reward, done = rotate(env, task, target_quat=np.array([0, 0, 0, 1]))  # Assuming zero rotation is needed
        if done:
            print("[Task] Task ended after rotating!")
            return

        # Step 2: Move to the side position of the middle drawer
        obs, reward, done = move(env, task, target_pos=side_pos_middle)
        if done:
            print("[Task] Task ended after moving to side position!")
            return

        # Step 3: Move to the anchor position of the middle drawer
        obs, reward, done = move(env, task, target_pos=middle_anchor_pos)
        if done:
            print("[Task] Task ended after moving to anchor position!")
            return

        # Step 4: Pick the middle drawer
        obs, reward, done = pick(env, task, target_pos=middle_anchor_pos)
        if done:
            print("[Task] Task ended after picking the drawer!")
            return

        # Step 5: Pull the middle drawer open
        obs, reward, done = pull(env, task, pull_distance=0.1)  # Assuming a pull distance of 0.1
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")
-------------------

=== Instruction 3 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving a robotic gripper interacting with a drawer. It begins by setting up the environment and resetting the task to its initial state. It optionally initializes video recording for the simulation. The function retrieves the positions of relevant objects, specifically the drawer's anchor and side positions.

The task consists of several key steps: first, the gripper is rotated to a specified orientation; next, it moves to the side position of the bottom drawer; then, it moves to the anchor position of the drawer. After reaching the anchor position, the gripper attempts to pick up the drawer and finally pulls the drawer open by a specified distance. Throughout the process, the function checks if the task is completed after each step and prints appropriate messages. Finally, it ensures that the environment is properly shut down after the task execution.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Definition**: TASK is a PDDL domain and problem definition for a specific task involving a gripper and drawers, while CODE_FUNC describes a function that implements a simulation of that task.
2. **Format**: TASK is structured in a formal PDDL syntax, whereas CODE_FUNC is written in a programming language format (likely Python or similar).
3. **Purpose**: TASK defines the rules, actions, and states for a planning problem, while CODE_FUNC outlines the procedural steps to execute the task in a simulation environment.
4. **Components**: TASK includes types, predicates, and actions with preconditions and effects, while CODE_FUNC focuses on the sequence of operations and interactions without formal preconditions and effects.
5. **Execution**: TASK is meant for a planner to generate a sequence of actions based on the defined domain, while CODE_FUNC is an executable function that directly performs the actions in a simulation.
6. **State Management**: TASK defines the initial state and the effects of actions in a declarative manner, while CODE_FUNC manages state changes imperatively through function calls and checks.
7. **Output**: TASK does not specify output messages or feedback, while CODE_FUNC includes print statements to provide feedback during execution.
8. **Environment Setup**: TASK does not include any setup or teardown processes, while CODE_FUNC explicitly mentions initializing the environment and shutting it down after execution.
9. **Simulation Aspect**: TASK is purely a planning domain, while CODE_FUNC involves running a simulation, which may include visual or interactive elements.
10. **Flexibility**: TASK is more abstract and can be used with different planners, while CODE_FUNC is specific to a particular implementation and may not be easily adaptable to other contexts without modification.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment
from skill_code import *
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define the positions for the drawer and gripper
        bottom_anchor_pos = positions['bottom_anchor_pos']
        side_pos_bottom = positions['bottom_side_pos']

        # === Execute the Plan ===
        # Step 1: Rotate the gripper to the correct orientation (not specified, assuming zero_deg)
        obs, _, done = rotate(env, task, target_quat=np.array([0, 0, 0, 1]))  # Assuming no rotation needed
        if done:
            print("[Task] Task ended after rotating!")
            return

        # Step 2: Move to the side position of the bottom drawer
        obs, _, done = move(env, task, target_pos=side_pos_bottom)
        if done:
            print("[Task] Task ended after moving to side position!")
            return

        # Step 3: Move to the anchor position of the bottom drawer
        obs, _, done = move(env, task, target_pos=bottom_anchor_pos)
        if done:
            print("[Task] Task ended after moving to anchor position!")
            return

        # Step 4: Pick the bottom drawer
        obs, _, done = pick(env, task, target_pos=bottom_anchor_pos)
        if done:
            print("[Task] Task ended after picking the drawer!")
            return

        # Step 5: Pull the drawer to open it
        obs, _, done = pull(env, task, pull_distance=0.1)  # Assuming a pull distance of 0.1
        if done:
            print("[Task] Task completed successfully! Drawer is now open.")
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")

if __name__ == "__main__":
    run_skeleton_task()
-------------------

=== Instruction 4 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving a robotic gripper interacting with a drawer. It begins by setting up the environment and resetting the task to its initial state. It optionally initializes video recording for the simulation. The function retrieves the positions of objects in the environment, specifically the positions for the middle drawer.

The task consists of several key steps: first, the gripper is rotated to the correct orientation; next, it moves to the side position of the middle drawer; then, it moves to the anchor position of the middle drawer. After reaching the anchor position, the gripper picks up the middle drawer and finally pulls it open by a specified distance. At each step, the function checks if the task is completed and prints appropriate messages. The environment is ensured to be shut down properly at the end of the task.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - TASK describes a specific goal (unlocking a cabinet by opening a drawer) in a formalized planning domain.
   - CODE_FUNC outlines a procedural function for simulating the task with a robotic gripper.

2. **Structure**: 
   - TASK is structured in PDDL (Planning Domain Definition Language) format, defining actions, predicates, and types.
   - CODE_FUNC is written in a programming language format, detailing a sequence of operations and checks.

3. **Level of Abstraction**: 
   - TASK operates at a high level of abstraction, focusing on the planning and logical conditions required to achieve the goal.
   - CODE_FUNC operates at a lower level, detailing the implementation steps and interactions with the environment.

4. **Execution**: 
   - TASK does not specify how the actions are executed; it only defines what actions can be taken and under what conditions.
   - CODE_FUNC specifies the sequence of actions to be executed, including initialization and completion checks.

5. **Environment Interaction**: 
   - TASK defines the environment in terms of states and actions without detailing how to interact with it.
   - CODE_FUNC includes specific interactions with the environment, such as retrieving object positions and managing video recording.

6. **Feedback Mechanism**: 
   - TASK does not include any feedback or logging mechanisms.
   - CODE_FUNC includes print statements to provide feedback on the task's progress and completion.

7. **Initialization**: 
   - TASK does not mention any initialization steps beyond defining the initial state in the problem.
   - CODE_FUNC explicitly mentions resetting the task to its initial state and optionally initializing video recording.

8. **Completion Check**: 
   - TASK does not include any mechanism for checking if the task is completed.
   - CODE_FUNC includes checks to determine if the task has been completed at each step.

9. **Specificity of Actions**: 
   - TASK defines actions in a general sense (e.g., rotate, move-to-side, pick, pull) without implementation details.
   - CODE_FUNC specifies the exact sequence and conditions under which these actions are performed in a simulation context.

10. **Output**: 
    - TASK does not produce any output; it is a formal definition.
    - CODE_FUNC produces output in the form of printed messages indicating the status of the task.

In summary, the semantic differences between TASK and CODE_FUNC are significant, reflecting their distinct purposes and levels of detail in describing the task of unlocking a cabinet by opening a drawer.

Refined Code Generated:
-------------------
import numpy as np
from env import setup_environment, shutdown_environment
from skill_code import rotate, move, pick, pull
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define the positions for the drawers
        middle_anchor_pos = positions['middle_anchor_pos']
        side_pos_middle = positions['middle_side_pos']

        # === Execute the Plan ===
        # Step 1: Rotate the gripper to the correct orientation
        obs, reward, done = rotate(env, task, target_quat=np.array([0, 0, 0, 1]))
        if done:
            print("[Task] Task ended after rotation!")
            return

        # Step 2: Move to the side position of the middle drawer
        obs, reward, done = move(env, task, target_pos=side_pos_middle)
        if done:
            print("[Task] Task ended after moving to side position!")
            return

        # Step 3: Move to the anchor position of the middle drawer
        obs, reward, done = move(env, task, target_pos=middle_anchor_pos)
        if done:
            print("[Task] Task ended after moving to anchor position!")
            return

        # Step 4: Pick the middle drawer
        obs, reward, done = pick(env, task, target_pos=middle_anchor_pos)
        if done:
            print("[Task] Task ended after picking the drawer!")
            return

        # Step 5: Pull the middle drawer to open it
        obs, reward, done = pull(env, task, pull_distance=0.1)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")
-------------------

=== Instruction 5 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving a robotic gripper interacting with a drawer. It begins by setting up the environment and resetting the task to its initial state. Video recording is optionally initialized to capture the simulation. The function retrieves the positions of various objects, specifically the positions of the drawers.

The task consists of several key steps: first, the gripper is rotated to a ninety-degree angle. Next, the gripper moves to the side position of the middle drawer, followed by moving to the anchor position of the same drawer. The gripper then attempts to pick up the middle drawer and finally pulls it to open it. After each step, the function checks if the task is completed and prints appropriate messages. 

Regardless of the outcome, the environment is ensured to be properly shut down at the end of the task. The function is executed when the script is run as the main program.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Nature of Content**: TASK is a formal representation of a planning problem in PDDL (Planning Domain Definition Language), while CODE_FUNC is a description of a procedural function that outlines steps for executing a simulation task.
2. **Format**: TASK is structured in a domain-specific language (PDDL) with defined predicates, actions, and preconditions, whereas CODE_FUNC is written in a narrative format describing the function's behavior and steps.
3. **Purpose**: TASK defines the rules and conditions for a planning problem, focusing on the logical structure of actions and their effects. CODE_FUNC describes the implementation of a simulation task, detailing how the actions are executed in a programming context.
4. **Execution**: TASK does not specify how the actions are executed; it only defines what actions can be taken under what conditions. CODE_FUNC explicitly describes the sequence of actions and their execution in a simulation environment.
5. **State Representation**: TASK uses predicates to represent the state of the world (e.g., whether a drawer is open or locked), while CODE_FUNC describes the state in terms of the simulation's progress and the actions taken by the gripper.
6. **Level of Abstraction**: TASK operates at a higher level of abstraction, focusing on planning and logical reasoning, while CODE_FUNC operates at a lower level, detailing specific procedural steps and interactions with the environment.
7. **Output**: TASK does not produce output in the traditional sense; it is a model for planning. CODE_FUNC includes output in the form of printed messages indicating the progress and completion of the task.

Overall, the two serve different purposes within the context of robotics and simulation, with TASK focusing on planning and CODE_FUNC on execution.

Refined Code Generated:
-------------------
import numpy as np
from env import setup_environment, shutdown_environment
from skill_code import pick, pull, rotate, move
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define the positions for the drawers
        middle_anchor_pos = positions['middle_anchor_pos']

        # === Execute the Plan ===
        # Step 1: Rotate the gripper to ninety degrees
        print("[Task] Rotating gripper to ninety degrees.")
        obs, reward, done = rotate(env, task, target_quat=np.array([0, 0, 1, 0]), 
                                   max_steps=100, threshold=0.05, timeout=10.0)
        if done:
            print("[Task] Task ended after rotating!")
            return

        # Step 2: Move to the side position of the middle drawer
        print("[Task] Moving to side position of the middle drawer.")
        obs, reward, done = move(env, task, target_pos=positions['middle_side_pos'], 
                                 max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Task ended after moving to side position!")
            return

        # Step 3: Move to the anchor position of the middle drawer
        print("[Task] Moving to anchor position of the middle drawer.")
        obs, reward, done = move(env, task, target_pos=middle_anchor_pos, 
                                 max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Task ended after moving to anchor position!")
            return

        # Step 4: Pick the middle drawer
        print("[Task] Picking the middle drawer.")
        obs, reward, done = pick(env, task, target_pos=middle_anchor_pos, 
                                 approach_distance=0.15, max_steps=100, 
                                 threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Task ended after picking!")
            return

        # Step 5: Pull the middle drawer to open it
        print("[Task] Pulling the middle drawer to open it.")
        obs, reward, done = pull(env, task, pull_distance=0.1, pull_axis='y', 
                                 max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")
-------------------

