=== Instruction 1 ===
Is Correct: False
Syntax Pass: False
Code Function: This code defines a sequence for a robot to interact with a bottom drawer. First, the robot grasps the handle of the bottom drawer. Next, it pulls the drawer open by a specified distance. If any error occurs during these actions, it is caught and printed. The sequence is executed when the script is run directly.
Similarity: {'ok': False, 'reason': "The code description does not mention turning on the light, which is required before the robot can grasp the handle and open the drawer according to the domain's preconditions."}
Differences: 1. **Level of Abstraction**  
   - TASK specifies a high-level goal: "Open one drawer," without specifying which drawer or how.
   - CODE_FUNC describes a concrete sequence for a specific drawer (the bottom drawer), including grasping its handle and pulling it open.

2. **Drawer Selection**  
   - TASK allows for any drawer to be opened.
   - CODE_FUNC only operates on the bottom drawer.

3. **Precondition Handling**  
   - TASK does not mention preconditions (e.g., light state, drawer locked/unlocked).
   - CODE_FUNC does not explicitly handle preconditions such as ensuring the room is bright or the drawer is unlocked, which are required in the domain.

4. **Error Handling**  
   - TASK does not mention error handling.
   - CODE_FUNC includes a try/except block to catch and print errors during execution.

5. **Action Granularity**  
   - TASK is a single-step instruction.
   - CODE_FUNC decomposes the task into multiple steps: grasping the handle and pulling the drawer.

6. **Object Interaction**  
   - TASK does not specify how to interact with the drawer (e.g., via handle).
   - CODE_FUNC explicitly requires grasping the handle before pulling.

7. **Parameterization**  
   - TASK is parameter-free.
   - CODE_FUNC specifies which handle and drawer, and includes a "distance" parameter for pulling.

8. **Execution Context**  
   - TASK is a declarative instruction.
   - CODE_FUNC is an imperative script, meant to be run as a program.

9. **Domain Assumptions**  
   - TASK assumes the agent will handle all necessary domain constraints.
   - CODE_FUNC assumes certain domain conditions (e.g., handle is accessible, drawer is unlocked, room is bright) but does not check or enforce them.

10. **Output/Feedback**  
    - TASK does not specify any output or feedback.
    - CODE_FUNC prints errors if they occur.

11. **Scope**  
    - TASK is open to any drawer in the environment.
    - CODE_FUNC is scoped to a specific drawer (bottom drawer) and its handle.

12. **Light Condition**  
    - TASK does not mention the need to turn on the light.
    - CODE_FUNC does not include turning on the light, which may be required per the domain.

13. **Lock State**  
    - TASK does not mention unlocking the drawer.
    - CODE_FUNC does not include unlocking the drawer if it is locked.

14. **Generalizability**  
    - TASK is general and could apply to any drawer.
    - CODE_FUNC is specific and not generalizable without modification.

15. **Completion Criteria**  
    - TASK is complete when any drawer is open.
    - CODE_FUNC is complete when the bottom drawer is open (assuming no errors).

---

**Summary:**  
The semantic differences are primarily in specificity, precondition handling, error handling, and generality. The TASK is a high-level, general instruction, while CODE_FUNC is a specific, stepwise, imperative implementation for a particular drawer, lacking explicit handling of some domain-required preconditions.

Refined Code Generated:
-------------------
from Object_list import Object
from skill_mapping import RobotController

def open_one_drawer():
    """
    Opens any one unlocked and closed drawer, ensuring all preconditions are met.
    """
    robot = RobotController()

    # Step 1: If the room is dark, turn on the light
    if robot.get_room_light_state() == "dark":
        robot.execute_movement(Object["light_switch"], mode=2, axis=1)

    # Step 2: Find any unlocked and closed drawer
    drawers = [
        ("drawer_bottom", "drawer_bottom_handle"),
        ("drawer_middle", "drawer_middle_handle"),
        ("drawer_top", "drawer_top_handle"),
    ]
    selected_drawer = None
    selected_handle = None
    for drawer, handle in drawers:
        if robot.get_drawer_lock_state(Object[drawer]) == "unlocked" and robot.get_drawer_open_state(Object[drawer]) == "closed":
            selected_drawer = drawer
            selected_handle = handle
            break

    if selected_drawer is None:
        print("No unlocked and closed drawer available to open.")
        return

    # Step 3: Pick the handle of the selected drawer
    robot.execute_movement(Object[selected_handle], mode=1, axis=0)

    # Step 4: Pull the drawer using the handle
    robot.execute_movement(Object[selected_handle], mode=4, axis=0, distance=0.1)

def main():
    """
    Main entry point to open one drawer.
    """
    open_one_drawer()

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

=== Instruction 2 ===
Is Correct: False
Syntax Pass: False
Code Function: This code defines a sequence for a robot to open the bottom drawer. It first instructs the robot to move to the bottom drawer's handle using a specific approach direction. Then, it commands the robot to pull the handle to open the drawer by a set distance. If any error occurs during these actions, it prints an error message. The sequence is executed when the script is run directly.
Similarity: {'ok': False, 'reason': 'The code does not account for turning on the light, picking up the handle, or ensuring preconditions like room brightness and holding the handle before pulling the drawer, which are required by the domain.'}
Differences: 1. **Lighting Condition**:  
   - **TASK** (PDDL) requires the room to be bright (i.e., the light must be turned on) before the drawer can be pulled open.  
   - **CODE_FUNC** does not mention or handle the lighting condition; it assumes the robot can operate regardless of room brightness.

2. **Handle Grasping**:  
   - **TASK** requires the robot to be holding the correct handle (associated with the drawer) before pulling.  
   - **CODE_FUNC** assumes the robot can pull the handle without explicitly picking it up or verifying the grasp.

3. **Drawer Lock State**:  
   - **TASK** requires the drawer to be unlocked before it can be opened.  
   - **CODE_FUNC** does not check or unlock the drawer; it assumes the drawer is already unlocked.

4. **Robot State**:  
   - **TASK** requires the robot to be at the correct location, have a free hand, and be in a specific state (e.g., robot-free, hand-empty) before performing actions.  
   - **CODE_FUNC** does not check or enforce these preconditions.

5. **Error Handling**:  
   - **CODE_FUNC** includes error handling (printing an error message if something goes wrong).  
   - **TASK** (PDDL) does not specify error handling.

6. **Parameterization**:  
   - **TASK** is abstract and parameterized over any drawer, handle, and location.  
   - **CODE_FUNC** is concrete, targeting the bottom drawer and its handle specifically.

7. **Action Granularity**:  
   - **TASK** decomposes the action into primitive steps (e.g., pick handle, move, pull).  
   - **CODE_FUNC** may combine these into higher-level commands (e.g., move and pull), possibly skipping intermediate steps.

8. **Distance Specification**:  
   - **CODE_FUNC** specifies pulling the handle by a set distance.  
   - **TASK** does not specify how far to pull, only that the drawer becomes open.

9. **Execution Trigger**:  
   - **CODE_FUNC** executes the sequence when the script is run directly.  
   - **TASK** is a declarative specification, not an executable script.

10. **Success Criteria**:  
    - **TASK** defines success as the drawer being open.  
    - **CODE_FUNC** may not explicitly check the final state, only that the actions are performed.

11. **Domain Knowledge**:  
    - **TASK** encodes domain knowledge (e.g., which handle belongs to which drawer, drawer states).  
    - **CODE_FUNC** may hardcode these associations or assume them.

12. **Multiple Drawers**:  
    - **TASK** is general for any drawer.  
    - **CODE_FUNC** is specific to the bottom drawer.

13. **Initial State Handling**:  
    - **TASK** assumes and checks initial states (e.g., robot location, drawer state, room brightness).  
    - **CODE_FUNC** may not check or set up the initial state.

14. **Conditional Effects**:  
    - **TASK** can express conditional effects (e.g., updating drawer fullness).  
    - **CODE_FUNC** does not model or update such state transitions.

15. **Physical Constraints**:  
    - **TASK** models physical constraints (e.g., must be holding the handle, must be at the location).  
    - **CODE_FUNC** may not enforce these constraints.

16. **Language/Representation**:  
    - **TASK** is in PDDL (declarative planning language).  
    - **CODE_FUNC** is in imperative code (likely Python).

17. **Observation/Feedback**:  
    - **TASK** does not specify observation or feedback.  
    - **CODE_FUNC** may print errors or status.

18. **Concurrency/Atomicity**:  
    - **TASK** actions are atomic and sequential.  
    - **CODE_FUNC** may or may not handle concurrency.

19. **Extensibility**:  
    - **TASK** is easily extensible to other drawers or handles.  
    - **CODE_FUNC** would require code changes for other drawers.

20. **Explicitness of Preconditions**:  
    - **TASK** explicitly lists all preconditions for each action.  
    - **CODE_FUNC** may implicitly assume preconditions are met.

---

**Summary**:  
The main semantic differences are in precondition checking (lighting, handle grasp, lock state), abstraction/generalization, error handling, and explicitness of state and actions.

Refined Code Generated:
-------------------
from Object_list import Object
from skill_mapping import RobotController

def long_horizon_task2_oracle_seq():
    """
    Pull open a single drawer (bottom drawer) following all domain preconditions.
    """
    robot = RobotController()

    try:
        # Step 1: Move to the light switch location and turn on the light if the room is dark
        robot.execute_movement(Object["light_switch"], mode=1, axis=0)
        robot.execute_push_switch(Object["light_switch"])

        # Step 2: Move to the bottom drawer area if not already there
        robot.execute_movement(Object["drawer_area"], mode=1, axis=0)

        # Step 3: Pick up the handle of the bottom drawer
        robot.execute_pick(Object["handle_bottom"])

        # Step 4: Pull to open the bottom drawer using the handle
        robot.execute_pull(Object["drawer_bottom"], Object["handle_bottom"])

    except Exception as error:
        print(f"Error during task execution: {error}")

def main():
    """
    Main entry point for pulling open a single drawer.
    """
    long_horizon_task2_oracle_seq()

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

=== Instruction 3 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to perform a two-step task. First, the robot grasps the handle of the bottom drawer by approaching it along the x-axis. Next, the robot pulls the drawer open by moving the handle along the same axis for a specified distance. If any error occurs during these actions, it is caught and printed.
Similarity: {'ok': True, 'reason': "The code describes grasping the handle and pulling the drawer open, which matches the task of sliding one drawer open according to the domain's required actions."}
Differences: 1. **Specificity of Drawer**  
   - TASK: Refers generically to "one drawer" without specifying which drawer.
   - CODE_FUNC: Explicitly operates on the "bottom drawer" (drawer_bottom).

2. **Handle Grasping**  
   - TASK: Does not mention the need to grasp a handle; only instructs to open a drawer.
   - CODE_FUNC: Explicitly includes the step of grasping the handle before opening.

3. **Approach and Movement Details**  
   - TASK: Abstract instruction; does not specify how to approach or manipulate the drawer.
   - CODE_FUNC: Specifies approaching the handle along the x-axis and pulling along the same axis for a set distance.

4. **Error Handling**  
   - TASK: No mention of error handling or contingencies.
   - CODE_FUNC: Includes error catching and printing if an error occurs during execution.

5. **Lighting/Room State**  
   - TASK: Does not mention environmental conditions (e.g., lighting).
   - CODE_FUNC: Does not mention lighting either, but the PDDL domain requires the room to be bright for opening drawers, which is not handled in CODE_FUNC.

6. **Action Granularity**  
   - TASK: High-level, single-step instruction.
   - CODE_FUNC: Breaks down into multiple low-level actions (approach, grasp, pull, error handling).

7. **Object Generality**  
   - TASK: Applies to any drawer.
   - CODE_FUNC: Hardcoded to the bottom drawer and its handle.

8. **Precondition Satisfaction**  
   - TASK: Assumes all preconditions (e.g., unlocked, not full, etc.) are met or irrelevant.
   - CODE_FUNC: Does not check or ensure preconditions like unlocked state, room brightness, or robot state.

9. **Effect Scope**  
   - TASK: Only requires the drawer to be open at the end.
   - CODE_FUNC: May leave the robot still holding the handle, depending on implementation, whereas the PDDL expects the robot to release the handle after opening.

10. **Domain Knowledge Usage**  
    - TASK: Abstract, does not reference domain-specific predicates or actions.
    - CODE_FUNC: Implicitly assumes knowledge of robot kinematics and handle manipulation, but not the full PDDL domain logic (e.g., light switch, hand state).

11. **Location Handling**  
    - TASK: Does not specify robot location.
    - CODE_FUNC: Specifies approach along a particular axis, implying spatial reasoning.

12. **Multiple Drawers**  
    - TASK: Could apply to any of several drawers.
    - CODE_FUNC: Only applies to the bottom drawer.

13. **Handle Identification**  
    - TASK: Does not mention handles.
    - CODE_FUNC: Explicitly identifies and manipulates the handle.

14. **Postconditions**  
    - TASK: Drawer is open.
    - CODE_FUNC: Drawer is open, but may not ensure all PDDL postconditions (e.g., hand-empty, robot-free).

15. **Language/Format**  
    - TASK: Natural language instruction.
    - CODE_FUNC: Procedural code description.

16. **Error Recovery**  
    - TASK: No error recovery.
    - CODE_FUNC: Catches and prints errors, but does not attempt recovery.

17. **Parameterization**  
    - TASK: No parameters specified.
    - CODE_FUNC: Hardcoded parameters (bottom drawer, x-axis, distance).

18. **Assumed Initial State**  
    - TASK: No assumptions about initial state.
    - CODE_FUNC: Assumes robot can approach and grasp handle without specifying initial state.

19. **Action Sequence**  
    - TASK: Single action.
    - CODE_FUNC: Sequence of actions (approach, grasp, pull).

20. **Object Manipulation**  
    - TASK: Manipulation is abstract.
    - CODE_FUNC: Manipulation is explicit (handle, axis, distance).

---

These differences cover all semantic distinctions between the TASK and CODE_FUNC as described.

Refined Code Generated:
-------------------
"""Module to slide open any one drawer, ensuring all necessary preconditions are met."""
from object_list import Object
from skill_mapping import RobotController

def slide_one_drawer_open():
    """Slides open any one closed and unlocked drawer, ensuring room is bright and robot is free."""
    robot = RobotController()

    # Step 1: Ensure the room is bright
    if robot.get_room_light_state() == "dark":
        robot.execute_push_switch(Object["light_switch"], Object["ready-pose"])

    # Step 2: Find a closed and unlocked drawer
    drawers = ["drawer_bottom", "drawer_middle", "drawer_top"]
    handles = {
        "drawer_bottom": "handle_bottom",
        "drawer_middle": "handle_middle",
        "drawer_top": "handle_top"
    }
    selected_drawer = None
    for drawer in drawers:
        if robot.is_drawer_closed(drawer) and robot.is_drawer_unlocked(drawer):
            selected_drawer = drawer
            break

    if selected_drawer is None:
        print("No closed and unlocked drawer available to open.")
        return

    handle = handles[selected_drawer]

    # Step 3: Pick the handle
    if not robot.is_holding(handle):
        if not robot.is_on_floor(handle):
            print(f"Handle {handle} is not accessible.")
            return
        robot.execute_pick(Object[handle], Object["ready-pose"])

    # Step 4: Pull the drawer open
    robot.execute_pull(selected_drawer, handle, Object["ready-pose"])

def main():
    """Main entry point to slide one drawer open."""
    slide_one_drawer_open()

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

=== Instruction 4 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to perform a two-step task involving a drawer. First, the robot moves to grasp the handle of the bottom drawer using a specific approach direction. Next, the robot pulls the handle to open the drawer by a set distance. If any error occurs during these actions, it is caught and printed.
Similarity: {'ok': False, 'reason': 'The code does not turn on the light before attempting to open the drawer, but the domain requires the room to be bright to open a drawer.'}
Differences: 1. **Specificity of Drawer**  
   - TASK: Refers generically to "one of the drawers" (any drawer).
   - CODE_FUNC: Refers specifically to the "bottom drawer".

2. **Level of Abstraction**  
   - TASK: High-level, natural language instruction ("Open up one of the drawers").
   - CODE_FUNC: Low-level, stepwise robot control (move to handle, grasp, pull by distance).

3. **Action Decomposition**  
   - TASK: Single, atomic instruction (open a drawer).
   - CODE_FUNC: Decomposes into sub-actions: approach, grasp, pull.

4. **Error Handling**  
   - TASK: No mention of error handling.
   - CODE_FUNC: Explicitly catches and prints errors during execution.

5. **Parameterization**  
   - TASK: No parameters specified (which drawer, how far to open, etc.).
   - CODE_FUNC: Specifies which drawer (bottom), which handle, approach direction, and pull distance.

6. **Implicit Preconditions**  
   - TASK: Assumes necessary preconditions (e.g., light is on, drawer is unlocked, robot is at correct location) without stating them.
   - CODE_FUNC: May implicitly handle preconditions via code structure, but not explicitly stated in the description.

7. **Object Interaction**  
   - TASK: Does not specify how the drawer is opened (e.g., by handle, by pushing/pulling).
   - CODE_FUNC: Specifies opening by grasping the handle and pulling.

8. **Domain Knowledge**  
   - TASK: Does not reference domain-specific objects (e.g., handle, approach direction).
   - CODE_FUNC: References domain-specific objects and actions (handle, approach direction, pull distance).

9. **Outcome Specification**  
   - TASK: Only specifies the end state (drawer open).
   - CODE_FUNC: Specifies the process to reach the end state (grasp, pull, error handling).

10. **Robustness**  
    - TASK: No mention of robustness or contingencies.
    - CODE_FUNC: Includes error handling for robustness.

11. **Ambiguity**  
    - TASK: Ambiguous as to which drawer and how to open.
    - CODE_FUNC: Unambiguous, fully specified for the bottom drawer.

12. **Temporal Structure**  
    - TASK: No explicit temporal structure.
    - CODE_FUNC: Sequential, stepwise temporal structure (first grasp, then pull).

13. **Physical Parameters**  
    - TASK: No mention of physical parameters (distance, force, etc.).
    - CODE_FUNC: Specifies pull distance.

14. **Reusability**  
    - TASK: Generic, reusable for any drawer.
    - CODE_FUNC: Hardcoded for the bottom drawer and its handle.

15. **Error Reporting**  
    - TASK: No error reporting.
    - CODE_FUNC: Prints errors if they occur.

---

**Summary:**  
The TASK is a high-level, generic, ambiguous instruction, while the CODE_FUNC is a low-level, specific, stepwise, robust implementation for a particular drawer, including error handling and physical parameters.

Refined Code Generated:
-------------------
"""Module to open one of the drawers using the robot controller."""

from Object_list import Object
from skill_mapping import RobotController

def open_one_drawer():
    """Open one of the drawers (generic, any available drawer)."""
    robot = RobotController()

    try:
        # Step 1: If the room is dark, turn on the light
        if robot.is_room_dark():
            robot.execute_push_switch(Object["light_switch"], Object["ready-pose"])

        # Step 2: Select an unlocked and closed drawer (generic)
        candidate_drawers = [
            ("drawer_bottom", "handle_bottom"),
            ("drawer_middle", "handle_middle"),
            ("drawer_top", "handle_top"),
        ]
        drawer_to_open = None
        handle_to_use = None
        for drawer_name, handle_name in candidate_drawers:
            if robot.is_drawer_unlocked(drawer_name) and robot.is_drawer_closed(drawer_name):
                drawer_to_open = drawer_name
                handle_to_use = handle_name
                break

        if drawer_to_open is None or handle_to_use is None:
            print("No unlocked and closed drawer available to open.")
            return

        # Step 3: Pick the handle of the selected drawer
        robot.execute_movement(Object[handle_to_use], mode=1, axis=0)

        # Step 4: Pull to open the selected drawer
        robot.execute_movement(Object[handle_to_use], mode=4, distance=0.1)

    except Exception as error:
        print(f"Error during task execution: {error}")

def main():
    """Main entry point to open one of the drawers."""
    open_one_drawer()

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

=== Instruction 5 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to perform a two-step task involving a drawer. First, the robot grasps the bottom handle of a drawer. Next, the robot pulls the handle to open the drawer by a specified distance. The code handles possible errors during each step and prints error messages if any issues occur.
Similarity: {'ok': False, 'reason': 'The code only describes grasping the handle and pulling it, but in this domain, the robot must first turn on the light before it can open the drawer, which the code does not mention.'}
Differences: 1. **Explicitness of Light Condition**  
   - TASK: The instruction "Uncover a drawer by opening it" does not specify any requirement about the room's lighting condition.
   - CODE_FUNC: The code does not mention or handle the need to turn on the light before acting, but the PDDL domain requires the room to be bright for opening the drawer (via `execute_pull`).

2. **Handle Grasping**  
   - TASK: The instruction does not mention the need to grasp a handle; it simply says to open the drawer.
   - CODE_FUNC: The code explicitly includes a step to grasp the bottom handle before pulling.

3. **Drawer Selection**  
   - TASK: The instruction refers generically to "a drawer" without specifying which one.
   - CODE_FUNC: The code specifically targets the "bottom" drawer and its handle.

4. **Error Handling**  
   - TASK: The instruction does not mention error handling.
   - CODE_FUNC: The code includes error handling for each step and prints error messages if issues occur.

5. **Partial Opening**  
   - TASK: The instruction does not specify how far to open the drawer.
   - CODE_FUNC: The code opens the drawer "by a specified distance," implying partial or controlled opening.

6. **Object Manipulation**  
   - TASK: The instruction only requires opening the drawer, not manipulating any objects.
   - CODE_FUNC: The code includes grasping an object (the handle) as part of the process.

7. **Step Granularity**  
   - TASK: The instruction is a single high-level action.
   - CODE_FUNC: The code decomposes the task into two explicit steps: grasping and pulling.

8. **Assumed Preconditions**  
   - TASK: The instruction assumes the drawer can be opened without specifying preconditions (e.g., unlocked, closed, handle accessible).
   - CODE_FUNC: The code assumes the handle is accessible and the drawer can be pulled, but does not check for lock state or other preconditions.

9. **Feedback/Output**  
   - TASK: The instruction does not specify any feedback or output.
   - CODE_FUNC: The code prints error messages if steps fail.

10. **Domain Knowledge**  
    - TASK: The instruction is domain-agnostic and could apply to any drawer.
    - CODE_FUNC: The code is tailored to a robot in a specific environment with a bottom drawer and handle.

---

**Summary:**  
The main semantic differences are in explicitness of steps, error handling, specificity of the drawer and handle, handling of lighting conditions, and granularity of actions.

Refined Code Generated:
-------------------
"""Module to uncover a drawer by opening it, following domain constraints."""

from Object_list import Object
from skill_mapping import RobotController

def long_horizon_task2_oracle_seq():
    """Sequence to open a drawer, ensuring all domain preconditions are met."""
    robot = RobotController()

    # Step 1: Move to the light switch location and turn on the light if needed
    robot.execute_movement(Object["light_switch"], mode=0)  # Move to light switch
    robot.execute_movement(Object["light_switch"], mode=2)  # Push the switch to turn on the light

    # Step 2: Move to the handle location and pick the handle
    robot.execute_movement(Object["drawer_bottom_handle"], mode=0)  # Move to handle
    robot.execute_movement(Object["drawer_bottom_handle"], mode=1, axis=0)  # Pick the handle

    # Step 3: Pull the drawer using the handle to open it
    robot.execute_movement(Object["drawer_bottom_handle"], mode=4, distance=0.1)  # Pull to open

def main():
    """Main entry point to execute the drawer opening sequence."""
    long_horizon_task2_oracle_seq()

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

