{"record":{"id":"a04b46bbe1d107e5","repo":"Genesis-Embodied-AI/genesis-world","slug":"direction-must-have-shape-3","errorCode":null,"errorMessage":"direction must have shape (3,)","messagePattern":"direction must have shape \\(3,\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"genesis/engine/force_fields.py","lineNumber":66,"sourceCode":"\nclass Constant(ForceField):\n    \"\"\"\n    Constant force field with a static acceleration everywhere.\n\n    Parameters:\n    -----------\n    direction: array_like, shape=(3,)\n        The direction of the force (acceleration). Will be normalized.\n    strength: float\n        The strength of the force (acceleration).\n    \"\"\"\n\n    def __init__(self, direction=(1, 0, 0), strength=1.0):\n        super().__init__()\n\n        direction = np.array(direction)\n        if direction.shape != (3,):\n            raise ValueError(\"direction must have shape (3,)\")\n\n        self._direction = direction / np.linalg.norm(direction)\n        self._strength = strength\n        self._acc_qd = qd.Vector(self._direction * self._strength, dt=gs.qd_float)\n\n    @qd.func\n    def _get_acc(self, pos, vel, t, i):\n        return self._acc_qd\n\n    @property\n    def direction(self):\n        return self._direction\n\n    @property\n    def strength(self):\n        return self._strength\n\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/Genesis-Embodied-AI/genesis-world/blob/56e4aa5d82bdb83f2e532e4cc364cb69527acb06/genesis/engine/force_fields.py#L48-L84","documentation":"A directional ForceField (e.g. ConstantForceField) validates its direction argument at construction: after np.asarray, it must have shape exactly (3,). Any other shape (wrong length, nested list, scalar, or a (3,1) array) raises this ValueError before the field is created.","triggerScenarios":"Passing direction=[1,0] (2 elements), direction=[1,0,0,0] (4 elements), a scalar, or a (3,1)/(1,3) nested array to ConstantForceField(direction=...).","commonSituations":"Configuring wind-like force fields in a scene and passing a 2D vector from a config file, reusing a column-vector numpy array shaped (3,1), or passing a batch of directions where only one is expected.","solutions":["Pass a flat 3-element iterable, e.g. direction=[0,0,-1] or np.array([0,0,-1])","If the value comes from another array, flatten to shape (3,) first: np.ravel(arr) or arr.reshape(3)","Validate direction.shape == (3,) in your scene-construction code before creating the field"],"exampleFix":"# before\nfield = ConstantForceField(direction=[[0], [0], [-1]], strength=1.0)\n# after\nfield = ConstantForceField(direction=[0, 0, -1], strength=1.0)","handlingStrategy":"validation","validationCode":"direction = np.asarray(direction).ravel()\nassert direction.shape == (3,), 'direction must be a flat 3-vector'\nfield = ConstantForceField(direction=direction, strength=1.0)\n","typeGuard":"def is_vec3(x) -> bool:\n    return np.asarray(x).shape == (3,)\n","tryCatchPattern":"try:\n    field = ConstantForceField(direction=direction, strength=1.0)\nexcept ValueError as e:\n    raise ValueError(f'bad direction {direction!r}: {e}') from e\n","preventionTips":["Normalize all 3-vector inputs to shape (3,) at your config boundary","Avoid storing directions as (3,1) column vectors"],"tags":["genesis","force-field","validation","shape-mismatch"],"backgroundTag":"argument-shape-validation","analyzedSha":"56e4aa5d82bdb83f2e532e4cc364cb69527acb06","analyzedAt":"2026-08-28T15:15:07.922Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}