# Initialization


```python
%matplotlib inline
%config InlineBackend.figure_format = 'svg'

import numpy as np
import scqubits as scq
```

# Transmon qubit

The transmon qubit and the Cooper pair box are described by the Hamiltonian 
\begin{equation}
H_\text{CPB}=4E_\text{C}(\hat{n}-n_g)^2+\frac{1}{2}E_\text{J}\sum_n(|n\rangle\langle n+1|+\text{h.c.}),
\end{equation}
expressed in the charge basis. Here,  $E_C$ is the charging energy, $E_J$ the Josephson energy, and $n_g$ the offset charge. Internal representation of the Hamiltonian proceeds via the charge basis with charge-number cutoff specified by `ncut`, which must be chosen sufficiently large for convergence.

An instance of the transmon qubit is initialized as follows:


```python
tmon = scq.Transmon(
    EJ=30.02,
    EC=1.2,
    ng=0.3,
    ncut=31
)
```

Or, alternatively, we can use the graphical user interface (if the `ipywidgets` package is installed)


```python
tmon = scq.Transmon.create()
```


    HBox(children=(VBox(children=(HBox(children=(Label(value='EJ'), FloatText(value=15.0)), layout=Layout(justify_…



    Output()


## Calculating and plotting energy levels and eigenfunctions

The energy eigenvalues of the transmon Hamiltonian for the given set of model parameters are obtained by calling the `eigenvals()` method. The optional parameter `evals_count` specifies the sought number of eigenenergies.


```python
tmon.eigenvals(evals_count=12)
```




    array([-12.07703386,  -6.39445819,  -1.05664942,   3.89594699,
             8.34157217,  12.54032139,  14.69273601,  20.71739651,
            20.85721955,  30.96770401,  30.96906144,  43.86230239])



To plot eigenenergies as a function of one of the qubit parameters (`EJ`, `EC`, or `ng`), we generate an array of values for the desired parameter and call the method `plot_evals_vs_paramvals`:


```python
ng_list = np.linspace(-2, 2, 220)
tmon.plot_evals_vs_paramvals('ng', ng_list, evals_count=6, subtract_ground=False);
```


    HBox(children=(FloatProgress(value=0.0, description='Spectral data', max=220.0, style=ProgressStyle(descriptio…


    


    

    



```python
tmon.plot_n_wavefunction(esys=None, which=0, mode='real');
```


    

    



```python
tmon.plot_wavefunction(esys=None, which=0, mode='real');
```


    

    



```python
tmon.plot_phi_wavefunction(which=[0, 1, 4, 5], mode='abs_sqr');
```


    

    


## Calculating and visualizing matrix elements

Matrix elements can be calculated by referring to the `Transmon` operator methods in string form. For instance, `.n_operator` yields the charge operator:


```python
tmon.matrixelement_table('n_operator', evals_count=3)
```




    array([[ 0.2999574 , -0.90286728, -0.00126536],
           [-0.90286728,  0.30195231, -1.21191324],
           [-0.00126536, -1.21191324,  0.26241099]])



Visualizing matrix elements is accomplished by calling the `.plot_matrixelements` method:


```python
tmon.plot_matrixelements('n_operator', evals_count=10);
```


    

    



```python
tmon.plot_matrixelements('cos_phi_operator', evals_count=10, show3d=False, show_numbers=True);
```


    

    



```python
fig, ax = tmon.plot_matelem_vs_paramvals('n_operator', 'ng', ng_list, select_elems=4, filename='./data/test');
```


    HBox(children=(FloatProgress(value=0.0, description='Spectral data', max=220.0, style=ProgressStyle(descriptio…


    


    HBox(children=(FloatProgress(value=0.0, max=220.0), HTML(value='')))


    


    

    


## Tunable Transmon

An important modification of the transmon qubit is the replacement of the Josephson junction by a SQUID loop of two Josephson junctions. A flux threaded through this loop can then be used to change the effective Josephson energy of the circuit and thus make the transmon tunable. The resulting Hamiltonian is 
\begin{equation}
H_\text{CPB}=4E_\text{C}(\hat{n}-n_g)^2+\frac{1}{2}E_\text{J,eff}(\Phi_\text{ext})\sum_n(|n\rangle\langle n+1|+\text{h.c.}),
\end{equation}
expressed in the charge basis. Here,  parameters are as above except for the effective Josephson energy $E_\text{J,eff}(\Phi_\text{ext}) = E_{\text{J,max}} \sqrt{\cos^2(\pi\Phi_\text{ext}/\Phi_0)+ d^2 \sin^2 (\pi\Phi_\text{ext}/\Phi_0)}$, where $E_\text{J,max} = E_\text{J1} + E_\text{J2}$ is the maximum Josephson energy, and $d=(E_\text{J1}-E_\text{J2})/(E_\text{J1}+E_\text{J2})$ is the relative junction asymmetry.

An instance of a tunable transmon qubit is obtained like this:


```python
tune_tmon = scq.TunableTransmon(
    EJmax=50.0,
    EC=0.5,
    d=0.01,
    flux=0.0,
    ng=0.0,
    ncut=30
)
```

Alternatively, the `.create` method can again be used if `ipywidgets` is available:


```python
tune_tmon = scq.TunableTransmon.create()
```


    HBox(children=(VBox(children=(HBox(children=(Label(value='EJmax'), FloatText(value=30.0)), layout=Layout(justi…



    Output()



```python
flux_list = np.linspace(-1.1, 1.1, 220)
tune_tmon.plot_evals_vs_paramvals('flux', flux_list, subtract_ground=True);
```


    HBox(children=(FloatProgress(value=0.0, description='Spectral data', max=220.0, style=ProgressStyle(descriptio…


    


    

    



```python

```

930062471db22743ec4b4ca96c60016a933f7b37
ipynb
Jupyter Notebook
examples/demo_transmon.ipynb
IlyaLSMmisis/scqubits-1
c4915c998c2d1ef3348db0e4c423e74c7181da40
BSD-3-Clause
examples/demo_transmon.ipynb
IlyaLSMmisis/scqubits-1
c4915c998c2d1ef3348db0e4c423e74c7181da40
BSD-3-Clause
examples/demo_transmon.ipynb
IlyaLSMmisis/scqubits-1
c4915c998c2d1ef3348db0e4c423e74c7181da40
BSD-3-Clause
Qwen/Qwen-72B
1. YES
2. YES