# First example

As a first example use case for BubbleDet, let us consider a simple real scalar model in 4d. A code to compute the nucleation rate for this model is outlined below.

To start, we import the relevant libraries, and define the model by a tree-level potential. We also define the first and second derivatives of the potential.

```
import numpy as np # arrays and maths
from cosmoTransitions.tunneling1D import SingleFieldInstanton # bounce
from BubbleDet import BubbleConfig, ParticleConfig, BubbleDeterminant
# dimension
dim = 4
# parameters
msq = 0.25
g = -1
lam = 1
# potential and its derivatives
def V(x):
return 1 / 2 * msq * x**2 + 1 / 6 * g * x**3 + 1 / 24 * x**4
def dV(x):
return msq * x + 1 / 2 * g * x**2 + 1 / 6 * x**3
def ddV(x):
return msq + g * x + 1 / 2 * x**2
# minima
phi_true = (-3 * g + np.sqrt(9 * g**2 - 24 * msq)) / 2
phi_false = 0
```

For the values of the parameters we have chosen, the potential has a false
(metastable) minimum at `phi_false`

, and a true (stable) vacuum at
`phi_true`

.

We then use CosmoTransitions to solve for the bubble, or bounce, profile. Note that it is important that the bounce is solved to high accuracy as numerical errors propagate to the functional determinant. We also compute the tree-level action evaluated on the bubble.

```
# nucleation object
ct_obj = SingleFieldInstanton(
phi_true,
phi_false,
V,
dV,
d2V=ddV,
alpha=(dim - 1),
)
# bounce calculation
profile = ct_obj.findProfile(xtol=1e-9, phitol=1e-9)
# bounce action
S0 = ct_obj.findAction(profile)
```

This profile can then be used to construct a `BubbleConfig`

object,
which characterises the background field.

```
# creating bubble config instance
bub_config = BubbleConfig.fromCosmoTransitions(ct_obj, profile)
```

Then, a `ParticleConfig`

object is constructed which characterises
the fluctuating particle, in this case the Higgs itself.

```
# creating particle instance
higgs = ParticleConfig(
W_Phi=ddV,
spin=0,
dof_internal=1,
zero_modes="Higgs",
)
```

These are then passed to construct a `BubbleDeterminant`

instance,
from which we can call all the major functionality of the BubbleDet package,
including the computation of the full functional determinant of scalar field
fluctuations in the background of the bubble.

```
# creating bubble determinant instance
bub_det = BubbleDeterminant(bub_config, higgs)
# fluctuation determinant
S1, S1_err = bub_det.findDeterminant()
# printing results
print("S0 :", S0)
print("S1 :", S1)
print("err(S1) :", S1_err)
```

The variables `S0`

and `S1`

store the tree-level and one-loop
action for the bounce configuration, and `S1_err`

gives an estimate
for the numerical error in `S1`

.

Here is a component diagram showing how the different classes and packages interacted in this first example.