How to sample from unnormalized distribution with bounded support?

I would like to sample from a distribution using NUTS, the issue is that the distribution is bounded to be strictly positive.

For instance, for a wrapped normal distribution:

import torch.nn.functional as F
from pyro.distributions.transforms import SoftplusTransform
from pyro.infer import MCMC, NUTS

def exp_nll(x):
    return x["u"]**2

nuts = NUTS(
    potential_fn=exp_nll,
    transforms={"u": SoftplusTransform()}
)
mcmc = MCMC(
    nuts,
    num_samples=1000,
    warmup_steps=100,
    initial_params={
        "u": torch.tensor(1.)
    }
)
mcmc.run()
print(F.softplus(mcmc.get_samples()["u"]))

And this seems to work, but it does generate some NaNs sometimes, and it doesn’t generalize at all to the exponential distribution or to my distribution where I get only NaN. Is this the right approach?

Thanks in advance.

This seems to be a reasonable approach. Maybe you need SoftplusTransform().inv instead?