ds4dm / ecole

Extensible Combinatorial Optimization Learning Environments
https://www.ecole.ai
BSD 3-Clause "New" or "Revised" License
318 stars 68 forks source link

How to train on datasets containing general integers #367

Open samwu-learn opened 11 months ago

samwu-learn commented 11 months ago

Describe the bug

Setting

To Reproduce

episode_counter, sample_counter = 0, 0 Path("samples/").mkdir(exist_ok=True)

We will solve problems (run episodes) until we have saved enough samples

while sample_counter < DATA_MAX_SAMPLES: episode_counter += 1

observation, action_set, _, done, _ = env.reset(next(instances))
while not done:
    (scores, scores_are_expert), node_observation = observation
    action = action_set[scores[action_set].argmax()]

    # Only save samples if they are coming from the expert (strong branching)
    if scores_are_expert and (sample_counter < DATA_MAX_SAMPLES):
        sample_counter += 1
        data = [node_observation, action, action_set, scores]
        filename = f"samples/sample_{sample_counter}.pkl"

        with gzip.open(filename, "wb") as f:
            pickle.dump(data, f)

    observation, action_set, _, done, _ = env.step(action)

print(f"Episode {episode_counter}, {sample_counter} samples collected so far")

In the above code(code in ecole /example.ipynb) , if the input instance contains an integer, the done variable is always true, and a pkl file cannot be generated for this instance,

Expected behavior

Additional context

I would greatly appreciate it with your generous assistance.