sbi/inference/snle/snle_base.py

Killed 51 out of 78 mutants

Timeouts

Mutants that made the test suite take a lot longer so the tests were killed.

Mutant 52

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -249,7 +249,7 @@
         )
 
         epoch, self._val_log_prob = 0, float("-Inf")
-        while epoch <= max_num_epochs and not self._converged(epoch, stop_after_epochs):
+        while epoch <= max_num_epochs or not self._converged(epoch, stop_after_epochs):
 
             # Train for a single epoch.
             self._posterior.net.train()

Mutant 84

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -353,7 +353,7 @@
         )
 
         # Notice opposite sign to pyro potential.
-        return log_likelihood + self.prior.log_prob(theta)
+        return log_likelihood - self.prior.log_prob(theta)
 
     def pyro_potential(self, theta: Dict[str, Tensor]) -> Tensor:
         r"""Return posterior log probability of parameters $p(\theta|x)$.

Survived

Survived mutation testing. These mutants show holes in your test suite.

Mutant 9

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -80,7 +80,7 @@
             self._build_neural_net = utils.likelihood_nn(model=density_estimator)
         else:
             self._build_neural_net = density_estimator
-        self._posterior = None
+        self._posterior = ""
         self._sample_with_mcmc = True
         self._mcmc_method = mcmc_method
 

Mutant 13

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -119,7 +119,7 @@
             Posterior $p(\theta|x_o)$ that can be sampled and evaluated.
         """
 
-        max_num_epochs = 2 ** 31 - 1 if max_num_epochs is None else max_num_epochs
+        max_num_epochs = 3 ** 31 - 1 if max_num_epochs is None else max_num_epochs
 
         num_sims_per_round = self._ensure_list(num_simulations_per_round, num_rounds)
 

Mutant 14

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -119,7 +119,7 @@
             Posterior $p(\theta|x_o)$ that can be sampled and evaluated.
         """
 
-        max_num_epochs = 2 ** 31 - 1 if max_num_epochs is None else max_num_epochs
+        max_num_epochs = 2 * 31 - 1 if max_num_epochs is None else max_num_epochs
 
         num_sims_per_round = self._ensure_list(num_simulations_per_round, num_rounds)
 

Mutant 15

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -119,7 +119,7 @@
             Posterior $p(\theta|x_o)$ that can be sampled and evaluated.
         """
 
-        max_num_epochs = 2 ** 31 - 1 if max_num_epochs is None else max_num_epochs
+        max_num_epochs = 2 ** 32 - 1 if max_num_epochs is None else max_num_epochs
 
         num_sims_per_round = self._ensure_list(num_simulations_per_round, num_rounds)
 

Mutant 16

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -119,7 +119,7 @@
             Posterior $p(\theta|x_o)$ that can be sampled and evaluated.
         """
 
-        max_num_epochs = 2 ** 31 - 1 if max_num_epochs is None else max_num_epochs
+        max_num_epochs = 2 ** 31 + 1 if max_num_epochs is None else max_num_epochs
 
         num_sims_per_round = self._ensure_list(num_simulations_per_round, num_rounds)
 

Mutant 17

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -119,7 +119,7 @@
             Posterior $p(\theta|x_o)$ that can be sampled and evaluated.
         """
 
-        max_num_epochs = 2 ** 31 - 1 if max_num_epochs is None else max_num_epochs
+        max_num_epochs = 2 ** 31 - 2 if max_num_epochs is None else max_num_epochs
 
         num_sims_per_round = self._ensure_list(num_simulations_per_round, num_rounds)
 

Mutant 25

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -135,7 +135,7 @@
                 )
 
             x = self._batched_simulator(theta)
-            x_shape = x_shape_from_simulation(x)
+            x_shape = None
 
             # First round or if retraining from scratch:
             # Call the `self._build_neural_net` with the rounds' thetas and xs as

Mutant 32

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -211,7 +211,7 @@
         """
 
         # Starting index for the training set (1 = discard round-0 samples).
-        start_idx = int(discard_prior_samples and round_ > 0)
+        start_idx = int(discard_prior_samples and round_ >= 0)
         # Get total number of training examples.
         num_examples = sum(len(theta) for theta in self._theta_bank)
 

Mutant 33

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -211,7 +211,7 @@
         """
 
         # Starting index for the training set (1 = discard round-0 samples).
-        start_idx = int(discard_prior_samples and round_ > 0)
+        start_idx = int(discard_prior_samples and round_ > 1)
         # Get total number of training examples.
         num_examples = sum(len(theta) for theta in self._theta_bank)
 

Mutant 34

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -211,7 +211,7 @@
         """
 
         # Starting index for the training set (1 = discard round-0 samples).
-        start_idx = int(discard_prior_samples and round_ > 0)
+        start_idx = int(discard_prior_samples or round_ > 0)
         # Get total number of training examples.
         num_examples = sum(len(theta) for theta in self._theta_bank)
 

Mutant 35

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -211,7 +211,7 @@
         """
 
         # Starting index for the training set (1 = discard round-0 samples).
-        start_idx = int(discard_prior_samples and round_ > 0)
+        start_idx = None
         # Get total number of training examples.
         num_examples = sum(len(theta) for theta in self._theta_bank)
 

Mutant 42

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -218,7 +218,7 @@
         # Select random train and validation splits from (theta, x) pairs.
         permuted_indices = torch.randperm(num_examples)
         num_training_examples = int((1 - validation_fraction) * num_examples)
-        num_validation_examples = num_examples - num_training_examples
+        num_validation_examples = num_examples + num_training_examples
         train_indices, val_indices = (
             permuted_indices[:num_training_examples],
             permuted_indices[num_training_examples:],

Mutant 44

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -233,7 +233,7 @@
         train_loader = data.DataLoader(
             dataset,
             batch_size=min(training_batch_size, num_training_examples),
-            drop_last=True,
+            drop_last=False,
             sampler=SubsetRandomSampler(train_indices),
         )
         val_loader = data.DataLoader(

Mutant 46

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -240,7 +240,7 @@
             dataset,
             batch_size=min(training_batch_size, num_validation_examples),
             shuffle=False,
-            drop_last=False,
+            drop_last=True,
             sampler=SubsetRandomSampler(val_indices),
         )
 

Mutant 50

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -249,7 +249,7 @@
         )
 
         epoch, self._val_log_prob = 0, float("-Inf")
-        while epoch <= max_num_epochs and not self._converged(epoch, stop_after_epochs):
+        while epoch < max_num_epochs and not self._converged(epoch, stop_after_epochs):
 
             # Train for a single epoch.
             self._posterior.net.train()

Mutant 58

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -262,7 +262,7 @@
                 log_prob = self._posterior.net.log_prob(theta_batch, context=x_batch)
                 loss = -torch.mean(log_prob)
                 loss.backward()
-                if clip_max_norm is not None:
+                if clip_max_norm is  None:
                     clip_grad_norm_(
                         self._posterior.net.parameters(), max_norm=clip_max_norm,
                     )

Mutant 59

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -268,7 +268,7 @@
                     )
                 optimizer.step()
 
-            epoch += 1
+            epoch = 1
 
             # Calculate validation performance.
             self._posterior.net.eval()

Mutant 60

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -268,7 +268,7 @@
                     )
                 optimizer.step()
 
-            epoch += 1
+            epoch -= 1
 
             # Calculate validation performance.
             self._posterior.net.eval()

Mutant 61

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -268,7 +268,7 @@
                     )
                 optimizer.step()
 
-            epoch += 1
+            epoch += 2
 
             # Calculate validation performance.
             self._posterior.net.eval()

Mutant 62

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -272,7 +272,7 @@
 
             # Calculate validation performance.
             self._posterior.net.eval()
-            log_prob_sum = 0
+            log_prob_sum = 1
             with torch.no_grad():
                 for batch in val_loader:
                     theta_batch, x_batch = (

Mutant 66

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -282,7 +282,7 @@
                     log_prob = self._posterior.net.log_prob(
                         theta_batch, context=x_batch
                     )
-                    log_prob_sum += log_prob.sum().item()
+                    log_prob_sum = log_prob.sum().item()
             self._val_log_prob = log_prob_sum / num_validation_examples
 
             self._maybe_show_progress(self._show_progress_bars, epoch)

Mutant 68

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -283,7 +283,7 @@
                         theta_batch, context=x_batch
                     )
                     log_prob_sum += log_prob.sum().item()
-            self._val_log_prob = log_prob_sum / num_validation_examples
+            self._val_log_prob = log_prob_sum * num_validation_examples
 
             self._maybe_show_progress(self._show_progress_bars, epoch)
 

Mutant 74

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -333,7 +333,7 @@
         self.prior = prior
         self.x = x
 
-        if mcmc_method in ("slice", "hmc", "nuts"):
+        if mcmc_method in ("XXsliceXX", "hmc", "nuts"):
             return self.pyro_potential
         else:
             return self.np_potential

Mutant 75

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -333,7 +333,7 @@
         self.prior = prior
         self.x = x
 
-        if mcmc_method in ("slice", "hmc", "nuts"):
+        if mcmc_method in ("slice", "XXhmcXX", "nuts"):
             return self.pyro_potential
         else:
             return self.np_potential

Mutant 76

--- sbi/inference/snle/snle_base.py
+++ sbi/inference/snle/snle_base.py
@@ -333,7 +333,7 @@
         self.prior = prior
         self.x = x
 
-        if mcmc_method in ("slice", "hmc", "nuts"):
+        if mcmc_method in ("slice", "hmc", "XXnutsXX"):
             return self.pyro_potential
         else:
             return self.np_potential