code: def test_sample_is_valid(num_leaves):
      pyro.set_rng_seed(num_leaves)
  
      # Check with disperse leaves.
      leaf_times = torch.randn(num_leaves)
      coal_times = _sample_coalescent_times(leaf_times)
      assert CoalescentTimesConstraint(leaf_times).check(coal_times)
      assert len(set(coal_times.tolist())) == len(coal_times)
  
      # Check with simultaneous leaves.
      leaf_times = torch.zeros(num_leaves)
      coal_times = _sample_coalescent_times(leaf_times)
      assert CoalescentTimesConstraint(leaf_times).check(coal_times)
      assert len(set(coal_times.tolist())) == len(coal_times)
  
imports: import io
  import re
  import pytest
  import torch
  import pyro
  from pyro.distributions import CoalescentTimes, CoalescentTimesWithRate
  from pyro.distributions.coalescent import CoalescentRateLikelihood, CoalescentTimesConstraint, _sample_coalescent_times, bio_phylo_to_times
  from pyro.distributions.util import broadcast_shape
  from tests.common import assert_close
label_desc: Use image node_id 1 for calling a global function with example usage: test_sample_is_valid(num_leaves) without return types