Error while using `rep.distribution.choice`

Getting the following error while using rep.distribution.choice:

[Error] [omni.graph.core.plugin] /Replicator/SDGPipeline/OgnSampleChoice: Assertion raised in compute - AttributeData '__resolved_outputs:samples' of type 'double3[]' required array of elements of length 3, got 1d array of size 3
  File "/home/atai/.local/share/ov/pkg/deps/28c70d9b2f0e7eb6e8d60682fea71057/extscache/omni.replicator.core-1.7.7+104.2.lx64.r.cp37/omni/replicator/core/ogn/python/_impl/nodes/OgnSampleChoice.py", line 115, in compute
    db.outputs.samples = samples
  File "/home/atai/.local/share/ov/pkg/deps/28c70d9b2f0e7eb6e8d60682fea71057/extscache/omni.replicator.core-1.7.7+104.2.lx64.r.cp37/omni/replicator/core/ogn/OgnSampleChoiceDatabase.py", line 168, in __setattr__
    super().__setattr__(item, new_value)
  File "/var/tmp/packman/chk/kit-sdk/104.2+release.295.529af2e4.tc.linux-x86_64.release/exts/omni.graph/omni/graph/core/_impl/database.py", line 657, in __setattr__
    super().__setattr__(item, new_value)
  File "/home/atai/.local/share/ov/pkg/deps/28c70d9b2f0e7eb6e8d60682fea71057/extscache/omni.replicator.core-1.7.7+104.2.lx64.r.cp37/omni/replicator/core/ogn/OgnSampleChoiceDatabase.py", line 143, in samples
    self.samples.value = value_to_set
  File "/var/tmp/packman/chk/kit-sdk/104.2+release.295.529af2e4.tc.linux-x86_64.release/exts/omni.graph/omni/graph/core/_impl/utils.py", line 385, in wrapper_non_const
    return func(self, *args, **kwargs)
  File "/var/tmp/packman/chk/kit-sdk/104.2+release.295.529af2e4.tc.linux-x86_64.release/exts/omni.graph/omni/graph/core/_impl/runtime.py", line 126, in value
    self.helper.set(new_value, on_gpu=self._on_gpu)
  File "/var/tmp/packman/chk/kit-sdk/104.2+release.295.529af2e4.tc.linux-x86_64.release/exts/omni.graph/omni/graph/core/_impl/attribute_values.py", line 115, in set
    self._data.set(new_value, on_gpu=on_gpu)

You can reproduce the error by running following code:

import omni.replicator.core as rep

with rep.new_layer():

    torus = rep.create.torus(semantics=[("class", "torus")], position=(0, -200 , 100))
    sphere = rep.create.sphere(semantics=[("class", "sphere")], position=(0, 100, 100))
    cube = rep.create.cube(semantics=[("class", "cube")], position=(100, -200, 100))
    
    with rep.trigger.on_frame(num_frames=10):
        prims = rep.get.prims(semantics=[("class", "torus"), ("class", "sphere"), ("class", "cube")])
        with prims:
            rep.modify.pose(
                position = rep.distribution.uniform((-200,-200,-200), (200, 200, 200)),
                rotation=rep.distribution.uniform((-90,-180, 0), (-90, 180, 0)),
                scale = rep.distribution.choice(choices=[0.8, 1, 1.2, 1.5]), # Error line
            )

    rep.orchestrator.run()

Hi @ShyamPatel. Welcome to the forums! This is more of a Replicator-specific question so I’ve moved it over to Synthetic Data Generation forum.

Hi @ShyamPatel we have a bug tracked for this. The issue is that a uniform float can’t be passed, it need to be a vector. Try something like this:

import omni.replicator.core as rep

with rep.new_layer():

    torus = rep.create.torus(semantics=[("class", "torus")], position=(0, -200 , 100))
    sphere = rep.create.sphere(semantics=[("class", "sphere")], position=(0, 100, 100))
    cube = rep.create.cube(semantics=[("class", "cube")], position=(100, -200, 100))
    
    with rep.trigger.on_frame(num_frames=10):
        prims = rep.get.prims(semantics=[("class", "torus"), ("class", "sphere"), ("class", "cube")])
        with prims:
            rep.modify.pose(
                position = rep.distribution.uniform((-200,-200,-200), (200, 200, 200)),
                rotation=rep.distribution.uniform((-90,-180, 0), (-90, 180, 0)),
                scale = rep.distribution.choice(choices=[(0.8,0.8,0.8), (1.0,1.0,1.0)]), # Corrected Error line
            )

    rep.orchestrator.run()

@pcallender Thanks for your reply.

I have one more doubt here. So finally rep.distribution.choice() will return output vector with shape of 3, right? But, here I need only single value.

scale takes 3 parameters explicitly (x, y, z).

There are some convenience methods elsewhere that interpret a single value as a uniform scale, but currently in this case the scale parameter expects 3 values.

Using choices=[(0.8,0.8,0.8), (1.0,1.0,1.0)] is currently the correct way to select a choice of uniform scale

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.