Skip to content

V2.0.0#66

Merged
Pabloo22 merged 60 commits intoPabloo22:v2-devfrom
bikuta6:v2.0.0
Oct 12, 2025
Merged

V2.0.0#66
Pabloo22 merged 60 commits intoPabloo22:v2-devfrom
bikuta6:v2.0.0

Conversation

@bikuta6
Copy link

@bikuta6 bikuta6 commented Aug 13, 2025

Jobshopgraph connectivity + id changes
Single jobshopgraph adapted to new graph (WIP)

bikuta6 and others added 11 commits June 27, 2025 10:52
…ntified and managed within the `JobShopGraph` and `Node` classes.

* **Node Class:**    * The `node_id` type hint in the `Node` class has been updated from `int` to a `tuple[str, int]`. This allows for more granular identification of nodes by their type (as a string) and a local integer ID unique within that type.

* **JobShopGraph Class:**
    * **New Attribute:** Introduced `_nodes_map` (type: `dict[tuple[str, int], Node]`), a dictionary mapping node tuple IDs to their corresponding `Node` objects for quick lookup.
    * The `_next_node_id` attribute has been refactored from a single integer to a dictionary (`dict[str, int]`). This dictionary now maps each node type (string) to its next available local ID, enabling type-specific ID generation.
    * The `add_node` method has been updated to leverage this new `_next_node_id` dictionary, ensuring new nodes receive IDs conforming to the `(type, local_id)` tuple structure.
    * The `removed_nodes` attribute and the `remove_node` method have been similarly refactored to use the dictionary-based tracking by node type and local ID, allowing for efficient management of removed nodes.
    * Documentation throughout `JobShopGraph` has been updated to reflect these changes in node ID handling.

* **Tests:**
    * All relevant existing tests within the `graph` module have been refactored to account for the new tuple-based node ID behavior, ensuring test suite compatibility.
    * Specifically, the assertion for `NetworkXError` on removed nodes was adjusted: The test code was changed from `with pytest.raises(nx.NetworkXError): list(graph.graph.edges(last_removed_node_id))` (which incorrectly did not raise an error as `edges()` returns an empty list for non-existent nodes) to **attempting to remove an edge involving a non-existent node**, which correctly triggers `nx.NetworkXError`.

**Pending/Known Issues (to be addressed in subsequent commits/PRs):**

* Tests related to the `SingleJobShopGraphEnv` may not yet pass due to further integration work required.
* Specific fixes and enhancements for the `plot` and `reinforcement learning` modules (including `plot_disjunctive_graph` and `plot_resource_task_graph`) are still pending and will be addressed separately.
changed color mapping to fit new ids
ID consistency in directed disjunctive graph creation + style corrections
Removed nx digraph, only kept for testing and plots as property, built when called.

New edge_index dict attribute contains edges per type, each edge being 2 nodes objects (src, tgt)
Documentation changes to reflect local ids (node_type, local_id)
Minor changes, more efficient nx graph creation
@bikuta6
Copy link
Author

bikuta6 commented Aug 13, 2025

New id changes for jobshopgraph

@Pabloo22 Pabloo22 requested a review from Copilot August 13, 2025 11:15
@Pabloo22 Pabloo22 added this to the v2.0.0 milestone Aug 13, 2025
@Pabloo22 Pabloo22 added enhancement New feature or request refactor and removed enhancement New feature or request labels Aug 13, 2025
@Pabloo22
Copy link
Owner

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant and well-thought-out refactoring of the JobShopGraph class, moving from a networkx-based implementation to a custom, more efficient adjacency list representation. The change of node identifiers to a (type, local_id) tuple is a solid design choice for heterogeneous graphs. The related changes in the reinforcement learning environment and visualization components are consistent with this new architecture.

My review focuses on improving encapsulation, fixing a minor typo, and cleaning up test code. I've also noted that several tests are currently skipped, which is understandable for a work-in-progress of this scale, but they should be re-enabled before the final merge. Overall, this is a great step forward for the library's architecture.

Comment on lines 83 to 94
graph.add_edge(
scheduled_operation.operation.operation_id,
next_scheduled_operation.operation.operation_id,
graph._nodes_map[
("OPERATION", scheduled_operation.operation.operation_id)
],
graph._nodes_map[
(
"OPERATION",
next_scheduled_operation.operation.operation_id,
)
],
type=EdgeType.DISJUNCTIVE,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The code directly accesses the private _nodes_map attribute of the JobShopGraph instance. It's better to use the public API to fetch nodes to improve encapsulation and maintainability. The JobShopGraph class provides a get_operation_node method for this purpose, which makes the code cleaner and more robust to future changes in the JobShopGraph implementation.

            graph.add_edge(
                graph.get_operation_node(scheduled_operation.operation.operation_id),
                graph.get_operation_node(
                    next_scheduled_operation.operation.operation_id
                ),
                type=EdgeType.DISJUNCTIVE,
            )

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

- Fixed untested disjunctive graph updater to account for mutable node ids
- Skipped observation space tests due to variable shapes is observations
- edge index is now generated on jobshopgraph
- Now there can be multiple disjunctive and conjunctive edgetypes, to account for tuple edgettypes
- Deleted removed_nodes key from observation, as the mask for removed nodes is created on the get_observation method of single jobshopgraph environment
skipped tests:
 - single and multijobshopgraph envs observation space and padding tests, due to observations now being mutable in size, causing errors on observation spaces and padding not being needed due to new observations structures more adapted to pytorch geometric's HeteroData object.

Now observation key REMOVED NODES no longer exists, for it has no use, since removed node features are discarded during observation creation.
Replaces flat node feature keys in the observation dictionary with a nested 'node_features_dict' keyed by FeatureType values. Updates environment, observation space, and tests to use the new structure, improving clarity and extensibility for heterogeneous graph observations.
Local operation id added for available operations, job and machine nodes not handled yet
Standardizes node type names to lowercase throughout the codebase for consistency and correctness. Adds 'available_operations_with_ids' as an action mask to the observation dictionary in the reinforcement learning environment, updates related logic and tests, and adjusts action selection to use this mask, now actions being tuples of (operation_node_id, machine_node_id). Updates test and utility code to match the new conventions.
Pabloo22 and others added 12 commits September 13, 2025 21:23
…Pabloo22#75)

Adds functional `modular_instance_generator` and related functions. It also refactors the organization of the module and deprecates the `InstanceGenerator` interface.

- Implemented duration matrix generation with validation.
- Created machine matrix generation functions with and without recirculation.
- Developed modular instance generator for creating job shop instances.
- Added release date matrix generation with various strategies.
- Introduced size selectors for dynamic job and machine counts.
- Added comprehensive tests for duration matrix, machine matrix, modular instance generator, release date matrix, and size selectors.
- Removed outdated test file for generation utilities.
instead of the deprecated `durations_matrix_array`
…rculation`

Correct machine matrix shape and add validation for job and machine counts
…ntified and managed within the `JobShopGraph` and `Node` classes.

* **Node Class:**    * The `node_id` type hint in the `Node` class has been updated from `int` to a `tuple[str, int]`. This allows for more granular identification of nodes by their type (as a string) and a local integer ID unique within that type.

* **JobShopGraph Class:**
    * **New Attribute:** Introduced `_nodes_map` (type: `dict[tuple[str, int], Node]`), a dictionary mapping node tuple IDs to their corresponding `Node` objects for quick lookup.
    * The `_next_node_id` attribute has been refactored from a single integer to a dictionary (`dict[str, int]`). This dictionary now maps each node type (string) to its next available local ID, enabling type-specific ID generation.
    * The `add_node` method has been updated to leverage this new `_next_node_id` dictionary, ensuring new nodes receive IDs conforming to the `(type, local_id)` tuple structure.
    * The `removed_nodes` attribute and the `remove_node` method have been similarly refactored to use the dictionary-based tracking by node type and local ID, allowing for efficient management of removed nodes.
    * Documentation throughout `JobShopGraph` has been updated to reflect these changes in node ID handling.

* **Tests:**
    * All relevant existing tests within the `graph` module have been refactored to account for the new tuple-based node ID behavior, ensuring test suite compatibility.
    * Specifically, the assertion for `NetworkXError` on removed nodes was adjusted: The test code was changed from `with pytest.raises(nx.NetworkXError): list(graph.graph.edges(last_removed_node_id))` (which incorrectly did not raise an error as `edges()` returns an empty list for non-existent nodes) to **attempting to remove an edge involving a non-existent node**, which correctly triggers `nx.NetworkXError`.

**Pending/Known Issues (to be addressed in subsequent commits/PRs):**

* Tests related to the `SingleJobShopGraphEnv` may not yet pass due to further integration work required.
* Specific fixes and enhancements for the `plot` and `reinforcement learning` modules (including `plot_disjunctive_graph` and `plot_resource_task_graph`) are still pending and will be addressed separately.
Deleted observation wrapper and test for resource task graph observations, as it is no longer needed, changes are handled directly by single job shop graph env
@Pabloo22 Pabloo22 marked this pull request as ready for review September 13, 2025 19:45
Pabloo22 and others added 7 commits September 13, 2025 21:46
…ntified and managed within the `JobShopGraph` and `Node` classes.

* **Node Class:**    * The `node_id` type hint in the `Node` class has been updated from `int` to a `tuple[str, int]`. This allows for more granular identification of nodes by their type (as a string) and a local integer ID unique within that type.

* **JobShopGraph Class:**
    * **New Attribute:** Introduced `_nodes_map` (type: `dict[tuple[str, int], Node]`), a dictionary mapping node tuple IDs to their corresponding `Node` objects for quick lookup.
    * The `_next_node_id` attribute has been refactored from a single integer to a dictionary (`dict[str, int]`). This dictionary now maps each node type (string) to its next available local ID, enabling type-specific ID generation.
    * The `add_node` method has been updated to leverage this new `_next_node_id` dictionary, ensuring new nodes receive IDs conforming to the `(type, local_id)` tuple structure.
    * The `removed_nodes` attribute and the `remove_node` method have been similarly refactored to use the dictionary-based tracking by node type and local ID, allowing for efficient management of removed nodes.
    * Documentation throughout `JobShopGraph` has been updated to reflect these changes in node ID handling.

* **Tests:**
    * All relevant existing tests within the `graph` module have been refactored to account for the new tuple-based node ID behavior, ensuring test suite compatibility.
    * Specifically, the assertion for `NetworkXError` on removed nodes was adjusted: The test code was changed from `with pytest.raises(nx.NetworkXError): list(graph.graph.edges(last_removed_node_id))` (which incorrectly did not raise an error as `edges()` returns an empty list for non-existent nodes) to **attempting to remove an edge involving a non-existent node**, which correctly triggers `nx.NetworkXError`.

**Pending/Known Issues (to be addressed in subsequent commits/PRs):**

* Tests related to the `SingleJobShopGraphEnv` may not yet pass due to further integration work required.
* Specific fixes and enhancements for the `plot` and `reinforcement learning` modules (including `plot_disjunctive_graph` and `plot_resource_task_graph`) are still pending and will be addressed separately.
Deleted observation wrapper and test for resource task graph observations, as it is no longer needed, changes are handled directly by single job shop graph env
@Pabloo22 Pabloo22 requested a review from Copilot September 24, 2025 10:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 33 out of 42 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

job_shop_lib/reinforcement_learning/_single_job_shop_graph_env.py:307

  • The docstring for the reset method still mentions returning 'available_operations_with_ids' in the info dictionary, but the implementation on line 331 no longer includes this key. The docstring should be updated to reflect the actual return structure.
        self,
        *,
        seed: int | None = None,
        options: dict[str, Any] | None = None,
    ) -> tuple[ObservationDict, dict[str, Any]]:

job_shop_lib/reinforcement_learning/_single_job_shop_graph_env.py:335

  • The docstring for the step method still mentions returning 'available_operations_with_ids' in the info dictionary, but the implementation no longer includes this key. The docstring should be updated to match the actual implementation.
        self, action: tuple[int, int]
    ) -> tuple[ObservationDict, float, bool, bool, dict[str, Any]]:

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 85.77406% with 34 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
job_shop_lib/graphs/_job_shop_graph.py 92.36% 11 Missing ⚠️
...einforcement_learning/_multi_job_shop_graph_env.py 26.66% 11 Missing ⚠️
...raphs/graph_updaters/_disjunctive_graph_updater.py 0.00% 8 Missing ⚠️
job_shop_lib/graphs/_node.py 80.00% 2 Missing ⚠️
...inforcement_learning/_single_job_shop_graph_env.py 95.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Pabloo22 and others added 5 commits October 2, 2025 14:17
Matplotlib renders slightly differently across platforms (fonts, antialiasing, layout backends), so a baseline captured on Linux won’t match macOS pixel-for-pixel.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Pabloo22 Pabloo22 changed the base branch from main to v2-dev October 12, 2025 09:51
@Pabloo22 Pabloo22 merged commit 901ccef into Pabloo22:v2-dev Oct 12, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Update node IDs from local to global v2.0.0: Improve RL environments support for heterogeneous graphs

5 participants