-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added reset teset in supply chain scenarios #550
base: sc_refinement
Are you sure you want to change the base?
Conversation
tests/supply_chain/test_env_reset.py
Outdated
|
||
# ##################################### Before reset ##################################### | ||
|
||
order_1 = Order( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we place specific order_1, order_2, order_3, and also orders in random ticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea I set up like this is that order_1, order_2, order_3, are their own unit functions. Then the random ticks later is because, I think the current order needs to be passed in the current env.tick, which will affect the expected_finish_tick. So the purpose is to randomly tick several orders in the set rounds to make the test more perfect.
tests/supply_chain/test_env_reset.py
Outdated
env.step(None) | ||
env_metric_1[i] = env.metrics | ||
states_1[i] = list(storage_nodes[i:storage_node_index:features].flatten().astype(np.int)) | ||
states_1[i].append(storage_nodes[i:storage_node_index:"product_id_list"].flatten().astype(np.int).sum()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why sum them up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand it this way, because many attributes of the snapshot inch of storage are NodeAttributeAccessor objects, which are of ndarray type after being taken out from the snapshot. I was afraid that it would be difficult to compare, so I added sum().
tests/supply_chain/test_env_reset.py
Outdated
|
||
class MyTestCase(unittest.TestCase): | ||
""" | ||
. consumer unit test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to separate the snapshots checking of different units into different tests.
Maybe you can organize the tests to:
- test env reset with None action
- test env reset with ManufactureAction only
- test env reset with ConsumerAction only
- test env reset with both ManufactureAction and ConsumerAction
and also enrich the action onwer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will modify it in the direction you said.
Add reset test in sc scene and fix the problem found by reset test
Modify test according to comments
Modify test according to comments ++
env_metric_1[i] = env.metrics | ||
|
||
for idx in range(len(consumer_nodes)): | ||
states_1_consumer[i][idx] = consumer_nodes[i:idx:consumer_features].flatten().astype(np.int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some are int, some are float
|
||
# snapshot should reset after env.reset(). | ||
for idx in range(len(manufacture_nodes)): | ||
states = manufacture_nodes[1:idx:manufacture_features].flatten().astype(np.int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use frame_index 1?
states = seller_nodes[1:idx:seller_features].flatten().astype(np.int) | ||
self.assertEqual([0, 0, 0, 0, 0, 0, 0, 0], list(states)) | ||
|
||
expect_tick = 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to re-claim expect_tick
manufacture_nodes = env.snapshot_list["manufacture"] | ||
distribution_nodes = env.snapshot_list["distribution"] | ||
|
||
consumer_features = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can put these features in common, no need to re-claim them in each test function
states_2_manufacture: Dict[int, dict] = defaultdict(dict) | ||
states_2_distribution: Dict[int, dict] = defaultdict(dict) | ||
|
||
for i in range(expect_tick): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
you can wrap line 110-130 as a function, so as to reduce the redundant code(current line 170-190, similar parts in other test functions)
-
snapshot can be accessed (all ticks) only once at the end of the simulation.
@@ -0,0 +1,790 @@ | |||
# Copyright (c) Microsoft Corporation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both file test_action_reset
and test_env_reset
in this PR, prefer the naming test_env_reset
Modify test according to comments +++
Description
Added reset teset and fixed distribution unit reset issue in supply chain scenarios
Type of Change
Related Component
Has Been Tested
Needs Follow Up Actions
Checklist