microsoft/qlib · error · SeedIteratorNotAvailable

Seed iterator for testing is not available.

Error message

Seed iterator for testing is not available.

What it means

SeedIteratorNotAvailable from the default `Vessel.test_seed_iterator` (qlib/rl/trainer/vessel.py:64). The trainer obtains test-environment initial states from this hook; the base class intentionally raises because it cannot know your task's test set.

Source

Thrown at qlib/rl/trainer/vessel.py:64

    reward: Reward
    trainer: Trainer

    def assign_trainer(self, trainer: Trainer) -> None:
        self.trainer = weakref.proxy(trainer)  # type: ignore

    def train_seed_iterator(self) -> ContextManager[Iterable[InitialStateType]] | Iterable[InitialStateType]:
        """Override this to create a seed iterator for training.
        If the iterable is a context manager, the whole training will be invoked in the with-block,
        and the iterator will be automatically closed after the training is done."""
        raise SeedIteratorNotAvailable("Seed iterator for training is not available.")

    def val_seed_iterator(self) -> ContextManager[Iterable[InitialStateType]] | Iterable[InitialStateType]:
        """Override this to create a seed iterator for validation."""
        raise SeedIteratorNotAvailable("Seed iterator for validation is not available.")

    def test_seed_iterator(self) -> ContextManager[Iterable[InitialStateType]] | Iterable[InitialStateType]:
        """Override this to create a seed iterator for testing."""
        raise SeedIteratorNotAvailable("Seed iterator for testing is not available.")

    def train(self, vector_env: BaseVectorEnv) -> Dict[str, Any]:
        """Implement this to train one iteration. In RL, one iteration usually refers to one collect."""
        raise NotImplementedError()

    def validate(self, vector_env: FiniteVectorEnv) -> Dict[str, Any]:
        """Implement this to validate the policy once."""
        raise NotImplementedError()

    def test(self, vector_env: FiniteVectorEnv) -> Dict[str, Any]:
        """Implement this to evaluate the policy on test environment once."""
        raise NotImplementedError()

    def log(self, name: str, value: Any) -> None:
        # FIXME: this is a workaround to make the log at least show somewhere.
        # Need a refactor in logger to formalize this.
        if isinstance(value, (np.ndarray, list)):
            value = np.mean(value)

View on GitHub (pinned to 79633dd950)

Solutions

  1. Override `test_seed_iterator` to yield the held-out test initial states.
  2. Mirror the structure of `train_seed_iterator` with your test split (orders/dates excluded from train and val).
  3. If test evaluation is optional in your script, gate it behind a config flag so the hook is only required when testing is enabled.

Example fix

// before
trainer.test(my_vessel)  # vessel lacks test_seed_iterator
// after
class MyVessel(Vessel):
    def test_seed_iterator(self): return iter(test_orders)
trainer.test(my_vessel)
Defensive patterns

Strategy: validation

Validate before calling

from qlib.rl.trainer.vessel import Vessel

def test_seeds_available(vessel: Vessel) -> bool:
    return type(vessel).test_seed_iterator is not Vessel.test_seed_iterator

Type guard

def vessel_supports_testing(v) -> bool:
    from qlib.rl.trainer.vessel import Vessel
    return type(v).test_seed_iterator is not Vessel.test_seed_iterator

Try / catch

from qlib.rl.trainer.vessel import SeedIteratorNotAvailable
try:
    metrics = trainer.test(vessel)
except SeedIteratorNotAvailable:
    log.warning("test seed iterator missing; skip evaluation")
    metrics = {}

Prevention

When it happens

Trigger: Calling `trainer.test(vessel)` (or a workflow step that evaluates on a test split) with a vessel that does not override `test_seed_iterator`.

Common situations: Running the standard train->test pipeline where only train/val hooks were implemented; renaming to `test_seed_iter` in a refactor; expecting the trainer to fall back to the validation iterator automatically (it does not).

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/2eb14693a52c50b6. Report an issue: GitHub.