=== Instruction 1 ===
Is Correct: False
Syntax Pass: False
Code Function: This code defines a sequence for a robot to interact with a drawer. First, the robot moves to pick the bottom handle of the drawer from a ready position. Next, the robot pulls the drawer open by pulling the same handle along the x-axis for a specified distance. The code handles any errors that occur during these actions by printing error messages. The sequence is executed when the script is run directly.
Similarity: {'ok': True, 'reason': 'The described code sequence picks up the correct handle and pulls the corresponding unlocked, closed drawer open, which matches the task of opening one drawer.'}
Differences: 1. **Specificity of Drawer**:  
   - TASK: The instruction is to "Open one drawer," which is general and does not specify which drawer to open.
   - CODE_FUNC: The code specifically targets the "bottom" drawer by interacting with the "bottom handle" and opening the "bottom" drawer.

2. **Error Handling**:  
   - TASK: The instruction and PDDL do not mention error handling.
   - CODE_FUNC: The code explicitly handles errors during the pick and pull actions by printing error messages.

3. **Axis and Distance of Pull**:  
   - TASK: The instruction and PDDL do not specify the axis or distance for pulling the drawer.
   - CODE_FUNC: The code specifies pulling the handle along the x-axis for a certain distance.

4. **Execution Trigger**:  
   - TASK: The instruction is a static command; the PDDL is a domain/problem definition, not an executable script.
   - CODE_FUNC: The sequence is executed when the script is run directly (i.e., it has an entry point).

5. **Level of Abstraction**:  
   - TASK: The instruction is high-level and abstract ("Open one drawer").
   - CODE_FUNC: The code is low-level and concrete, specifying exact actions, objects, and parameters.

6. **Object Manipulation**:  
   - TASK: The instruction does not mention picking up the handle.
   - CODE_FUNC: The robot explicitly picks up the handle before pulling.

7. **Observation/State Use**:  
   - TASK: The PDDL problem defines multiple drawers and handles, with some drawers locked/unlocked.
   - CODE_FUNC: The code assumes the bottom drawer is available and does not check the state of other drawers.

8. **Language/Format**:  
   - TASK: Expressed as a natural language instruction and PDDL.
   - CODE_FUNC: Expressed as executable code (presumably Python or similar).

9. **Output/Feedback**:  
   - TASK: No output or feedback is specified.
   - CODE_FUNC: Provides feedback via error messages if actions fail.

10. **Assumptions about Initial State**:  
    - TASK: The PDDL initial state includes multiple drawers, some locked, some unlocked.
    - CODE_FUNC: The code assumes the bottom drawer is the target and does not dynamically select which drawer to open.

Refined Code Generated:
-------------------
"""Module to open one available (unlocked and closed) drawer using the robot controller."""

from Object_list import Object
from skill_mapping import RobotController

def open_one_drawer():
    """Open one available (unlocked and closed) drawer."""
    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"),
    ]

    # For this example, we assume Object contains keys for both drawers and handles
    for drawer_name, handle_name in drawers:
        drawer = Object.get(drawer_name)
        handle = Object.get(handle_name)
        if drawer is None or handle is None:
            continue

        # Check if the drawer is unlocked and closed
        if getattr(drawer, "is_unlocked", False) and getattr(drawer, "is_closed", False):
            # Pick the handle
            robot.execute_movement(handle, mode=1, axis=0)
            # Pull the handle to open the drawer
            robot.execute_movement(handle, mode=4, axis=0, distance=0.1)
            break

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 interact with a drawer. First, the robot picks up the bottom handle of the drawer from a ready position, approaching along the x-axis. Next, the robot pulls the drawer open using the same handle, again approaching along the x-axis and moving 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': True, 'reason': 'The code describes picking up the correct handle and pulling open the corresponding unlocked, closed drawer, which matches the task of pulling open a single drawer.'}
Differences: 1. **Specificity of Drawer**  
   - TASK: "Pull open a single drawer" is generic; it does not specify which drawer to open.
   - CODE_FUNC: The code specifically operates on the "bottom" drawer (using "handle_bottom" and "drawer_bottom").

2. **Approach Direction**  
   - TASK: No mention of approach direction.
   - CODE_FUNC: Explicitly states the robot approaches along the x-axis.

3. **Movement Distance**  
   - TASK: No mention of how far to pull the drawer.
   - CODE_FUNC: Specifies the drawer is moved by a certain 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.
   - CODE_FUNC: Sequence is executed when the script is run directly (i.e., includes a main guard).

6. **Handle Manipulation**  
   - TASK: Does not specify how the drawer is pulled open (e.g., via handle).
   - CODE_FUNC: Robot explicitly picks up the handle object before pulling.

7. **Initial Robot Position**  
   - TASK: No mention of robot's starting position.
   - CODE_FUNC: Robot starts from a "ready" position.

8. **Sequence of Actions**  
   - TASK: Only instructs to pull open a drawer.
   - CODE_FUNC: Includes both picking up the handle and pulling the drawer, making the sequence explicit.

9. **Object References**  
   - TASK: Refers to "a single drawer" generically.
   - CODE_FUNC: Refers to specific objects ("handle_bottom", "drawer_bottom").

10. **Precondition Awareness**  
    - TASK: No explicit mention of preconditions (e.g., drawer must be unlocked and closed).
    - CODE_FUNC: Implicitly assumes preconditions are met but does not check or state them.

11. **Language/Format**  
    - TASK: Natural language instruction.
    - CODE_FUNC: Code description and logic.

12. **Domain Knowledge**  
    - TASK: Does not reference the domain or object model.
    - CODE_FUNC: Assumes knowledge of the domain (handles, drawers, positions).

13. **Plurality**  
    - TASK: "a single drawer" (singular, but generic).
    - CODE_FUNC: Only operates on one, but specifically the bottom drawer.

14. **Implicit vs. Explicit Steps**  
    - TASK: Leaves implementation details implicit.
    - CODE_FUNC: Makes all steps explicit (pick handle, pull drawer, error handling, etc.).

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

def pull_open_drawer():
    """Pull open a single drawer."""
    robot = RobotController()
    try:
        # Pick up a handle of a drawer (generic: pick the first available handle)
        handle = Object["drawer_bottom_handle"]
        robot.execute_movement(handle, mode=1, axis=0)
        # Pull open the corresponding drawer
        robot.execute_movement(handle, mode=4, distance=0.1)
    except Exception as error:
        print(f"Error during task execution: {error}")

def main():
    """Main function to pull open a single drawer."""
    pull_open_drawer()

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 involving a drawer. First, the robot grasps the bottom handle of the drawer. Next, it pulls the drawer open by a specified distance. If any error occurs during these actions, it prints an error message.
Similarity: {'ok': True, 'reason': "The code functionally matches the task by grasping the correct handle and pulling the drawer open, which aligns with the domain's requirements for opening a drawer."}
Differences: 1. **Explicit Drawer Selection**:  
   - **TASK**: "Slide one drawer open" is ambiguous about which drawer to open; it does not specify which drawer or handle.
   - **CODE_FUNC**: Explicitly selects the "bottom" drawer by grasping the "bottom handle" and opening the "bottom drawer".

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

3. **Partial vs. Full Open**:  
   - **TASK**: "Slide open" could mean fully or partially open; the degree is unspecified.
   - **CODE_FUNC**: Specifies opening the drawer by a certain distance (implying possibly a partial open).

4. **Error Handling**:  
   - **TASK**: No mention of error handling or what to do if the action fails.
   - **CODE_FUNC**: Includes error checking and prints an error message if any step fails.

5. **Number of Steps**:  
   - **TASK**: Implies a single action ("slide open").
   - **CODE_FUNC**: Decomposes into two explicit actions: grasp handle, then pull.

6. **Drawer State Preconditions**:  
   - **TASK**: Does not specify preconditions (e.g., drawer must be unlocked and closed).
   - **CODE_FUNC**: Assumes the drawer is in a state where it can be opened (unlocked, closed), but does not check or change these states.

7. **Robot Location**:  
   - **TASK**: Does not specify where the robot should be.
   - **CODE_FUNC**: Assumes the robot is in the correct position to grasp and pull.

8. **Object Generality**:  
   - **TASK**: "One drawer" could refer to any drawer.
   - **CODE_FUNC**: Hardcodes the "bottom" drawer and its handle.

9. **Action Granularity**:  
   - **TASK**: High-level instruction.
   - **CODE_FUNC**: Low-level, stepwise execution.

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

11. **Concurrency/Atomicity**:  
    - **TASK**: Implies atomicity (one action).
    - **CODE_FUNC**: Non-atomic, split into sequential steps.

12. **Assumed Knowledge**:  
    - **TASK**: Assumes the agent knows how to open a drawer.
    - **CODE_FUNC**: Explicitly programs the steps required.

13. **Parameterization**:  
    - **TASK**: No parameters (distance, which drawer, etc.).
    - **CODE_FUNC**: Parameterizes the pull distance.

14. **Handle-Drawer Association**:  
    - **TASK**: Does not mention handles.
    - **CODE_FUNC**: Assumes knowledge of which handle belongs to which drawer.

15. **Failure Recovery**:  
    - **TASK**: No mention of what to do on failure.
    - **CODE_FUNC**: Stops and reports on failure.

---

**Summary**:  
The CODE_FUNC is more specific, procedural, and robust (with error handling), while the TASK is high-level, ambiguous, and underspecified.

Refined Code Generated:
-------------------
"""Module to slide one drawer open."""
from Object_list import Object
from skill_mapping import RobotController

def slide_one_drawer_open():
    """Slide any one available drawer open."""
    robot = RobotController()
    # List of candidate drawers and their handles
    drawers = [
        ("drawer_bottom", "drawer_bottom_handle"),
        ("drawer_middle", "drawer_middle_handle"),
        ("drawer_top", "drawer_top_handle"),
    ]
    for drawer, handle in drawers:
        try:
            # Try to pick the handle
            robot.execute_movement(Object[handle], mode=1, axis=0)
            # Try to pull the drawer open
            robot.execute_movement(Object[handle], mode=4, axis=0, distance=0.1)
            return
        except Exception as error:
            print(f"Failed to open {drawer}: {error}")
    print("Could not open any drawer.")

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. Next, it pulls the handle to open the drawer by a specified distance. If any error occurs during these actions, it is caught and printed.
Similarity: {'ok': True, 'reason': "The described code achieves the task by grasping the handle and pulling to open one of the drawers, matching the domain's requirements for opening a drawer."}
Differences: 1. **Specificity of Drawer**  
   - TASK: The instruction is to "Open up one of the drawers," which is ambiguous as to which drawer should be opened.
   - CODE_FUNC: The code specifically targets the "bottom drawer" (drawer_bottom).

2. **Precondition Awareness**  
   - TASK: The instruction does not mention any preconditions (e.g., whether the drawer is locked or unlocked, open or closed).
   - CODE_FUNC: The code implicitly assumes the drawer can be opened (i.e., it is unlocked and closed), as it proceeds to grasp the handle and pull.

3. **Action Granularity**  
   - TASK: The instruction is high-level and does not specify how to open the drawer (e.g., which handle to grasp, how to pull).
   - CODE_FUNC: The code details the steps: move to the handle, grasp it, and pull to open the drawer by a specified distance.

4. **Error Handling**  
   - TASK: No mention of error handling or what to do if the drawer cannot be opened.
   - CODE_FUNC: The code includes error handling (try/except) to catch and print errors during the process.

5. **Drawer State Change**  
   - TASK: The instruction only specifies the end goal (drawer open), not the process.
   - CODE_FUNC: The code explicitly performs the process (move, grasp, pull) to achieve the open state.

6. **Object Manipulation**  
   - TASK: No mention of manipulating handles or objects.
   - CODE_FUNC: The code involves grasping the handle object associated with the drawer.

7. **Distance/Extent of Opening**  
   - TASK: Does not specify how far to open the drawer.
   - CODE_FUNC: The code specifies opening the drawer by a certain distance.

8. **Domain Knowledge Usage**  
   - TASK: Does not reference domain-specific knowledge (e.g., which handle belongs to which drawer).
   - CODE_FUNC: The code uses domain knowledge to identify and interact with the correct handle and drawer.

9. **Robotic State**  
   - TASK: No mention of the robot's state (location, hand status, etc.).
   - CODE_FUNC: The code manages the robot's state (moving, grasping, etc.) as part of the process.

10. **Ambiguity vs. Determinism**  
    - TASK: Ambiguous as to which drawer and how to open it.
    - CODE_FUNC: Deterministic, always operates on the bottom drawer in a specific way.

Refined Code Generated:
-------------------
"""Module to open any available drawer."""
from Object_list import Object
from skill_mapping import RobotController

def open_any_drawer():
    """Attempts to open any available closed and unlocked drawer."""
    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"),
    ]
    for drawer_name, handle_name in drawers:
        try:
            # Check if the drawer is closed and unlocked
            if robot.is_drawer_closed(drawer_name) and robot.is_drawer_unlocked(drawer_name):
                # Move to 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, axis=0, distance=0.1)
                return
        except Exception as error:
            print(f"Error while trying to open {drawer_name}: {error}")

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

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

=== Instruction 5 ===
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 attempts to pick or grasp the handle of the bottom drawer by approaching it along the x-axis. Next, the robot tries to pull the handle to open the drawer by moving along the same axis for 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': True, 'reason': "The code's described sequence matches the domain's requirements for opening (uncovering) the bottom drawer: picking the handle and pulling it to open the drawer."}
Differences: 1. **Level of Abstraction**  
   - TASK describes the goal in natural language: "Uncover a drawer by opening it." It is an instruction specifying the desired end state (drawer open).
   - CODE_FUNC describes a concrete sequence of robot actions: approach the bottom drawer handle, grasp it, and pull to open the drawer, with error handling.

2. **Target of Action**  
   - TASK is general: "a drawer" (no specific drawer is mentioned).
   - CODE_FUNC is specific: it operates on the "bottom drawer" only.

3. **Required Preconditions**  
   - TASK does not specify any preconditions (e.g., whether the drawer is locked or unlocked, or if the robot is at a certain location).
   - CODE_FUNC implicitly assumes the robot can approach and grasp the handle, and that the drawer is in a state that allows opening (e.g., unlocked and closed).

4. **Error Handling**  
   - TASK does not mention error handling.
   - CODE_FUNC includes error catching and printing if actions fail.

5. **Action Granularity**  
   - TASK is high-level and outcome-focused.
   - CODE_FUNC is low-level and process-focused, detailing the steps (approach, grasp, pull).

6. **Domain Knowledge**  
   - TASK does not reference domain-specific predicates or actions.
   - CODE_FUNC is implicitly tied to the robot's action repertoire (e.g., moving along axes, grasping handles).

7. **Object Interaction**  
   - TASK does not specify how the drawer is to be opened (e.g., by handle, by pushing, etc.).
   - CODE_FUNC specifies opening by grasping and pulling the handle.

8. **Error States and Recovery**  
   - TASK does not address what happens if the drawer cannot be opened.
   - CODE_FUNC includes mechanisms to handle and report errors.

9. **Execution Context**  
   - TASK is a standalone instruction.
   - CODE_FUNC is a script that executes when run directly.

10. **Implicit Assumptions**  
    - TASK assumes the agent knows how to open a drawer.
    - CODE_FUNC assumes the robot can localize, approach, and manipulate the handle, and that the drawer is physically accessible.

11. **Outcome Specification**  
    - TASK specifies the outcome: the drawer is uncovered/open.
    - CODE_FUNC specifies the process, with the outcome being a result of successful execution.

12. **Scope**  
    - TASK could apply to any drawer.
    - CODE_FUNC applies only to the bottom drawer in the current context.

13. **Reference to Domain Model**  
    - TASK does not reference the PDDL domain or its predicates.
    - CODE_FUNC is written to operate within the constraints and affordances of the robot's codebase, which may or may not map directly to the PDDL actions.

14. **Handling of Multiple Drawers**  
    - TASK could be interpreted as applying to any or all drawers.
    - CODE_FUNC only operates on one specific drawer.

15. **Language**  
    - TASK is in English.
    - CODE_FUNC is in code (presumably Python or similar).

---

**Summary:**  
The semantic differences are primarily in specificity, abstraction, error handling, and scope. The TASK is a high-level, general instruction, while CODE_FUNC is a low-level, specific implementation for a particular drawer with explicit error handling and process steps.

Refined Code Generated:
-------------------
"""Module to open (uncover) any available drawer."""
from Object_list import Object
from skill_mapping import RobotController

def open_drawer(drawer_name):
    """Open (uncover) the specified drawer if possible."""
    robot = RobotController()
    handle_name = f"{drawer_name}_handle"
    try:
        # Approach the handle of the specified drawer
        robot.execute_movement(Object[handle_name], mode=1, axis=0)
        # Pull to open the drawer using the handle
        robot.execute_movement(Object[handle_name], mode=4, axis=0, distance=0.1)
    except Exception as error:
        print(f"Failed to open {drawer_name}: {error}")

def main():
    # Try to open any available drawer (bottom, middle, top)
    for drawer in ["drawer_bottom", "drawer_middle", "drawer_top"]:
        open_drawer(drawer)

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

