Skip to content
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

Open
wants to merge 11 commits into
base: sc_refinement
Choose a base branch
from

Conversation

v-heli
Copy link

@v-heli v-heli commented Jun 16, 2022

Description

Added reset teset and fixed distribution unit reset issue in supply chain scenarios

Type of Change

  • Non-breaking bug fix
  • Test

Related Component

  • Simulation toolkit

Has Been Tested

  • OS:
    • Windows
  • Python version:
    • 3.9
  • Key information snapshot(s):

Needs Follow Up Actions

  • New release package
  • New docker image

Checklist

  • Add/update the related comments
  • Add/update the related tests
  • Add/update the related documentations
  • Update the dependent downstream modules usage

@v-heli v-heli requested review from lihuoran and Jinyu-W June 16, 2022 04:35

# ##################################### Before reset #####################################

order_1 = Order(
Copy link
Collaborator

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?

Copy link
Author

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.

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())
Copy link
Collaborator

Choose a reason for hiding this comment

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

why sum them up?

Copy link
Author

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().


class MyTestCase(unittest.TestCase):
"""
. consumer unit test
Copy link
Collaborator

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.

Copy link
Author

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
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)
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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 = (
Copy link
Collaborator

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):
Copy link
Collaborator

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.
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants