Skip to content

Setting bounding box of product domain leads to "RuntimeError: Boolean value of Tensor with more than one value is ambiguous" #50

@CAarset

Description

@CAarset

First of all, thank you sincerely for this beautiful and easy-to-use physics-based neural network code; the ease of use for moving domains is particularly noteworthy.

I've ran into a minor yet breaking error when seeking to manually specify bounding boxes of product domains.

  • Release: 1.0.6rc2
  • Issue description: If you attempt to call the .bounding_box() of a ProductDomain after you've manually set the bounding box via .set_bounding_box, you will consistently throw the error

RuntimeError: Boolean value of Tensor with more than one value is ambiguous

This appears to be because of the line

if self.bounds: return self.bounds

in .bounding_box. If self.bounds was set by .set_bounding_box, this ends up evaluating the truth value of a torch tensor (self.bounds), which immediately causes the error. I suspect a suitable workaround would be changing the above code to

if self.bounds is not None: return self.bounds

since self.bounds is already pre-set to None in init.

  • Minimal breaking example:
I = tp.spaces.R1('i')
interval = tp.domains.Interval(I,0,1)
box = interval * interval
print(box.bounding_box()) # Works correctly
box.set_bounding_box(box.bounding_box()) # In principle, a harmless overwrite
print(box.bounding_box()) # But now, throws an error
  • Side note: The warning produced when the code is forced to estimate an unknown bounding box is misleading; it outputs
warnings.warn(
                f"""The bounding box of the ProductDomain dependens of the
                              values of domain_b. Therefor will sample
                              {N_APPROX_VOLUME} in domain_b, to compute a 
                              approixmation. If the bounds a known exactly, set 
                              them with .set_bounds()."""
            )

but the actual name of the method that sets bounds is .set_bounding_box, not .set_bounds. There are also typos in "dependens", "therefore,", "are known" and "an approixmation".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions