Implementation:Google deepmind Dm control Variation Deterministic
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Domain_Randomization |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Deterministic (non-random) variation classes that wrap fixed values, cyclic sequences, or identity transforms into the Variation interface for use in the dm_control Composer framework.
Description
The deterministic module provides three Variation subclasses that produce values without randomness. Constant wraps a single fixed value and always returns it regardless of the initial_value, current_value, or random_state arguments. This is primarily useful in tests, where it allows verification that variations are invoked correctly without introducing randomness.
Sequence iterates through a provided list of values in order, cycling back to the beginning when the list is exhausted. Each element in the sequence may itself be a Variation object, which is recursively evaluated via variation_values.evaluate. This enables predictable orderings of values, such as placing multiple objects at specific pre-defined locations.
Identity simply returns the current_value unchanged, serving as a pass-through or no-op variation. This is useful when a variation slot must be filled but no actual transformation is desired.
Usage
Use Constant primarily in unit tests to verify variation invocation without randomness. Use Sequence when you need a fixed, repeating sequence of values for props or attributes. Use Identity as a placeholder when a variation is required by the API but no modification is needed.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/composer/variation/deterministic.py
- Lines: 1-71
Signature
class Constant(base.Variation):
def __init__(self, value):
...
class Sequence(base.Variation):
def __init__(self, values):
...
class Identity(base.Variation):
def __call__(self, initial_value=None, current_value=None, random_state=None):
...
Import
from dm_control.composer.variation import deterministic
from dm_control.composer.variation.deterministic import Constant, Sequence, Identity
I/O Contract
Inputs (Constant)
| Name | Type | Required | Description |
|---|---|---|---|
| value | any | Yes | The fixed value to always return |
Inputs (Sequence)
| Name | Type | Required | Description |
|---|---|---|---|
| values | list | Yes | List of values (or Variation objects) to cycle through |
Inputs (Identity)
| Name | Type | Required | Description |
|---|---|---|---|
| current_value | any | No | The current value to pass through unchanged |
Outputs
| Name | Type | Description |
|---|---|---|
| Constant return | same as constructor value |
The fixed value provided at construction |
| Sequence return | same as element type | The next value in the cyclic sequence, recursively evaluated |
| Identity return | same as current_value |
The current value, unchanged |
Usage Examples
from dm_control.composer.variation import deterministic
# Constant variation for testing
const = deterministic.Constant(42)
assert const() == 42
assert const(initial_value=0, current_value=10, random_state=None) == 42
# Sequence variation cycles through values
seq = deterministic.Sequence([1.0, 2.0, 3.0])
assert seq() == 1.0
assert seq() == 2.0
assert seq() == 3.0
assert seq() == 1.0 # Cycles back to the beginning
# Identity variation returns the current value
identity = deterministic.Identity()
assert identity(current_value=99) == 99
# Sequence with nested variations
from dm_control.composer.variation import distributions
import numpy as np
rng = np.random.RandomState(42)
seq_with_variations = deterministic.Sequence([
deterministic.Constant(1.0),
distributions.Uniform(0.0, 1.0),
])
val1 = seq_with_variations(random_state=rng) # Returns 1.0 (constant)
val2 = seq_with_variations(random_state=rng) # Returns a uniform sample