=== Instruction 1 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to sequentially open two drawers. First, the robot picks the handle of the bottom drawer and pulls it open by a specified distance. Then, it picks the handle of the middle drawer and pulls it open by the same distance. If any error occurs during these actions, it is caught and printed. The process is initiated when the script is run directly.
Similarity: {'ok': True, 'reason': 'The described code functionally achieves the task by sequentially opening two drawers, matching the instruction and available domain actions.'}
Differences: 1. **Explicitness of Sequence**:  
   - TASK only instructs to "Open two drawers" without specifying which drawers or the order.
   - CODE_FUNC specifies the bottom drawer is opened first, then the middle drawer.

2. **Drawer Selection**:  
   - TASK is agnostic to which two drawers are opened.
   - CODE_FUNC selects and opens the bottom and middle drawers specifically.

3. **Error Handling**:  
   - TASK does not mention error handling.
   - CODE_FUNC includes error catching and printing.

4. **Distance Specification**:  
   - TASK does not mention how far to open the drawers.
   - CODE_FUNC specifies a distance to pull the drawers open.

5. **Handle Manipulation**:  
   - TASK does not mention handles.
   - CODE_FUNC explicitly picks the handle of each drawer before pulling.

6. **Assumption of Initial State**:  
   - TASK does not assume or require any initial state.
   - CODE_FUNC assumes the robot is able to pick handles and that the drawers are in a state that allows opening.

7. **Number of Drawers**:  
   - TASK: "two drawers" (any two).
   - CODE_FUNC: exactly the bottom and middle drawers.

8. **Action Granularity**:  
   - TASK is high-level.
   - CODE_FUNC is low-level, specifying pick and pull actions for each drawer.

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

10. **Initiation Condition**:  
    - TASK is a standalone instruction.
    - CODE_FUNC only runs the process if the script is executed as the main module.

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

def open_two_drawers():
    """
    Opens any two drawers using the robot controller.
    """
    robot = RobotController()
    drawers = [
        ("drawer_bottom_handle", 0),
        ("drawer_middle_handle", 0),
        ("drawer_top_handle", 0)
    ]
    opened = 0
    for handle_name, axis in drawers:
        if opened >= 2:
            break
        robot.execute_movement(Object[handle_name], mode=1, axis=axis)
        robot.execute_movement(Object[handle_name], mode=4, axis=axis, distance=0.1)
        opened += 1

def main():
    """
    Main function to open two drawers.
    """
    open_two_drawers()

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

=== Instruction 2 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to sequentially open two drawers. First, the robot approaches and grasps the bottom drawer handle, then pulls the bottom drawer open. Next, it approaches and grasps the middle drawer handle, and pulls the middle drawer open. If any error occurs during these actions, it prints an error message.
Similarity: {'ok': True, 'reason': 'The described code functionally achieves the task by sequentially opening two drawers using the available actions and handles as specified in the domain.'}
Differences: 1. **Explicitness of Sequence**:  
   - **TASK**: The instruction "Pull open a pair of drawers" does not specify which drawers to open, nor the order in which to open them.
   - **CODE_FUNC**: The code explicitly opens the bottom drawer first, then the middle drawer, in that specific order.

2. **Error Handling**:  
   - **TASK**: The instruction does not mention or imply any error handling or what to do if an error occurs.
   - **CODE_FUNC**: The code includes error handling—if any error occurs during the actions, it prints an error message.

3. **Drawer Selection**:  
   - **TASK**: The instruction is generic; it does not specify which two drawers to open.
   - **CODE_FUNC**: The code specifically selects the bottom and middle drawers to open.

4. **Assumed Preconditions**:  
   - **TASK**: The instruction assumes the drawers can be opened but does not specify preconditions (e.g., that the drawers are unlocked, closed, or that the robot is at a certain location).
   - **CODE_FUNC**: The code implicitly assumes and checks for necessary preconditions (e.g., robot must approach, grasp handle, etc.) as per the domain.

5. **Level of Detail**:  
   - **TASK**: The instruction is high-level and abstract.
   - **CODE_FUNC**: The code is low-level and concrete, specifying the exact sequence of actions (approach, grasp, pull) for each drawer.

6. **Number of Drawers**:  
   - **TASK**: "A pair of drawers" could mean any two drawers.
   - **CODE_FUNC**: The code always opens the bottom and middle drawers, not any arbitrary pair.

7. **Implicit vs. Explicit Error Reporting**:  
   - **TASK**: No mention of reporting or handling errors.
   - **CODE_FUNC**: Explicitly reports errors if they occur.

8. **Robot Location**:  
   - **TASK**: No mention of robot movement or location.
   - **CODE_FUNC**: The code includes the robot approaching each drawer before opening.

9. **Handle Grasping**:  
   - **TASK**: Does not mention grasping handles.
   - **CODE_FUNC**: The code explicitly includes grasping the handle before pulling.

10. **Action Completion**:  
    - **TASK**: Does not specify what to do after opening the drawers.
    - **CODE_FUNC**: The code completes after opening the two specified drawers and handling any errors.

---

**Summary**:  
The main semantic differences are specificity (which drawers, order), explicit error handling, and the level of detail in the actions (including movement, grasping, and error reporting), all of which are present in CODE_FUNC but not in the TASK instruction.

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

def long_horizon_task2_oracle_seq(drawer_handles):
    """
    Pull open a pair of drawers specified by their handle names.
    :param drawer_handles: List of two handle names (e.g., ["drawer_bottom_handle", "drawer_top_handle"])
    """
    robot = RobotController()
    for handle_name in drawer_handles:
        robot.execute_movement(Object[handle_name], mode=1, axis=0)
        robot.execute_movement(Object[handle_name], mode=4, distance=0.1)

def main():
    # Example: open any two drawers (here, bottom and top)
    drawer_handles = ["drawer_bottom_handle", "drawer_top_handle"]
    long_horizon_task2_oracle_seq(drawer_handles)

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

=== Instruction 3 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to sequentially open three drawers (bottom, middle, and top) by interacting with their handles. For each drawer, the robot first moves to pick the handle and then pulls the drawer open by a specified distance. The process is repeated for all three drawers in order from bottom to top. If any error occurs during execution, it is caught and printed.
Similarity: {'ok': False, 'reason': 'The code does not check whether drawers are unlocked before attempting to open them, so it may try to open locked drawers, which does not satisfy the instruction to open only unlocked drawers.'}
Differences: 1. **Explicit Sequential Order**:  
   - CODE_FUNC specifies that drawers are opened in a fixed order: bottom, then middle, then top.  
   - TASK only requires that all unlocked drawers be opened, with no specified order.

2. **Assumption of Drawer State**:  
   - CODE_FUNC assumes all three drawers are to be opened, regardless of their locked/unlocked state.  
   - TASK requires only unlocked drawers to be opened.

3. **Error Handling**:  
   - CODE_FUNC includes error catching and printing.  
   - TASK does not mention error handling.

4. **Handle Interaction**:  
   - CODE_FUNC explicitly describes picking up the handle and pulling the drawer by a specified distance.  
   - TASK only requires the drawers to be opened, not specifying how (e.g., by handle, by distance).

5. **Completeness**:  
   - CODE_FUNC may attempt to open all three drawers even if some are locked (depending on implementation).  
   - TASK requires opening only those drawers that are unlocked.

6. **Implicit Preconditions**:  
   - CODE_FUNC may not check the locked/unlocked state before attempting to open.  
   - TASK semantically requires checking the unlocked state.

7. **Domain Generality**:  
   - TASK is general and applies to any number of drawers.  
   - CODE_FUNC is specific to three drawers (bottom, middle, top).

8. **Action Granularity**:  
   - CODE_FUNC details the robot's actions (move, pick handle, pull).  
   - TASK is high-level and does not specify action granularity.

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

10. **Assumed Initial State**:  
    - CODE_FUNC assumes the handles are on the floor and must be picked up.  
    - TASK does not specify the initial state of handles or their location.

11. **Physical Parameters**:  
    - CODE_FUNC mentions pulling the drawer by a "specified distance."  
    - TASK does not mention how far to open the drawers.

12. **Robot Location**:  
    - CODE_FUNC specifies the robot moves to each handle.  
    - TASK does not specify robot movement.

13. **Object Handling**:  
    - CODE_FUNC may require the robot to be hand-empty and free before picking up handles.  
    - TASK does not specify requirements about the robot's hand state.

14. **Failure Modes**:  
    - CODE_FUNC may fail if a drawer is locked or a handle is missing, and will print an error.  
    - TASK does not specify what to do in case of failure.

15. **Repetition**:  
    - CODE_FUNC repeats the process for each drawer in a hardcoded sequence.  
    - TASK implies iteration over all unlocked drawers, which may not be a fixed set.

---

**Summary**:  
The main semantic differences are that CODE_FUNC is specific, sequential, and assumes all drawers are to be opened regardless of lock state, while TASK is general, conditional on unlocked state, and does not specify order or method.

Refined Code Generated:
-------------------
"""Module to open all unlocked drawers using the robot controller."""

from Object_list import Object
from skill_mapping import RobotController

def open_all_unlocked_drawers():
    """Open all drawers that are currently unlocked."""
    robot = RobotController()

    # List of all drawers and their corresponding handles
    drawers = [
        {"drawer": "drawer_bottom", "handle": "handle_bottom", "handle_obj": "drawer_bottom_handle"},
        {"drawer": "drawer_middle", "handle": "handle_middle", "handle_obj": "drawer_middle_handle"},
        {"drawer": "drawer_top", "handle": "handle_top", "handle_obj": "drawer_top_handle"},
    ]

    for d in drawers:
        # Check if the drawer is unlocked
        if robot.is_drawer_unlocked(d["drawer"]):
            # Pick up the handle if not already holding it
            if not robot.is_holding(d["handle"]):
                robot.execute_movement(Object[d["handle_obj"]], mode=1, axis=0)
            # Pull the drawer open using the handle
            robot.execute_movement(Object[d["handle_obj"]], mode=4, distance=0.1)

def main():
    """Main function to open all unlocked drawers."""
    open_all_unlocked_drawers()

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

=== Instruction 4 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to sequentially open two drawers. First, the robot grasps the handle of the bottom drawer and pulls it open fully. Next, it grasps the handle of the middle drawer and pulls that open fully as well. If any error occurs during these actions, it prints an error message.
Similarity: {'ok': False, 'reason': "The code description does not mention unlocking the drawers, which is required before pulling them open according to the domain's preconditions."}
Differences: 1. **Specificity of Drawers**  
   - TASK: "Slide open two of the drawers." This is ambiguous as to which two drawers should be opened; any two drawers would satisfy the instruction.
   - CODE_FUNC: Specifies and opens the bottom drawer first, then the middle drawer. The top drawer is not considered.

2. **Order of Operations**  
   - TASK: Does not specify any order in which the drawers should be opened.
   - CODE_FUNC: Opens the bottom drawer first, then the middle drawer, in a fixed sequence.

3. **Error Handling**  
   - TASK: No mention of error handling or what to do if an error occurs.
   - CODE_FUNC: Includes error handling—if any error occurs during the actions, it prints an error message.

4. **Extent of Opening**  
   - TASK: "Slide open" could mean partially or fully open, depending on interpretation.
   - CODE_FUNC: Explicitly opens each drawer "fully."

5. **Implicit Preconditions**  
   - TASK: Does not specify preconditions such as the drawers being unlocked, handles being present, or the robot's initial state.
   - CODE_FUNC: Assumes the robot can grasp the handle and the drawer can be pulled open (implies preconditions are met).

6. **Coverage of Drawers**  
   - TASK: Could refer to any two drawers out of three (bottom, middle, top).
   - CODE_FUNC: Only ever opens the bottom and middle drawers, never the top.

7. **Sequentiality**  
   - TASK: Does not specify whether the drawers must be opened sequentially or in parallel.
   - CODE_FUNC: Opens drawers strictly one after the other.

8. **Feedback/Output**  
   - TASK: No mention of output or feedback.
   - CODE_FUNC: Prints an error message if something goes wrong.

9. **Assumed Robot Actions**  
   - TASK: Does not specify how the drawers are to be opened (e.g., by handle, by pushing, etc.).
   - CODE_FUNC: Specifies that the robot grasps the handle and pulls to open.

10. **Partial vs. Complete Action**  
    - TASK: "Slide open" could be interpreted as opening partially or fully.
    - CODE_FUNC: Opens each drawer "fully," not partially.

---

**Summary:**  
The main semantic differences are in specificity (which drawers, order, and extent of opening), error handling, and the explicitness of the robot's actions and feedback. The TASK is more general and ambiguous, while the CODE_FUNC is more specific and prescriptive.

Refined Code Generated:
-------------------
"""Module to slide open any two drawers using the robot controller."""
from Object_list import Object
from skill_mapping import RobotController

def long_horizon_task2_oracle_seq():
    """Slides open any two drawers."""
    robot = RobotController()
    drawer_handles = [
        "drawer_bottom_handle",
        "drawer_middle_handle",
        "drawer_top_handle"
    ]
    drawers_opened = 0

    for handle_name in drawer_handles:
        try:
            # Pick the handle at ready-pose (axis=0 for handle)
            robot.execute_movement(Object[handle_name], mode=1, axis=0)
            # Unlock the drawer (mode=3 for unlock, axis=0)
            robot.execute_movement(Object[handle_name], mode=3, axis=0)
            # Pull the drawer using the handle (mode=4, axis=0, distance=0.1 for full pull)
            robot.execute_movement(Object[handle_name], mode=4, axis=0, distance=0.1)
            drawers_opened += 1
            if drawers_opened == 2:
                break
        except Exception as error:
            print(f"Error during task execution: {error}")
            break

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

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

=== Instruction 5 ===
Is Correct: False
Syntax Pass: False
Code Function: This code controls a robot to sequentially open three drawers (bottom, middle, and top) by first picking each drawer's handle and then pulling the drawer open. For each drawer, the robot first grasps the handle and then pulls it by a specified distance. The process is repeated for all three drawers, and any errors during the actions are caught and printed. The main function runs this sequence when the script is executed.
Similarity: {'ok': False, 'reason': 'The code does not check whether a drawer is locked before attempting to open it, so it may try to open locked drawers, which does not satisfy the instruction to only uncover drawers that aren’t locked.'}
Differences: 1. **Conditionality on Lock State**  
   - **TASK**: Specifies to "uncover every drawer that isn’t locked," i.e., only drawers that are *not locked* should be opened.
   - **CODE_FUNC**: Opens all three drawers (bottom, middle, top) sequentially, with no mention or check of whether a drawer is locked or unlocked.

2. **Completeness of Drawer Set**  
   - **TASK**: The set of drawers to be opened is determined dynamically by their lock state; only unlocked drawers are to be opened.
   - **CODE_FUNC**: The set of drawers to be opened is statically defined as all three drawers, regardless of their lock state.

3. **Error Handling**  
   - **TASK**: Does not specify what to do if a drawer is locked or cannot be opened.
   - **CODE_FUNC**: Catches and prints errors during the open sequence, but still attempts to open all drawers regardless of lock state.

4. **Definition of "Uncover"**  
   - **TASK**: Uses the term "uncover," which in the PDDL context maps to opening a drawer (i.e., making (drawer-open ?d) true).
   - **CODE_FUNC**: Assumes "uncover" means to open the drawer by pulling after picking the handle, which matches the PDDL action, but this is an implicit mapping.

5. **Precondition Satisfaction**  
   - **TASK**: Implies the robot should only attempt to open drawers where the precondition (drawer-unlocked) is satisfied.
   - **CODE_FUNC**: Does not check or ensure the precondition (drawer-unlocked) before attempting to open each drawer.

6. **Order of Operations**  
   - **TASK**: Does not specify any order in which drawers should be opened.
   - **CODE_FUNC**: Opens drawers in a fixed order: bottom, middle, top.

7. **Extensibility**  
   - **TASK**: Would generalize to any number of drawers and any lock state.
   - **CODE_FUNC**: Hardcodes the number and identity of drawers.

8. **Action Selection**  
   - **TASK**: Requires a conditional selection of drawers based on their lock state.
   - **CODE_FUNC**: No conditional selection; all drawers are processed identically.

9. **State Awareness**  
   - **TASK**: Implies awareness of the current state (locked/unlocked) of each drawer.
   - **CODE_FUNC**: No state checking; assumes all drawers can be opened.

10. **Potential for No-Op**  
    - **TASK**: If all drawers are locked, the robot does nothing.
    - **CODE_FUNC**: Will attempt to open all drawers regardless, possibly resulting in errors.

---

**Summary:**  
The main semantic difference is that the TASK requires conditional action based on the lock state of each drawer, while the CODE_FUNC unconditionally attempts to open all drawers, ignoring their lock state.

Refined Code Generated:
-------------------
"""Module to uncover every drawer that isn’t locked by opening only unlocked drawers."""
from Object_list import Object
from skill_mapping import RobotController

def long_horizon_task2_oracle_seq():
    """Uncover every drawer that isn’t locked by opening only unlocked drawers."""
    robot = RobotController()

    # List of drawers and their corresponding handles
    drawers = [
        {"drawer": "drawer_bottom", "handle": "drawer_bottom_handle"},
        {"drawer": "drawer_middle", "handle": "drawer_middle_handle"},
        {"drawer": "drawer_top", "handle": "drawer_top_handle"},
    ]

    for item in drawers:
        drawer_name = item["drawer"]
        handle_name = item["handle"]

        # Check if the drawer is unlocked before attempting to open
        try:
            if robot.is_drawer_unlocked(drawer_name):
                try:
                    robot.execute_movement(Object[handle_name], mode=1, axis=0)
                except Exception as pick_error:
                    print(f"Error in execute_pick for {handle_name}: {pick_error}")
                    continue

                try:
                    robot.execute_movement(Object[handle_name], mode=4, distance=0.1)
                except Exception as pull_error:
                    print(f"Error in execute_pull for {handle_name}: {pull_error}")
            else:
                print(f"Skipped {drawer_name}: drawer is locked.")
        except Exception as state_error:
            print(f"Error checking lock state for {drawer_name}: {state_error}")

def main():
    """Main entry point to uncover unlocked drawers."""
    long_horizon_task2_oracle_seq()

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

