pg.hyper.HyperValue

Accessible via pg.hyper.HyperValue.

class HyperValue[source]

Bases: pg.symbolic.NonDeterministic

Base class for a hyper value.

Hyper value represents a space of objects, which is essential for programmatically generating objects. It can encode a concrete object into a DNA, or decode a DNA into a concrete object.

DNA is a nestable numeric interface we use to generate object (see geno.py). Each position in the DNA represents either the index of a choice, or a value itself is numeric. There could be multiple choices standing side-by-side, representing knobs on different parts of an object, or choices being chained, forming conditional choice spaces, which can be described by a tree structure.

Hyper values form a tree as the following:

digraph relationship {
  template [label="ObjectTemplate" href="object_template.html"];
  primitive [label="HyperPrimitive" href="hyper_primitive.html"];
  choices [label="OneOf/ManyOf" href="choices.html"];
  float [label="Float" href="float_class.html"];
  custom [label="CustomHyper" href="custom_hyper.html"];
  template -> primitive [label="elements (1:*)"];
  primitive -> choices [dir="back" arrowtail="empty" style="dashed"];
  primitive -> float [dir="back" arrowtail="empty" style="dashed"];
  primitive -> custom [dir="back" arrowtail="empty" style="dashed"];
  choices -> template [label="candidates (1:*)"];
}

Methods:

decode(dna)

Decode a value from a DNA.

dna_spec([location])

Get DNA spec of DNA that is decodable/encodable by this hyper value.

encode(value)

Encode a value into a DNA.

set_dna(dna)

Use this DNA to generate value.

Attributes:

dna

Returns the DNA that is being used by this hyper value.

decode(dna)[source]

Decode a value from a DNA.

Return type:

Any

property dna: DNA | None[source]

Returns the DNA that is being used by this hyper value.

abstract dna_spec(location=None)[source]

Get DNA spec of DNA that is decodable/encodable by this hyper value.

Return type:

pg.DNASpec

abstract encode(value)[source]

Encode a value into a DNA.

Return type:

pg.DNA

Parameters:

value – A value that conforms to the hyper value definition.

Returns:

DNA for the value.

set_dna(dna)[source]

Use this DNA to generate value.

NOTE(daiyip): self._dna is only used in __call__. Thus ‘set_dna’ can be called multiple times to generate different values.

Return type:

None

Parameters:

dna – DNA to use to decode the value.