Genesis-Embodied-AI/genesis-world · error · ValueError

position must have shape (3,)

Error message

position must have shape (3,)

What it means

A hybrid position/flow force field validates its position argument: np.asarray(position) must have shape exactly (3,). Any other shape raises this ValueError in __init__.

Source

Thrown at genesis/engine/force_fields.py:168

    Parameters:
    -----------
    strength: float
        The strength of the wind.
    position: array_like, shape=(3,)
        The position of the point.
    flow: float
        The flow of the force field.
    falloff_pow: float
        The power of the falloff.
    """

    def __init__(self, strength=1.0, position=(0, 0, 0), falloff_pow=0.0, flow=1.0):
        super().__init__()

        position = np.array(position)
        if position.shape != (3,):
            raise ValueError("position must have shape (3,)")

        self._strength = strength
        self._position = position
        self._falloff_pow = falloff_pow
        self._flow = flow

        self._position_qd = qd.Vector(self._position, dt=gs.qd_float)

    @qd.func
    def _get_acc(self, pos, vel, t, i):
        relative_pos = pos - self._position_qd
        radius = relative_pos.norm(gs.EPS)
        direction = relative_pos / radius
        falloff = 1 / (radius + 1.0) ** self._falloff_pow
        acc = self._strength * direction

        # flow
        acc += (acc - vel) * self._flow

View on GitHub (pinned to 56e4aa5d82)

Solutions

  1. Pass a flat 3-vector: position=[0, 0, 2]
  2. Flatten arrays: np.ravel(pos) before passing
  3. Validate config values with a shape check before scene construction

Example fix

# before
field = HybridForceField(strength=1.0, position=[0, 0])
# after
field = HybridForceField(strength=1.0, position=[0, 0, 0])
Defensive patterns

Strategy: validation

Validate before calling

position = np.ravel(position)
assert position.shape == (3,), 'position must be a flat 3-vector'
field = HybridForceField(strength=1.0, position=position)

Type guard

def is_vec3(x) -> bool:
    return np.asarray(x).shape == (3,)

Try / catch

try:
    field = HybridForceField(position=position, strength=1.0)
except ValueError as e:
    raise ValueError(f'invalid position {position!r}: {e}') from e

Prevention

When it happens

Trigger: Passing position=[0,0] or a nested/scalar value to HybridForceField(position=...); supplying a (3,1) array or a batch of positions where one is expected.

Common situations: Defining wind-with-falloff fields positioned at a target location and passing a 2D coordinate, or reusing an array from a geometry pipeline with an extra axis.

Related errors


AI-assisted analysis of Genesis-Embodied-AI/genesis-world@56e4aa5d82 (2026-08-28). Data as JSON: /api/errors/b1a5416892ee2dd4. Report an issue: GitHub.