2. Space Classes and Space Utilities¶
2.1. Space Base Class Reference¶
-
class
rlgraph.spaces.space.
Space
(add_batch_rank=False, add_time_rank=False, time_major=False)[source]¶ Bases:
rlgraph.utils.specifiable.Specifiable
Space class (based on and compatible with openAI Spaces). Provides a classification for state-, action-, reward- and other spaces.
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
flat_dim
¶ - Returns:
- int: The length of a flattened vector derived from this Space.
-
flatten
(mapping=None, custom_scope_separator='/', scope_separator_at_start=True, scope_=None, list_=None)[source]¶ A mapping function to flatten this Space into an OrderedDict whose only values are primitive (non-container) Spaces. The keys are created automatically from Dict keys and Tuple indexes.
- Args:
- mapping (Optional[callable]): A mapping function that takes a flattened auto-generated key and a primitive
- Space and converts the primitive Space to something else. Default is pass through.
- custom_scope_separator (str): The separator to use in the returned dict for scopes.
- Default: ‘/’.
- scope_separator_at_start (bool): Whether to add the scope-separator also at the beginning.
- Default: True.
scope_ (Optional[str]): For recursive calls only. Used for automatic key generation.
list_ (Optional[list]): For recursive calls only. The list so far.
- Returns:
- OrderedDict: The OrderedDict using auto-generated keys and containing only primitive Spaces
- (or whatever the mapping function maps the primitive Spaces to).
-
force_batch
(samples)[source]¶ Makes sure that samples is always returned with a batch rank no matter whether it already has one or not (in which case this method returns a batch of 1) or whether this Space has a batch rank or not.
- Args:
- samples (any): The samples to be batched. If already batched, return as-is.
- Returns:
- any: The batched sample.
-
get_shape
(with_batch_rank=False, with_time_rank=False, time_major=None, **kwargs)[source]¶ Returns the shape of this Space as a tuple with certain additional ranks at the front (batch) or the back (e.g. categories).
- Args:
- with_batch_rank (Union[bool,int]): Whether to include a possible batch-rank as None at 0th (or 1st)
- position. If with_batch_rank is an int (e.g. -1), the possible batch-rank is returned as that number (instead of None) at the 0th (or 1st if time_major is True) position. Default: False.
- with_time_rank (Union[bool,int]): Whether to include a possible time-rank as None at 1st (or 0th)
- position. If with_time_rank is an int, the possible time-rank is returned as that number (instead of None) at the 1st (or 0th if time_major is True) position. Default: False.
time_major (bool): Overwrites self.time_major if not None. Default: None (use self.time_major).
- Returns:
- tuple: The shape of this Space as a tuple.
-
get_variable
(name, is_input_feed=False, add_batch_rank=None, add_time_rank=None, time_major=False, is_python=False, local=False, **kwargs)[source]¶ Returns a backend-specific variable/placeholder that matches the space’s shape.
- Args:
name (str): The name for the variable.
- is_input_feed (bool): Whether the returned object should be an input placeholder,
- instead of a full variable.
- add_batch_rank (Optional[bool,int]): If True, will add a 0th (or 1st) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_batch_rank. Default: None.
- add_time_rank (Optional[bool,int]): If True, will add a 1st (or 0th) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_time_rank. Default: None.
- time_major (bool): Only relevant if both add_batch_rank and add_time_rank are True.
- Will make the time-rank the 0th rank and the batch-rank the 1st rank. Otherwise, batch-rank will be 0th and time-rank will be 1st. Default: False.
is_python (bool): Whether to create a python-based variable (list) or a backend-specific one.
- local (bool): Whether the variable must not be shared across the network.
- Default: False.
- Keyword Args:
- To be passed on to backend-specific methods (e.g. trainable, initializer, etc..).
- Returns:
- any: A Tensor Variable/Placeholder.
-
rank
¶ - Returns:
- int: The rank of the Space not including batch- or time-ranks (e.g. 3 for a space with shape=(10, 7, 5)).
-
sample
(size=None, fill_value=None)[source]¶ Uniformly randomly samples an element from this space. This is for testing purposes, e.g. to simulate a random environment.
- Args:
- size (Optional[int]): The number of samples or batch size to sample.
- If size is > 1: Returns a batch of size samples with the 0th rank being the batch rank (even if self.has_batch_rank is False). If size is None or (1 and self.has_batch_rank is False): Returns a single sample w/o batch rank. If size is 1 and self.has_batch_rank is True: Returns a single sample w/ the batch rank.
- fill_value (Optional[any]): The number or initializer specifier to fill the sample. Can be used to create
- a (non-random) sample with a certain fill value in all elements. TODO: support initializer spec-strings like ‘normal’, ‘truncated_normal’, etc..
- Returns:
- any: The sampled element(s).
-
shape
¶ - Returns:
- tuple: The shape of this Space as a tuple. Without batch or time ranks.
-
with_batch_rank
(add_batch_rank=True)[source]¶ Returns a deepcopy of this Space, but with has_batch_rank set to the provided value.
- Args:
- add_batch_rank (Union[bool,int]): The fixed size of the batch-rank or True or False.
- Returns:
- Space: The deepcopy of this Space, but with has_batch_rank set to True.
-
with_extra_ranks
(add_batch_rank=True, add_time_rank=True, time_major=False)[source]¶ Returns a deepcopy of this Space, but with has_batch_rank and has_time_rank set to the provided value. Use None to leave whatever value this Space has already.
- Args:
- add_batch_rank (Optional[bool]): If True or False, set the has_batch_rank property of the new Space
- to this value. Use None to leave the property as is.
- add_time_rank (Optional[bool]): If True or False, set the has_time_rank property of the new Space
- to this value. Use None to leave the property as is.
- time_major (Optional[bool]): Whether the time-rank should be the 0th rank (instead of the 1st by default).
- Not important if either batch_rank or time_rank are not set. Use None to leave the property as is.
- Returns:
- Space: The deepcopy of this Space, but with has_batch_rank set to True.
-
2.2. Box Spaces¶
-
class
rlgraph.spaces.box_space.
BoxSpace
(low, high, shape=None, add_batch_rank=False, add_time_rank=False, time_major=False, dtype=<class 'numpy.float32'>)[source]¶ Bases:
rlgraph.spaces.space.Space
A box in R^n with a shape tuple of len n. Each dimension may be bounded.
-
bounds
¶
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
flat_dim
¶ Returns: int: The length of a flattened vector derived from this Space.
-
force_batch
(samples)[source]¶ Makes sure that samples is always returned with a batch rank no matter whether it already has one or not (in which case this method returns a batch of 1) or whether this Space has a batch rank or not.
- Args:
- samples (any): The samples to be batched. If already batched, return as-is.
- Returns:
- any: The batched sample.
-
get_shape
(with_batch_rank=False, with_time_rank=False, time_major=None, **kwargs)[source]¶ Returns the shape of this Space as a tuple with certain additional ranks at the front (batch) or the back (e.g. categories).
- Args:
- with_batch_rank (Union[bool,int]): Whether to include a possible batch-rank as None at 0th (or 1st)
- position. If with_batch_rank is an int (e.g. -1), the possible batch-rank is returned as that number (instead of None) at the 0th (or 1st if time_major is True) position. Default: False.
- with_time_rank (Union[bool,int]): Whether to include a possible time-rank as None at 1st (or 0th)
- position. If with_time_rank is an int, the possible time-rank is returned as that number (instead of None) at the 1st (or 0th if time_major is True) position. Default: False.
time_major (bool): Overwrites self.time_major if not None. Default: None (use self.time_major).
- Returns:
- tuple: The shape of this Space as a tuple.
-
get_variable
(name, is_input_feed=False, add_batch_rank=None, add_time_rank=None, time_major=None, is_python=False, local=False, **kwargs)[source]¶ Returns a backend-specific variable/placeholder that matches the space’s shape.
- Args:
name (str): The name for the variable.
- is_input_feed (bool): Whether the returned object should be an input placeholder,
- instead of a full variable.
- add_batch_rank (Optional[bool,int]): If True, will add a 0th (or 1st) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_batch_rank. Default: None.
- add_time_rank (Optional[bool,int]): If True, will add a 1st (or 0th) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_time_rank. Default: None.
- time_major (bool): Only relevant if both add_batch_rank and add_time_rank are True.
- Will make the time-rank the 0th rank and the batch-rank the 1st rank. Otherwise, batch-rank will be 0th and time-rank will be 1st. Default: False.
is_python (bool): Whether to create a python-based variable (list) or a backend-specific one.
- local (bool): Whether the variable must not be shared across the network.
- Default: False.
- Keyword Args:
- To be passed on to backend-specific methods (e.g. trainable, initializer, etc..).
- Returns:
- any: A Tensor Variable/Placeholder.
-
-
class
rlgraph.spaces.int_box.
IntBox
(low=None, high=None, shape=None, dtype='int32', **kwargs)[source]¶ Bases:
rlgraph.spaces.box_space.BoxSpace
A box in Z^n (only integers; each coordinate is bounded) e.g. an image (w x h x RGB) where each color channel pixel can be between 0 and 255.
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
flat_dim_with_categories
¶ If we were to flatten this Space and also consider each single possible int value (assuming global bounds) as one category, what would the dimension have to be to represent this Space.
-
get_shape
(with_batch_rank=False, with_time_rank=False, **kwargs)[source]¶ - Keyword Args:
- with_category_rank (bool): Whether to include a category rank for this IntBox (if all dims have equal
- lower/upper bounds).
-
sample
(size=None, fill_value=None)[source]¶ Uniformly randomly samples an element from this space. This is for testing purposes, e.g. to simulate a random environment.
- Args:
- size (Optional[int]): The number of samples or batch size to sample.
- If size is > 1: Returns a batch of size samples with the 0th rank being the batch rank (even if self.has_batch_rank is False). If size is None or (1 and self.has_batch_rank is False): Returns a single sample w/o batch rank. If size is 1 and self.has_batch_rank is True: Returns a single sample w/ the batch rank.
- fill_value (Optional[any]): The number or initializer specifier to fill the sample. Can be used to create
- a (non-random) sample with a certain fill value in all elements. TODO: support initializer spec-strings like ‘normal’, ‘truncated_normal’, etc..
- Returns:
- any: The sampled element(s).
-
-
class
rlgraph.spaces.float_box.
FloatBox
(low=None, high=None, shape=None, dtype='float32', **kwargs)[source]¶ Bases:
rlgraph.spaces.box_space.BoxSpace
-
sample
(size=None, fill_value=None)[source]¶ Uniformly randomly samples an element from this space. This is for testing purposes, e.g. to simulate a random environment.
- Args:
- size (Optional[int]): The number of samples or batch size to sample.
- If size is > 1: Returns a batch of size samples with the 0th rank being the batch rank (even if self.has_batch_rank is False). If size is None or (1 and self.has_batch_rank is False): Returns a single sample w/o batch rank. If size is 1 and self.has_batch_rank is True: Returns a single sample w/ the batch rank.
- fill_value (Optional[any]): The number or initializer specifier to fill the sample. Can be used to create
- a (non-random) sample with a certain fill value in all elements. TODO: support initializer spec-strings like ‘normal’, ‘truncated_normal’, etc..
- Returns:
- any: The sampled element(s).
-
-
class
rlgraph.spaces.bool_box.
BoolBox
(shape=None, **kwargs)[source]¶ Bases:
rlgraph.spaces.box_space.BoxSpace
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
sample
(size=None, fill_value=None)[source]¶ Uniformly randomly samples an element from this space. This is for testing purposes, e.g. to simulate a random environment.
- Args:
- size (Optional[int]): The number of samples or batch size to sample.
- If size is > 1: Returns a batch of size samples with the 0th rank being the batch rank (even if self.has_batch_rank is False). If size is None or (1 and self.has_batch_rank is False): Returns a single sample w/o batch rank. If size is 1 and self.has_batch_rank is True: Returns a single sample w/ the batch rank.
- fill_value (Optional[any]): The number or initializer specifier to fill the sample. Can be used to create
- a (non-random) sample with a certain fill value in all elements. TODO: support initializer spec-strings like ‘normal’, ‘truncated_normal’, etc..
- Returns:
- any: The sampled element(s).
-
-
class
rlgraph.spaces.text_box.
TextBox
(shape=(), **kwargs)[source]¶ Bases:
rlgraph.spaces.box_space.BoxSpace
A text box in TXT^n where the shape means the number of text chunks in each dimension.
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
sample
(size=None, fill_value=None)[source]¶ Uniformly randomly samples an element from this space. This is for testing purposes, e.g. to simulate a random environment.
- Args:
- size (Optional[int]): The number of samples or batch size to sample.
- If size is > 1: Returns a batch of size samples with the 0th rank being the batch rank (even if self.has_batch_rank is False). If size is None or (1 and self.has_batch_rank is False): Returns a single sample w/o batch rank. If size is 1 and self.has_batch_rank is True: Returns a single sample w/ the batch rank.
- fill_value (Optional[any]): The number or initializer specifier to fill the sample. Can be used to create
- a (non-random) sample with a certain fill value in all elements. TODO: support initializer spec-strings like ‘normal’, ‘truncated_normal’, etc..
- Returns:
- any: The sampled element(s).
-
2.3. Container Spaces¶
-
class
rlgraph.spaces.containers.
ContainerSpace
(add_batch_rank=False, add_time_rank=False, time_major=False)[source]¶ Bases:
rlgraph.spaces.space.Space
A simple placeholder class for Spaces that contain other Spaces.
-
class
rlgraph.spaces.containers.
Dict
(spec=None, **kwargs)[source]¶ Bases:
rlgraph.spaces.containers.ContainerSpace
,dict
A Dict space (an ordered and keyed combination of n other spaces). Supports nesting of other Dict/Tuple spaces (or any other Space types) inside itself.
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
dtype
¶
-
flat_dim
¶ Returns: int: The length of a flattened vector derived from this Space.
-
force_batch
(samples)[source]¶ Makes sure that samples is always returned with a batch rank no matter whether it already has one or not (in which case this method returns a batch of 1) or whether this Space has a batch rank or not.
- Args:
- samples (any): The samples to be batched. If already batched, return as-is.
- Returns:
- any: The batched sample.
-
get_shape
(with_batch_rank=False, with_time_rank=False, time_major=None, with_category_rank=False)[source]¶ Returns the shape of this Space as a tuple with certain additional ranks at the front (batch) or the back (e.g. categories).
- Args:
- with_batch_rank (Union[bool,int]): Whether to include a possible batch-rank as None at 0th (or 1st)
- position. If with_batch_rank is an int (e.g. -1), the possible batch-rank is returned as that number (instead of None) at the 0th (or 1st if time_major is True) position. Default: False.
- with_time_rank (Union[bool,int]): Whether to include a possible time-rank as None at 1st (or 0th)
- position. If with_time_rank is an int, the possible time-rank is returned as that number (instead of None) at the 1st (or 0th if time_major is True) position. Default: False.
time_major (bool): Overwrites self.time_major if not None. Default: None (use self.time_major).
- Returns:
- tuple: The shape of this Space as a tuple.
-
get_variable
(name, is_input_feed=False, add_batch_rank=None, add_time_rank=None, time_major=None, **kwargs)[source]¶ Returns a backend-specific variable/placeholder that matches the space’s shape.
- Args:
name (str): The name for the variable.
- is_input_feed (bool): Whether the returned object should be an input placeholder,
- instead of a full variable.
- add_batch_rank (Optional[bool,int]): If True, will add a 0th (or 1st) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_batch_rank. Default: None.
- add_time_rank (Optional[bool,int]): If True, will add a 1st (or 0th) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_time_rank. Default: None.
- time_major (bool): Only relevant if both add_batch_rank and add_time_rank are True.
- Will make the time-rank the 0th rank and the batch-rank the 1st rank. Otherwise, batch-rank will be 0th and time-rank will be 1st. Default: False.
is_python (bool): Whether to create a python-based variable (list) or a backend-specific one.
- local (bool): Whether the variable must not be shared across the network.
- Default: False.
- Keyword Args:
- To be passed on to backend-specific methods (e.g. trainable, initializer, etc..).
- Returns:
- any: A Tensor Variable/Placeholder.
-
rank
¶ Returns: int: The rank of the Space not including batch- or time-ranks (e.g. 3 for a space with shape=(10, 7, 5)).
-
sample
(size=None, horizontal=False)[source]¶ Child classes must overwrite this one again with support for the horizontal parameter.
- Args:
- horizontal (bool): False: Within this container, sample each child-space size times.
- True: Produce size single containers in an np.array of len size.
-
shape
¶ Returns: tuple: The shape of this Space as a tuple. Without batch or time ranks.
-
-
class
rlgraph.spaces.containers.
Tuple
(*components, **kwargs)[source]¶ Bases:
rlgraph.spaces.containers.ContainerSpace
,tuple
A Tuple space (an ordered sequence of n other spaces). Supports nesting of other container (Dict/Tuple) spaces inside itself.
-
contains
(sample)[source]¶ Checks whether this space contains the given sample. This is more for testing purposes.
- Args:
- sample: The element to check.
- Returns:
- bool: Whether sample is a valid member of this space.
-
dtype
¶
-
flat_dim
¶ Returns: int: The length of a flattened vector derived from this Space.
-
force_batch
(samples)[source]¶ Makes sure that samples is always returned with a batch rank no matter whether it already has one or not (in which case this method returns a batch of 1) or whether this Space has a batch rank or not.
- Args:
- samples (any): The samples to be batched. If already batched, return as-is.
- Returns:
- any: The batched sample.
-
get_shape
(with_batch_rank=False, with_time_rank=False, time_major=None, with_category_rank=False)[source]¶ Returns the shape of this Space as a tuple with certain additional ranks at the front (batch) or the back (e.g. categories).
- Args:
- with_batch_rank (Union[bool,int]): Whether to include a possible batch-rank as None at 0th (or 1st)
- position. If with_batch_rank is an int (e.g. -1), the possible batch-rank is returned as that number (instead of None) at the 0th (or 1st if time_major is True) position. Default: False.
- with_time_rank (Union[bool,int]): Whether to include a possible time-rank as None at 1st (or 0th)
- position. If with_time_rank is an int, the possible time-rank is returned as that number (instead of None) at the 1st (or 0th if time_major is True) position. Default: False.
time_major (bool): Overwrites self.time_major if not None. Default: None (use self.time_major).
- Returns:
- tuple: The shape of this Space as a tuple.
-
get_variable
(name, is_input_feed=False, add_batch_rank=None, add_time_rank=None, time_major=None, **kwargs)[source]¶ Returns a backend-specific variable/placeholder that matches the space’s shape.
- Args:
name (str): The name for the variable.
- is_input_feed (bool): Whether the returned object should be an input placeholder,
- instead of a full variable.
- add_batch_rank (Optional[bool,int]): If True, will add a 0th (or 1st) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_batch_rank. Default: None.
- add_time_rank (Optional[bool,int]): If True, will add a 1st (or 0th) rank (None) to
- the created variable. If it is an int, will add that int (-1 means None). If None, will use the Space’s default value: self.has_time_rank. Default: None.
- time_major (bool): Only relevant if both add_batch_rank and add_time_rank are True.
- Will make the time-rank the 0th rank and the batch-rank the 1st rank. Otherwise, batch-rank will be 0th and time-rank will be 1st. Default: False.
is_python (bool): Whether to create a python-based variable (list) or a backend-specific one.
- local (bool): Whether the variable must not be shared across the network.
- Default: False.
- Keyword Args:
- To be passed on to backend-specific methods (e.g. trainable, initializer, etc..).
- Returns:
- any: A Tensor Variable/Placeholder.
-
rank
¶ Returns: int: The rank of the Space not including batch- or time-ranks (e.g. 3 for a space with shape=(10, 7, 5)).
-
sample
(size=None, horizontal=False)[source]¶ Child classes must overwrite this one again with support for the horizontal parameter.
- Args:
- horizontal (bool): False: Within this container, sample each child-space size times.
- True: Produce size single containers in an np.array of len size.
-
shape
¶ Returns: tuple: The shape of this Space as a tuple. Without batch or time ranks.
-
2.4. Space Utilities¶
-
rlgraph.spaces.space_utils.
check_space_equivalence
(space1, space2)[source]¶ Compares the two input Spaces for equivalence and returns the more generic Space of the two. The more generic Space is the one that has the properties has_batch_rank and/or has _time_rank set (instead of hard values in these ranks). E.g.: FloatBox((64,)) is equivalent with FloatBox((), +batch-rank). The latter will be returned.
NOTE: FloatBox((2,)) and FloatBox((3,)) are NOT equivalent.
- Args:
- space1 (Space): The 1st Space to compare. space2 (Space): The 2nd Space to compare.
- Returns:
- Union[Space,False]: False is the two spaces are not equivalent. The more generic Space of the two if they are
- equivalent.
-
rlgraph.spaces.space_utils.
get_list_registry
(from_space, capacity=None, initializer=0, flatten=True, add_batch_rank=False)[source]¶ Creates a list storage for a space by providing an ordered dict mapping space names to empty lists.
- Args:
from_space: Space to create registry from. capacity (Optional[int]): Optional capacity to initalize list. initializer (Optional(any)): Optional initializer for list if capacity is not None. flatten (bool): Whether to produce a FlattenedDataOp with auto-keys.
- add_batch_rank (Optional[bool,int]): If from_space is given and is True, will add a 0th rank (None) to
- the created variable. If it is an int, will add that int instead of None. Default: False.
- Returns:
- dict: Container dict mapping spaces to empty lists.
-
rlgraph.spaces.space_utils.
get_space_from_op
(op)[source]¶ Tries to re-create a Space object given some DataOp. This is useful for shape inference when passing a Socket’s ops through a GraphFunction and auto-inferring the resulting shape/Space.
- Args:
- op (DataOp): The op to create a corresponding Space for.
- Returns:
- Space: The inferred Space object.
-
rlgraph.spaces.space_utils.
sanity_check_space
(space, allowed_types=None, non_allowed_types=None, must_have_batch_rank=None, must_have_time_rank=None, must_have_batch_or_time_rank=False, must_have_categories=None, num_categories=None, rank=None)[source]¶ Sanity checks a given Space for certain criteria and raises exceptions if they are not met.
- Args:
space (Space): The Space object to check. allowed_types (Optional[List[type]]): A list of types that this Space must be an instance of. non_allowed_types (Optional[List[type]]): A list of type that this Space must not be an instance of.
- must_have_batch_rank (Optional[bool]): Whether the Space must (True) or must not (False) have the
- has_batch_rank property set to True. None, if it doesn’t matter.
- must_have_time_rank (Optional[bool]): Whether the Space must (True) or must not (False) have the
- has_time_rank property set to True. None, if it doesn’t matter.
- must_have_batch_or_time_rank (Optional[bool]): Whether the Space must (True) or must not (False) have either
- the has_batch_rank or the has_time_rank property set to True.
- must_have_categories (Optional[bool]): For IntBoxes, whether the Space must (True) or must not (False) have
- global bounds with num_categories > 0. None, if it doesn’t matter.
- num_categories (Optional[int,tuple]): An int or a tuple (min,max) range within which the Space’s
- num_categories rank must lie. Only valid for IntBoxes. None if it doesn’t matter.
- rank (Optional[int,tuple]): An int or a tuple (min,max) range within which the Space’s rank must lie.
- None if it doesn’t matter.
- Raises:
- RLGraphError: Various RLGraphErrors, if any of the conditions is not met.