microsoft/qlib · error · SeedIteratorNotAvailable
Seed iterator for training is not available.
Error message
Seed iterator for training is not available.
What it means
SeedIteratorNotAvailable raised by the default `Vessel.train_seed_iterator` (qlib/rl/trainer/vessel.py:56). A vessel is abstract: subclasses must override the seed-iterator hooks so the trainer knows which simulator initial states to train on. Calling the base implementation signals the override is missing.
Source
Thrown at qlib/rl/trainer/vessel.py:56
The ship also defines the most important logic of the core training part,
and (optionally) some callbacks to insert customized logics at specific events.
"""
simulator_fn: Callable[[InitialStateType], Simulator[InitialStateType, StateType, ActType]]
state_interpreter: StateInterpreter[StateType, ObsType]
action_interpreter: ActionInterpreter[StateType, PolicyActType, ActType]
policy: BasePolicy
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]:View on GitHub (pinned to 79633dd950)
Solutions
- Override `train_seed_iterator` in your vessel to return an iterable of initial states (e.g. a generator over order/date combinations), optionally a context-manager iterable for resource lifecycle.
- Model it on `OrderExecutionVessel` / existing vessels in the codebase that yield seeds from an order list.
- If training is genuinely unsupported for this vessel, catch `SeedIteratorNotAvailable` at the call site and skip the fit phase with a clear log.
Example fix
// before
class MyVessel(Vessel):
def train(self, venv): ...
# train_seed_iterator missing -> SeedIteratorNotAvailable
// after
class MyVessel(Vessel):
def train_seed_iterator(self):
return iter(self.order_list) # iterable of initial states
def train(self, venv): ... Defensive patterns
Strategy: validation
Validate before calling
from qlib.rl.trainer.vessel import Vessel
def train_seeds_available(vessel: Vessel) -> bool:
return type(vessel).train_seed_iterator is not Vessel.train_seed_iterator Type guard
def is_trainable_vessel(v) -> bool:
from qlib.rl.trainer.vessel import Vessel
return (
type(v).train_seed_iterator is not Vessel.train_seed_iterator
and type(v).train is not Vessel.train
) Try / catch
from qlib.rl.trainer.vessel import SeedIteratorNotAvailable
try:
seeds = vessel.train_seed_iterator()
except SeedIteratorNotAvailable:
raise RuntimeError("override train_seed_iterator before calling Trainer.fit") from None Prevention
- Treat vessel seed hooks as required abstract methods when adapting to a new task.
- Copy the seed-iterator trio (train/val/test) from an existing vessel first.
- Fail fast in vessel __init__ if seed sources (e.g. order lists) are empty.
When it happens
Trigger: Implementing a custom `Vessel` subclass that provides `train`/`validate`/`test` but not `train_seed_iterator`; passing a vessel instance whose seed methods were left at defaults into `Trainer.fit(train_vessel, ...)`.
Common situations: Adapting the RL workflow to a new task and copying only the train loop; refactor renaming the method so the override is lost; using the vessel in a context where training is not intended (then use a vessel that explicitly raises or skip fit).
Related errors
- Seed iterator for validation is not available.
- Seed iterator for testing is not available.
- Implement reward calculation recipe in `reward()`.
- Unsupported earlystopping mode: {mode}
- Render is not implemented in EnvWrapper.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/4e48033b065df9c8.
Report an issue: GitHub.