=== Instruction 1 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task in a robotic environment. 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 various objects needed for the task.

The task consists of a series of steps: first, it closes a gripper, then presses a switch to turn on a light, picks up an item (referred to as item1), places that item on a plate, picks up another item (tomato2), and finally places tomato2 on the plate. After each action, it checks if the task is completed and prints appropriate messages. If the task ends at any step, it exits early. Finally, it ensures that the environment is properly shut down after the task is completed or if an error occurs. The function is executed when the script is run directly.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - TASK describes a specific instruction for a robot to perform (putting tomatoes on a plate).
   - CODE_FUNC outlines a function that simulates a series of actions in a robotic environment.

2. **Structure**: 
   - TASK is defined using PDDL (Planning Domain Definition Language) with a focus on actions, preconditions, and effects.
   - CODE_FUNC is a narrative description of a function that includes procedural steps and logic for executing a task.

3. **Content**: 
   - TASK includes definitions of actions (pick, place, close_gripper, press) with their respective parameters, preconditions, and effects.
   - CODE_FUNC describes a sequence of actions without detailing the underlying logic or conditions for each action.

4. **Execution**: 
   - TASK is a declarative representation that can be used by a planner to generate a sequence of actions.
   - CODE_FUNC is an imperative representation that describes how to execute a series of actions in a specific order.

5. **Environment Interaction**: 
   - TASK specifies the conditions under which actions can be performed based on the state of the environment (e.g., dark, handempty).
   - CODE_FUNC describes the execution of actions but does not explicitly define the conditions under which each action is valid.

6. **Output**: 
   - TASK does not specify any output or feedback mechanism.
   - CODE_FUNC includes feedback mechanisms (e.g., printing messages) to indicate the status of the task after each action.

7. **Error Handling**: 
   - TASK does not address error handling or task termination conditions.
   - CODE_FUNC includes logic for early termination of the task and proper shutdown of the environment in case of errors.

8. **Initialization**: 
   - TASK does not include any initialization steps or setup for the environment.
   - CODE_FUNC mentions resetting the task to its initial state and optionally initializing video recording.

9. **Object Handling**: 
   - TASK defines objects and their states in a static manner.
   - CODE_FUNC describes dynamic interactions with objects (e.g., picking up and placing items) in a procedural context.

10. **Focus**: 
    - TASK focuses on the planning aspect of robotic actions.
    - CODE_FUNC focuses on the execution aspect of those actions in a simulation environment.

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 close_gripper, press, pick, place
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 object positions
        item1_pos = positions['item1']
        tomato2_pos = positions['tomato2']
        plate_pos = positions['plate']
        switch_pos = positions['switch']

        # === Execute the Plan ===
        # Step 1: Close the gripper
        print("[Task] Closing gripper...")
        obs, reward, done = close_gripper(env, task)
        if done:
            print("[Task] Task ended after closing gripper!")
            return

        # Step 2: Press the switch to turn on the light
        print("[Task] Pressing the switch...")
        obs, reward, done = press(env, task, switch_pos)
        if done:
            print("[Task] Task ended after pressing the switch!")
            return

        # Step 3: Pick item1 (tomato1)
        print("[Task] Picking item1...")
        obs, reward, done = pick(env, task, item1_pos)
        if done:
            print("[Task] Task ended after picking item1!")
            return

        # Step 4: Place item1 on the plate
        print("[Task] Placing item1 on the plate...")
        obs, reward, done = place(env, task, plate_pos)
        if done:
            print("[Task] Task ended after placing item1!")
            return

        # Step 5: Pick tomato2
        print("[Task] Picking tomato2...")
        obs, reward, done = pick(env, task, tomato2_pos)
        if done:
            print("[Task] Task ended after picking tomato2!")
            return

        # Step 6: Place tomato2 on the plate
        print("[Task] Placing tomato2 on the plate...")
        obs, reward, done = place(env, task, plate_pos)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
            return
        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 2 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving picking and placing an object. It begins by setting up the environment and resetting the task to its initial state. It initializes video recording capabilities and retrieves the positions of relevant objects in the environment. 

The task consists of a series of steps where the program attempts to pick a second tomato from a table and place it onto a plate. If the task is completed successfully at any step, it prints a success message and exits. If the first attempt fails, it repeats the pick and place actions. 

Finally, the environment is shut down properly after the task is completed or if an error occurs. The function is executed when the script is run as the main program.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - TASK defines a formal problem in PDDL for a robot to perform actions in a specific environment.
   - CODE_FUNC describes a procedural function that simulates the task of picking and placing objects programmatically.

2. **Structure**: 
   - TASK is structured in a declarative format using PDDL, focusing on defining actions, predicates, and the initial state.
   - CODE_FUNC is structured in an imperative programming style, detailing step-by-step instructions for executing the task.

3. **Execution**: 
   - TASK does not execute actions; it merely specifies what actions can be taken under what conditions.
   - CODE_FUNC actively executes the actions of picking and placing objects, including handling success and failure scenarios.

4. **Environment Setup**: 
   - TASK includes a detailed definition of the environment, including types and predicates relevant to the robot's actions.
   - CODE_FUNC mentions setting up the environment but does not define it in the same formal way as TASK.

5. **Error Handling**: 
   - TASK does not include any error handling or recovery mechanisms; it simply defines the conditions under which actions can be performed.
   - CODE_FUNC includes logic to handle failures and retries when attempting to pick and place the tomato.

6. **Output**: 
   - TASK does not produce any output; it is a static definition of a problem.
   - CODE_FUNC includes print statements to indicate success or failure during the execution of the task.

7. **Focus on Actions**: 
   - TASK focuses on the definitions of actions (pick, place, etc.) and their preconditions and effects.
   - CODE_FUNC focuses on the sequence of executing those actions in a simulation context.

8. **State Management**: 
   - TASK defines the initial state and the effects of actions on that state in a logical manner.
   - CODE_FUNC manages state through procedural code, resetting and updating the environment as the task progresses.

9. **Language**: 
   - TASK is written in PDDL, a language specifically designed for planning problems.
   - CODE_FUNC is written in a programming language (not specified, but likely Python or similar), which is used for scripting and simulation.

10. **Flexibility**: 
    - TASK is more flexible in terms of defining various scenarios and can be adapted for different planning problems.
    - CODE_FUNC is more rigid, as it follows a specific sequence of actions for a defined task without the same level of abstraction.

In summary, the semantic differences between TASK and CODE_FUNC are significant, reflecting their different purposes, structures, and execution methods.

Refined Code Generated:
-------------------
import numpy as np
from env import setup_environment, shutdown_environment
from skill_code import pick, place
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 object positions
        plate_pos = positions['plate']
        tomato2_pos = positions['tomato2']

        # === Execute the Plan ===
        # Step 1: Pick the second tomato from the table
        print("[Task] Picking tomato2 from the table.")
        obs, reward, done = pick(env, task, target_pos=tomato2_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 tomato2!")
            return

        # Step 2: Place the tomato onto the plate
        print("[Task] Placing tomato2 onto the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
            return

        # Step 3: Pick the second tomato from the table again (if needed)
        print("[Task] Picking tomato2 from the table again.")
        obs, reward, done = pick(env, task, target_pos=tomato2_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 tomato2 again!")
            return

        # Step 4: Place the tomato onto the plate again
        print("[Task] Placing tomato2 onto the plate again.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Task completed successfully on second attempt! Reward:", reward)
            return

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

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

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

=== Instruction 3 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving picking up and placing an object. 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 specific objects, namely a tomato and a plate. 

The task consists of two main steps: first, it attempts to pick up the tomato from its designated position, and if successful, it proceeds to place the tomato on the plate. After each action, it checks if the task is completed and prints relevant messages. Finally, it ensures that the environment is properly shut down after the task execution. The function is executed when the script is run as the main program.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: TASK describes a specific instruction for a robot to perform (picking up tomatoes and placing them on a plate), while CODE_FUNC outlines a function that simulates the execution of such a task in a programming context.
2. **Structure**: TASK is structured in PDDL (Planning Domain Definition Language) format, defining actions, predicates, and the problem domain, whereas CODE_FUNC is written in a programming language (likely Python) and describes a function with procedural steps.
3. **Detail Level**: TASK provides detailed preconditions and effects for actions in a formalized way, while CODE_FUNC gives a high-level overview of the simulation process without detailing the underlying logic or conditions.
4. **Execution Context**: TASK is a declarative specification meant for planning and execution by a robot, while CODE_FUNC is an imperative function that runs a simulation, likely in a software environment.
5. **Focus**: TASK focuses on the logical representation of actions and their conditions, while CODE_FUNC focuses on the procedural steps to execute those actions in a simulated environment.
6. **Output**: TASK does not specify any output or feedback mechanism, while CODE_FUNC includes print statements to provide feedback on the task's progress and completion.
7. **Environment Setup**: TASK includes the initial state of the environment in a formalized way, while CODE_FUNC describes the setup and reset of the environment in a more narrative form.
8. **Error Handling**: TASK does not address error handling or failure conditions, while CODE_FUNC implies checks for task completion and may include handling for success or failure of actions. 

In summary, the two are fundamentally different in purpose, structure, detail, execution context, focus, output, environment setup, and error handling.

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 pick, place
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
        descriptions, 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 object positions
        tomato2_pos = positions['tomato2']
        plate_pos = positions['plate']

        # === Execute Task Plan ===
        # Step 1: Pick up the tomato
        print("[Task] Picking up the tomato at:", tomato2_pos)
        obs, reward, done = pick(
            env,
            task,
            target_pos=tomato2_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 up the tomato!")
            return

        # Step 2: Place the tomato on the plate
        print("[Task] Placing the tomato on the plate at:", plate_pos)
        obs, reward, done = place(
            env,
            task,
            target_pos=plate_pos,
            approach_distance=0.15,
            max_steps=100,
            threshold=0.01,
            approach_axis='z',
            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 =====")

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 object manipulation. 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 various objects needed for the task.

The task consists of a series of steps: first, it closes a gripper, then presses a switch to turn on a light, picks up the first item (a tomato), places it on a plate, picks up a second tomato, and finally places it on the plate as well. After each action, it checks if the task is completed and prints appropriate messages. If the task ends at any step, it exits early. Finally, it ensures that the environment is properly shut down after the task is completed or if an error occurs.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: TASK describes a specific instruction for transferring tomatoes, while CODE_FUNC outlines a function for simulating a series of actions to achieve a task.
2. **Structure**: TASK is presented in a PDDL format defining a domain and problem, whereas CODE_FUNC is a narrative description of a function's behavior.
3. **Detail Level**: TASK includes detailed preconditions and effects for actions in a formalized manner, while CODE_FUNC provides a high-level overview of the steps without formal preconditions or effects.
4. **Execution**: TASK is a declarative representation of actions to be taken, while CODE_FUNC describes an imperative sequence of operations to be executed in a simulation.
5. **Environment Setup**: TASK includes initial conditions and predicates relevant to the robot's environment, while CODE_FUNC mentions setting up the environment but does not detail the initial state in a formal way.
6. **Error Handling**: CODE_FUNC includes a mechanism for early exit and error handling, which is not addressed in TASK.
7. **Output**: CODE_FUNC mentions printing messages upon task completion or errors, while TASK does not specify any output or feedback mechanism.
8. **Action Sequence**: TASK specifies the action of transferring two tomatoes, while CODE_FUNC describes a sequence of actions including closing the gripper and pressing a switch, which are not mentioned in TASK.

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 object positions
        tomato1_pos = positions['item1']
        tomato2_pos = positions['tomato2']
        plate_pos = positions['plate']
        switch_pos = positions['switch']

        # Step 1: Close the gripper
        print("[Task] Closing gripper...")
        obs, reward, done = close_gripper(env, task)
        if done:
            print("[Task] Task ended after closing gripper!")
            return

        # Step 2: Press the switch to turn on the light
        print("[Task] Pressing the switch...")
        obs, reward, done = press(env, task, switch_pos)
        if done:
            print("[Task] Task ended after pressing the switch!")
            return

        # Step 3: Pick the first tomato
        print("[Task] Picking the first tomato...")
        obs, reward, done = pick(env, task, tomato1_pos)
        if done:
            print("[Task] Task ended after picking the first tomato!")
            return

        # Step 4: Place the first tomato onto the plate
        print("[Task] Placing the first tomato onto the plate...")
        obs, reward, done = place(env, task, plate_pos)
        if done:
            print("[Task] Task ended after placing the first tomato!")
            return

        # Step 5: Pick the second tomato
        print("[Task] Picking the second tomato...")
        obs, reward, done = pick(env, task, tomato2_pos)
        if done:
            print("[Task] Task ended after picking the second tomato!")
            return

        # Step 6: Place the second tomato onto the plate
        print("[Task] Placing the second tomato onto the plate...")
        obs, reward, done = place(env, task, plate_pos)
        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 picking and placing objects. 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 specific objects, namely item1, tomato2, and a plate. 

The task consists of four main steps: first, it picks item1 from the table; second, it places item1 onto the plate; third, it picks tomato2 from the table; and finally, it places tomato2 onto the plate. After each action, it checks if the task is completed and prints appropriate messages. Regardless of the outcome, the environment is shut down at the end of the function. The function is executed when the script is run directly.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: TASK defines a specific action sequence for a robot to perform (tossing tomatoes), while CODE_FUNC describes a function that simulates a broader task involving multiple objects and actions.
2. **Action Sequence**: TASK specifies a direct instruction to toss two tomatoes, whereas CODE_FUNC outlines a sequence of picking and placing actions for multiple items, including item1 and tomato2.
3. **Environment Setup**: TASK includes a PDDL domain and problem definition, focusing on the robot's capabilities and constraints, while CODE_FUNC describes the initialization of a simulation environment and the resetting of the task state.
4. **Object Handling**: TASK mentions specific objects (tomatoes) and their locations (table, plate), while CODE_FUNC refers to a broader set of objects (item1, tomato2, plate) and their interactions.
5. **Completion Check**: CODE_FUNC includes a mechanism to check if the task is completed and print messages, which is not present in TASK.
6. **Execution Context**: CODE_FUNC is designed to be executed as a function within a script, while TASK is a declarative representation of actions in a planning domain.
7. **Video Recording**: CODE_FUNC mentions optional video recording for the simulation, which is not addressed in TASK.
8. **Finalization**: CODE_FUNC includes a shutdown procedure for the environment, while TASK does not specify any finalization steps.

In summary, the two are fundamentally different in purpose, structure, and execution context.

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 pick, place
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 object positions
        tomato1_pos = positions['item1']
        tomato2_pos = positions['tomato2']
        plate_pos = positions['plate']

        # Step 1: Pick tomato1 from the table
        print("[Task] Picking tomato1 from the table.")
        obs, reward, done = pick(env, task, tomato1_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking tomato1!")
            return

        # Step 2: Place tomato1 onto the plate
        print("[Task] Placing tomato1 onto the plate.")
        obs, reward, done = place(env, task, plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after placing tomato1!")
            return

        # Step 3: Pick tomato2 from the table
        print("[Task] Picking tomato2 from the table.")
        obs, reward, done = pick(env, task, tomato2_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking tomato2!")
            return

        # Step 4: Place tomato2 onto the plate
        print("[Task] Placing tomato2 onto the plate.")
        obs, reward, done = place(env, task, plate_pos, approach_distance=0.15)
        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 =====")
-------------------

