=== Instruction 1 ===
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 pick the bottom handle of the drawer from a ready position, approaching along the x-axis. Next, the robot pulls the drawer open by moving the handle along the x-axis for a specified distance. The code handles any errors that occur during these actions by printing error messages.
Similarity: {'ok': False, 'reason': 'The code only picks up the handle and pulls it, but does not ensure the drawer is unlocked or closed, which are required preconditions for opening the drawer in the domain.'}
Differences: 1. **Specificity of Drawer**:  
   - TASK: "Open one drawer." This is a general instruction; it does not specify which drawer to open.
   - CODE_FUNC: The code specifically targets the "bottom" drawer by picking the "bottom handle" and pulling it.

2. **Action Sequence**:  
   - TASK: Only requires the drawer to be opened; how this is achieved is unspecified.
   - CODE_FUNC: Specifies a two-step process: (a) pick the bottom handle, (b) pull the drawer open.

3. **Movement Details**:  
   - TASK: No mention of how the robot should move or approach the drawer.
   - CODE_FUNC: Explicitly describes moving to the handle from a "ready position" and approaching along the x-axis.

4. **Error Handling**:  
   - TASK: No mention of error handling.
   - CODE_FUNC: Includes error handling by printing error messages if actions fail.

5. **Handle Manipulation**:  
   - TASK: Does not mention handles.
   - CODE_FUNC: Involves picking up a handle to open the drawer.

6. **Assumed Preconditions**:  
   - TASK: Assumes the robot can open a drawer; does not specify preconditions.
   - CODE_FUNC: Assumes the handle is on the floor and must be picked up before pulling.

7. **Domain Knowledge Usage**:  
   - TASK: Abstract, does not reference domain predicates or actions.
   - CODE_FUNC: Implies knowledge of the domain (e.g., handle, drawer, movement along axes).

8. **Number of Drawers**:  
   - TASK: "One drawer"—could be any.
   - CODE_FUNC: Implies there are multiple drawers but selects the "bottom" one.

9. **Object Manipulation**:  
   - TASK: Only mentions opening a drawer.
   - CODE_FUNC: Involves manipulating an object (the handle) as part of the process.

10. **Location Reference**:  
    - TASK: No location is specified.
    - CODE_FUNC: References "ready position" and movement along the x-axis.

11. **Language Level**:  
    - TASK: High-level, natural language instruction.
    - CODE_FUNC: Low-level, stepwise procedural description.

12. **Implicit vs. Explicit Steps**:  
    - TASK: Leaves all steps implicit.
    - CODE_FUNC: Makes all steps explicit, including picking and pulling.

13. **Error Recovery**:  
    - TASK: No mention of what to do if something fails.
    - CODE_FUNC: Handles errors by printing messages.

14. **Robot State**:  
    - TASK: No mention of robot state.
    - CODE_FUNC: Implies robot starts at a "ready position" and is free to move.

15. **Handle Location**:  
    - TASK: No mention of handle location.
    - CODE_FUNC: Assumes handle is on the floor and must be picked up.

16. **Drawer State**:  
    - TASK: No mention of whether the drawer is locked/unlocked or open/closed.
    - CODE_FUNC: Assumes the drawer can be opened by pulling after picking the handle.

17. **Action Granularity**:  
    - TASK: Single high-level action.
    - CODE_FUNC: Multiple low-level actions.

18. **Output/Feedback**:  
    - TASK: No output or feedback specified.
    - CODE_FUNC: Provides feedback via error messages.

19. **Assumed Success**:  
    - TASK: Assumes the drawer can be opened.
    - CODE_FUNC: Accounts for possible failure.

20. **Temporal Order**:  
    - TASK: No order specified.
    - CODE_FUNC: Specifies a strict order: pick, then pull.

Refined Code Generated:
-------------------
"""Module to open one drawer using the robot controller."""
from object_list import OBJECTS
from skill_mapping import RobotController

def open_one_drawer():
    """Open any one closed and unlocked drawer."""
    robot = RobotController()
    # Find a closed and unlocked drawer and its handle
    for drawer_name in ["drawer_bottom", "drawer_middle", "drawer_top"]:
        drawer = OBJECTS.get(drawer_name)
        handle = OBJECTS.get(f"{drawer_name}_handle")
        if drawer is None or handle is None:
            continue
        if robot.is_drawer_closed(drawer) and robot.is_drawer_unlocked(drawer):
            # Move to handle location
            robot.move_to(handle.location)
            # Pick the handle
            robot.pick(handle)
            # Pull to open the drawer
            robot.pull_drawer(drawer, handle)
            return
    print("No closed and unlocked drawer found to open.")

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: The code defines a sequence for a robot to interact with a bottom drawer. First, the robot moves to pick the handle of the bottom drawer. Next, the robot pulls the drawer open using the handle. If any error occurs during these actions, it is caught and printed. The sequence is executed when the script is run directly.
Similarity: {'ok': True, 'reason': "The described code sequence moves the robot to pick the bottom drawer's handle and then pulls the drawer open, which matches the task of pulling open a single drawer."}
Differences: 1. **Specificity of Drawer**:  
   - **TASK**: The instruction is to "Pull open a single drawer," which is generic and does not specify which drawer to open.
   - **CODE_FUNC**: The code specifically interacts with the **bottom drawer** (drawer_bottom) and its handle (handle_bottom).

2. **Scope of Action**:  
   - **TASK**: Only requires the drawer to be pulled open (i.e., transition from closed to open).
   - **CODE_FUNC**: Includes the step of picking up the handle before pulling the drawer open, making the sequence more explicit and multi-step.

3. **Error Handling**:  
   - **TASK**: No mention of error handling or contingencies.
   - **CODE_FUNC**: Explicitly catches and prints errors that may occur during the pick or pull actions.

4. **Execution Context**:  
   - **TASK**: Is an instruction, not tied to any execution context.
   - **CODE_FUNC**: The sequence is executed only if the script is run as the main module (`if __name__ == "__main__":`).

5. **Implied Preconditions**:  
   - **TASK**: Assumes the drawer can be pulled open, but does not specify preconditions (e.g., that the drawer is unlocked, closed, and the robot is at the correct location).
   - **CODE_FUNC**: Implicitly assumes or handles these preconditions by picking the correct handle and attempting the pull, but does not explicitly check for lock state or robot location in the description.

6. **Object Manipulation**:  
   - **TASK**: Does not specify how the drawer is to be opened (e.g., by handle or otherwise).
   - **CODE_FUNC**: Specifies that the robot must pick the handle object before pulling the drawer.

7. **Drawer State**:  
   - **TASK**: Only specifies the end state (drawer open).
   - **CODE_FUNC**: The sequence ensures the drawer is opened, but also involves the intermediate state of holding the handle.

8. **Drawer Selection**:  
   - **TASK**: Could apply to any drawer.
   - **CODE_FUNC**: Applies only to the bottom drawer.

9. **Level of Abstraction**:  
   - **TASK**: High-level, abstract instruction.
   - **CODE_FUNC**: Low-level, concrete sequence of actions.

10. **Domain Knowledge**:  
    - **TASK**: Does not reference the domain or objects.
    - **CODE_FUNC**: Assumes knowledge of the domain's object names and structure (e.g., handle_bottom, drawer_bottom).

---

**Summary**: The main semantic differences are specificity (which drawer), explicitness of steps (handle pick), error handling, and abstraction level.

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

def pull_open_single_drawer(drawer_name, handle_name, location):
    """
    Pull open a single drawer by its handle.
    Args:
        drawer_name (str): The name of the drawer to open.
        handle_name (str): The name of the handle associated with the drawer.
        location (str): The location where the drawer and handle are.
    """
    robot = RobotController()
    # Pick the handle
    robot.execute_movement(Object[handle_name], mode=1, axis=0)
    # Pull to open the drawer
    robot.execute_movement(Object[handle_name], mode=4, distance=0.1)

# Example usage: open any drawer by specifying its handle and location
# For instance, to open the middle drawer:
# pull_open_single_drawer("drawer_middle", "drawer_middle_handle", "ready-pose") 

# To satisfy the TASK (generic, single drawer), do not call the function directly here.
-------------------

=== Instruction 3 ===
Is Correct: False
Syntax Pass: False
Code Function: This code defines a sequence for a robot to interact with a drawer. First, the robot picks the handle of the bottom drawer. Then, it pulls the handle to open the drawer by a specified distance. If any step fails, it prints an error message and stops the sequence. The process is started when the script is run directly.
Similarity: {'ok': True, 'reason': 'The code picks the handle and pulls it to open the drawer, matching the required steps to slide one drawer open according to the domain.'}
Differences: 1. **Specificity of Drawer**  
   - TASK: "Slide one drawer open" is generic; it does not specify which drawer to open.
   - CODE_FUNC: The code specifically interacts with the bottom drawer (by picking the handle of the bottom drawer).

2. **Level of Abstraction**  
   - TASK: High-level instruction; does not specify how to open the drawer (e.g., which handle to use, how to grasp, etc.).
   - CODE_FUNC: Low-level sequence; explicitly picks the handle, pulls it, and checks for errors.

3. **Error Handling**  
   - TASK: No mention of error handling or what to do if the action fails.
   - CODE_FUNC: Includes error checking after each step and aborts the sequence if a step fails.

4. **Distance/Extent of Opening**  
   - TASK: Does not specify how far to open the drawer.
   - CODE_FUNC: Pulls the handle "by a specified distance" (implies a parameterized or fixed extent).

5. **Initiation Condition**  
   - TASK: No mention of when or how the instruction is triggered.
   - CODE_FUNC: The process is started when the script is run directly (i.e., via `if __name__ == "__main__"`).

6. **Output/Feedback**  
   - TASK: No mention of output or feedback.
   - CODE_FUNC: Prints error messages if a step fails.

7. **Object Manipulation**  
   - TASK: Does not mention interacting with the handle.
   - CODE_FUNC: Explicitly picks the handle object before pulling.

8. **Drawer State Assumptions**  
   - TASK: Assumes a drawer can be opened, but does not specify preconditions (e.g., unlocked, closed).
   - CODE_FUNC: Implicitly assumes the drawer is closed and can be opened by pulling the handle.

9. **Single vs. Multiple Drawers**  
   - TASK: "one drawer" could refer to any drawer.
   - CODE_FUNC: Only operates on the bottom drawer.

10. **Sequence Termination**  
    - TASK: No mention of what happens after opening.
    - CODE_FUNC: Sequence stops if an error occurs; otherwise, ends after opening.

11. **Robustness**  
    - TASK: No robustness features.
    - CODE_FUNC: Robust to failure (stops on error).

12. **Parameterization**  
    - TASK: No parameters.
    - CODE_FUNC: Parameterizes the distance to pull the handle.

13. **Explicitness of Steps**  
    - TASK: Single-step instruction.
    - CODE_FUNC: Multi-step process (pick, pull, check).

14. **Assumed Context**  
    - TASK: No context about robot state or environment.
    - CODE_FUNC: Assumes robot is ready, knows which handle to pick, and can execute the sequence.

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

def slide_one_drawer_open():
    """
    Slides one available drawer open.
    """
    robot = RobotController()
    # Find any available drawer handle
    for drawer_name in ["drawer_bottom", "drawer_middle", "drawer_top"]:
        handle_name = f"{drawer_name}_handle"
        if handle_name in Object:
            try:
                robot.execute_movement(Object[handle_name], mode=1, axis=0)
                robot.execute_movement(Object[handle_name], mode=4, axis=0, distance=0.1)
                break
            except Exception as error:
                continue

def main():
    slide_one_drawer_open()

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

=== Instruction 4 ===
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 picks up the handle of the bottom drawer from a ready position, grasping it along the x-axis. Next, the robot pulls the bottom drawer open using the handle, again along the x-axis, and moves it by a specified distance. If any errors occur during these actions, they are caught and printed. The sequence is executed when the script is run directly.
Similarity: {'ok': False, 'reason': 'The code does not unlock the drawer before attempting to pull it open, but the domain requires the drawer to be unlocked before it can be opened.'}
Differences: 1. **Specificity of Drawer**  
   - TASK: The instruction is to "Open up one of the drawers," which is ambiguous and allows for any drawer to be opened.
   - CODE_FUNC: The code specifically targets the "bottom drawer" (drawer_bottom) and its handle (handle_bottom).

2. **Reference to Handle**  
   - TASK: Does not mention the handle or how to interact with the drawer.
   - CODE_FUNC: Explicitly involves picking up the handle of the bottom drawer before opening.

3. **Axis and Movement Details**  
   - TASK: No mention of direction, axis, or distance for opening.
   - CODE_FUNC: Specifies opening "along the x-axis" and by a "specified distance."

4. **Error Handling**  
   - TASK: No mention of error handling.
   - CODE_FUNC: Includes error catching and printing if actions fail.

5. **Execution Context**  
   - TASK: Purely an instruction, not tied to code execution context.
   - CODE_FUNC: Sequence is executed when the script is run directly (i.e., within a `__main__` block).

6. **Object Manipulation**  
   - TASK: Only requires the drawer to be opened, with no mention of picking up or manipulating objects.
   - CODE_FUNC: Requires the robot to pick up the handle (an object) before opening the drawer.

7. **Implied Preconditions**  
   - TASK: Assumes the drawer can be opened, with no mention of lock state, handle, or robot state.
   - CODE_FUNC: Implies the robot must be at the ready position, hand empty, and able to grasp the handle.

8. **Drawer Selection**  
   - TASK: Leaves the choice of drawer open.
   - CODE_FUNC: Hardcodes the bottom drawer as the target.

9. **Level of Abstraction**  
   - TASK: High-level, natural language instruction.
   - CODE_FUNC: Low-level, step-by-step procedural actions.

10. **Domain Knowledge Usage**  
    - TASK: Does not reference domain-specific predicates or actions.
    - CODE_FUNC: Implicitly maps to domain actions like `execute_pick` and `execute_pull` with specific parameters.

---

**Summary:**  
The main semantic differences are in specificity (which drawer), explicit handle manipulation, movement details, error handling, execution context, and abstraction level. The TASK is a general, high-level instruction, while the CODE_FUNC is a concrete, low-level implementation for a specific drawer and handle.

Refined Code Generated:
-------------------
"""Module to open any unlocked drawer using a robot controller."""
from Object_list import Object
from skill_mapping import RobotController

def long_horizon_task2_oracle_seq():
    """Open up one of the drawers (the first unlocked and closed one found)."""
    robot = RobotController()
    # List of drawers and their corresponding handles
    drawers = [
        ("drawer_bottom", "drawer_bottom_handle"),
        ("drawer_middle", "drawer_middle_handle"),
        ("drawer_top", "drawer_top_handle"),
    ]
    try:
        for drawer_name, handle_name in drawers:
            drawer = Object.get(drawer_name)
            handle = Object.get(handle_name)
            # Check if the drawer is unlocked and closed
            if robot.is_drawer_unlocked(drawer) and robot.is_drawer_closed(drawer):
                # If not holding anything, pick up the handle
                if robot.is_hand_empty():
                    robot.execute_movement(handle, mode=1, axis=0)
                # Unlock the drawer if needed
                if robot.is_drawer_locked(drawer):
                    robot.unlock_drawer(drawer)
                # Pull to open the drawer
                robot.execute_movement(handle, mode=4, distance=0.1)
                break
    except Exception as error:
        print(f"Error during task execution: {error}")

def main():
    """Main entry point to open a drawer."""
    long_horizon_task2_oracle_seq()

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

=== Instruction 5 ===
Is Correct: False
Syntax Pass: False
Code Function: This code defines a sequence for a robot to open the bottom drawer. First, the robot moves to grasp the handle of the bottom drawer. Then, it pulls the handle to open the drawer 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': True, 'reason': "The described code sequence matches the domain's requirements for opening a drawer by picking up the handle and executing a pull action, which uncovers the drawer as instructed."}
Differences: 1. **Level of Abstraction**  
   - TASK describes the *goal* or *desired outcome* ("Uncover a drawer by opening it"), not specifying how it is achieved.
   - CODE_FUNC describes the *specific sequence of actions* (move, grasp handle, pull handle) the robot must perform to open the drawer.

2. **Agent Perspective**  
   - TASK is *instructional* and *user-facing*, telling an agent what to achieve.
   - CODE_FUNC is *implementation-focused*, describing what the code does step by step.

3. **Error Handling**  
   - TASK does not mention errors or contingencies.
   - CODE_FUNC explicitly mentions catching and printing errors during execution.

4. **Drawer Specificity**  
   - TASK refers to "a drawer" generically.
   - CODE_FUNC specifies "the bottom drawer".

5. **Action Granularity**  
   - TASK is a single high-level action ("open the drawer").
   - CODE_FUNC breaks this into multiple low-level actions (move, grasp, pull).

6. **Execution Context**  
   - TASK is context-agnostic; it could be for a human or robot.
   - CODE_FUNC is explicitly for a robot and is executed as a script.

7. **Physical Interaction Details**  
   - TASK does not specify how the drawer is opened (e.g., by handle, by pulling).
   - CODE_FUNC specifies grasping the handle and pulling by a distance.

8. **Conditionality**  
   - TASK assumes the action is possible.
   - CODE_FUNC includes conditional logic (error catching) in case the action fails.

9. **Temporal Structure**  
   - TASK is atemporal (no sequence).
   - CODE_FUNC is temporal (sequence of steps).

10. **Parameterization**  
    - TASK does not mention parameters.
    - CODE_FUNC mentions parameters like "specified distance".

11. **Initiation**  
    - TASK is a standalone instruction.
    - CODE_FUNC is executed when the script is run directly (`if __name__ == "__main__":`).

Refined Code Generated:
-------------------
"""Module to uncover a drawer by opening it."""

from object_list import Object
from skill_mapping import RobotController

def long_horizon_task2_oracle_seq():
    """Uncover a drawer by opening it."""
    robot = RobotController()

    # Step 1: Pick up the handle of a drawer (e.g., handle_bottom at ready-pose)
    # Mapping: handle_bottom -> Object["drawer_bottom_handle"]
    # Approach axis: 0 (x-axis) for handles
    robot.execute_movement(Object["drawer_bottom_handle"], mode=1, axis=0)

    # Step 2: Pull to open the drawer using the handle
    # Mapping: drawer_bottom, handle_bottom, ready-pose
    # Use the handle's pose for pulling as well
    # Use a slightly larger distance for drawer pull
    robot.execute_movement(Object["drawer_bottom_handle"], mode=4, distance=0.1)

def main():
    """Main entry point to uncover a drawer by opening it."""
    long_horizon_task2_oracle_seq()

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

