code: def main(config):
      try:
          import pandas as pd
      except ModuleNotFoundError:
          print(
              "This task requires pandas,"
              'run "pip install -U pandas" to install.'
          )
          sys.exit(1)
  
      log_dir = "./log/mdkp"
      if not os.path.exists(log_dir):
          os.makedirs(log_dir, exist_ok=True)
      logger = util.create_logger(
          name="MDKP", log_dir=log_dir, debug=config.debug
      )
  
      logger.info("MDKP Demo")
      logger.info("=" * 30)
  
      train_task = MDKP(
          items_csv=config.item_csv,
          capacity_csv=config.cap_csv,
          use_synthesized_data=config.use_synthesized_data,
          test=False,
      )
      test_task = MDKP(
          items_csv=config.item_csv,
          capacity_csv=config.cap_csv,
          use_synthesized_data=config.use_synthesized_data,
          test=True,
      )
      policy = MDKPPolicy(
          num_bins=train_task.act_shape[0],
          num_items=train_task.act_shape[1],
      )
      solver = SimpleGA(
          pop_size=config.pop_size,
          param_size=policy.num_params,
          logger=logger,
          seed=config.seed,
      )
  
      # Train.
      trainer = Trainer(
          policy=policy,
          solver=solver,
          train_task=train_task,
          test_task=test_task,
          max_iter=config.max_iter,
          log_interval=config.log_interval,
          test_interval=config.test_interval,
          n_repeats=1,
          n_evaluations=1,
          seed=config.seed,
          log_dir=log_dir,
          logger=logger,
      )
      trainer.run(demo_mode=False)
  
      # Summarize the final result.
      logger.info("")
      logger.info("Summary of results")
      logger.info("=" * 30)
      logger.info(
          "Number of attributes: {}".format(test_task.num_attrs)
      )
      logger.info("Number of items: {}".format(test_task.num_items))
      logger.info("Number of bins: {}".format(test_task.num_bins))
      logger.info("Caps: {}".format(test_task.caps))
      best_params = trainer.solver.best_params[None, :]
      task_reset_fn = jax.jit(test_task.reset)
      policy_reset_fn = jax.jit(policy.reset)
      step_fn = jax.jit(test_task.step)
      act_fn = jax.jit(policy.get_actions)
      rollout_key = jax.random.PRNGKey(seed=0)[None, :]
      task_s = task_reset_fn(rollout_key)
      policy_s = policy_reset_fn(task_s)
      act, policy_s = act_fn(task_s, best_params, policy_s)
      task_s, reward, _ = step_fn(task_s, act)
      selections = np.array(act)[0]
      bin_assignment = (
          selections * (np.arange(test_task.num_bins)[:, None] + 1)
      ).sum(axis=0)
      results = np.hstack([test_task.items, bin_assignment[:, None]])
      num_selected_items = int(selections.sum())
      if reward == 0:
          logger.info("No valid solution is found.")
      else:
          result_csv = os.path.join(log_dir, "results.csv")
          pd.DataFrame(results).to_csv(result_csv, header=None)
          logger.info(
              "Number of selected items: {}".format(num_selected_items)
          )
          logger.info("Total value: {}".format(float(reward)))
          logger.info("Results saved to {}".format(result_csv))
  
file_path: evojax/examples/train_mdkp.py
imports: import argparse
  import os
  import sys
  import numpy
  from typing import Tuple
  import jax
  import jax.numpy
  from evojax import Trainer
  from evojax.task.mdkp import MDKP
  from evojax.task.mdkp import TaskState
  from evojax.policy import PolicyNetwork
  from evojax.policy.base import PolicyState
  from evojax.algo import SimpleGA
  from evojax import util
label_desc: Use image node_id 2 for calling a global function with example usage: main(config) without return types