gym_gz.randomizers.model#
gym_gz.randomizers.model.sdf#
- class gym_gz.randomizers.model.sdf.Distribution(value)#
Bases:
Enum
An enumeration.
- Gaussian = 2#
- Uniform = 1#
- class gym_gz.randomizers.model.sdf.GaussianParams(variance, mean)#
Bases:
NamedTuple
-
mean:
float
# Alias for field number 1
-
variance:
float
# Alias for field number 0
-
mean:
- class gym_gz.randomizers.model.sdf.Method(value)#
Bases:
Enum
An enumeration.
- Absolute = 1#
- Additive = 2#
- Coefficient = 3#
- class gym_gz.randomizers.model.sdf.RandomizationData(xpath, distribution, parameters, method, ignore_zeros, force_positive, element)#
Bases:
NamedTuple
-
distribution:
str
# Alias for field number 1
-
element:
Element
# Alias for field number 6
-
force_positive:
bool
# Alias for field number 5
-
ignore_zeros:
bool
# Alias for field number 4
-
parameters:
Union
[UniformParams
,GaussianParams
]# Alias for field number 2
-
xpath:
str
# Alias for field number 0
-
distribution:
- class gym_gz.randomizers.model.sdf.RandomizationDataBuilder(randomizer)#
Bases:
object
Builder class of a
RandomizationData
object.- Parameters:
randomizer (
SDFRandomizer
) – TheSDFRandomizer
object to which the created randomization will be inserted.
- add()#
Close the chaining of methods and return to the SDF randomizer the configuration.
- Raises:
RuntimeError – If the XPath pattern does not find any match in the SDF.
- Return type:
None
- at_xpath(xpath)#
Set the XPath pattern associated to the randomization.
- Parameters:
xpath (
str
) – The XPath pattern.- Return type:
- Returns:
The randomization builder to allow chaining methods.
- force_positive(force_positive=True)#
Force the randomized value to be greater than zero.
This option is helpful to enforce that values e.g. the mass will stay positive regardless of the applied distribution parameters.
- Parameters:
force_positive (
bool
) – True to force positive parameters, false otherwise.- Return type:
- Returns:
The randomization builder to allow chaining methods.
- ignore_zeros(ignore_zeros)#
Ignore the randomization of values that are zero.
If the value to randomize has a default value of 0 in the SDF, when this method is chained the randomization is skipped. In the case of a multi-match XPath pattern, the values that are not zero are not skipped.
- Parameters:
ignore_zeros (
bool
) – True if zeros should be ignored, false otherwise.- Return type:
- Returns:
The randomization builder to allow chaining methods.
- method(method)#
Set the randomization method.
- Parameters:
method (
Method
) – The desired randomization method.- Return type:
- Returns:
The randomization builder to allow chaining methods.
- sampled_from(distribution, parameters)#
Set the distribution associated to the randomization.
- Parameters:
distribution (
Distribution
) – The desired distribution.parameters (
Union
[UniformParams
,GaussianParams
]) – The namedtuple with the parameters of the distribution.
- Return type:
- Returns:
The randomization builder to allow chaining methods.
- class gym_gz.randomizers.model.sdf.SDFRandomizer(sdf_model)#
Bases:
object
Randomized SDF files generator.
- Parameters:
sdf_model (
str
) – The absolute path to the SDF file.- Raises:
ValueError – If the SDF file does not exist.
- clean()#
Clean the SDF randomizer.
- Return type:
None
- find_xpath(xpath)#
Find the elements that match an XPath pattern.
This method could be helpful to test the matches of a XPath pattern before using it in
at_xpath()
.- Parameters:
xpath (
str
) – The XPath pattern.- Return type:
List
[Element
]- Returns:
A list of elements matching the XPath pattern.
- get_active_randomizations()#
Return the active randomizations.
This method could be helpful also in the case of multi-match XPath patterns to validate that the inserted randomizations have been processed correctly.
- Return type:
List
[RandomizationData
]- Returns:
The list of the active randomizations.
- insert(randomization_data)#
Insert a randomization.
- Parameters:
randomization_data – A new randomization.
- Return type:
None
- new_randomization()#
Start the chaining to build a new randomization.
- Return type:
- Returns:
A randomization builder.
- process_data()#
Process all the inserted randomizations.
- Raises:
RuntimeError – If the XPath of a randomization has no matches.
- Return type:
None
- sample(pretty_print=False)#
Sample a randomized SDF string.
- Parameters:
pretty_print – True to pretty print the output.
- Raises:
ValueError – If the distribution of a randomization is not recognized.
ValueError – If the method of a randomization is not recognized.
- Return type:
str
- Returns:
The randomized model as SDF string.
- seed(seed)#
Seed the SDF randomizer.
- Parameters:
seed (
int
) – The seed number.- Return type:
None