```python
from sympy import *
from IPython.display import display
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
init_printing()
```

### Parameter derivatives of the VMC energy

Take a derivative of the VMC energy with respect to parameters in the wavefunction.   Express it in terms of values to be collected during a VMC run.


```python
# Wavefunction
psi = Function('psi')

# Variational parameter
p = Symbol('p')

# Local energy
Eloc = Function('E_L')

# Spatial coordinate
x = Symbol('x')
```


```python
# Wavefunction normalization integral

norm = Integral(psi(p,x)*psi(p,x),x)
norm
```


```python
# Energy integral (numerator)
num = Integral(psi(p,x)*psi(p,x)*Eloc(p,x),x)
num
```


```python
# Derivative with respect to parameter p
pd = diff(num/norm,p)
pd
```


```python
expand(pd)
```


```python
# Define a function that is the derivative the local energy (wrt parameter p)
Eloc_p = Function("E'")
Eloc_p
```




    E'




```python
# Replace normalization integral with N
N = Symbol('N')
pd2 = pd.subs(norm, N)
pd2
```


```python

```


```python
d = diff(Eloc(p,x),p)
d, type(d)
```




    (Derivative(E_L(p, x), p), sympy.core.function.Derivative)




```python
# Replace derivative of local energy with function
pd3 = expand(pd2.replace(diff(Eloc(p,x),p), Eloc_p(p,x)))
pd3
```


```python
# Define function that is the derivative of the wavefunction (wrt parameter p)
psi_p = Function("\psi'")
psi_p
```




    \psi'




```python
pd4 = pd3.replace(diff(psi(p,x),p),psi_p(p,x))
pd4
```


```python
# Need to collect
# E_L (the usual VMC energy), E',  E_L*psi', and psi'/psi

E_ave = Symbol("<E>")
Ep_ave = Symbol("<E'>")
psip_ave = Symbol("<\psi'/\psi>")
E_psip_ave = Symbol("<E \psi'/\psi>")
```


```python
E_psip_integral = Integral(2*Eloc(p,x) * psi_p(p,x) * psi(p,x), x)/N
E_psip_integral
```


```python
E_integral = Integral(Eloc(p,x) * psi(p,x)**2, x)/N
E_integral
```


```python
Ep_integral = Integral(Eloc_p(p,x) * psi(p,x)**2, x)/N
Ep_integral
```


```python
psip_integral = Integral(2*psi_p(p,x) * psi(p,x),x)/N
psip_integral
```


```python
pd5 = pd4.subs(E_integral, E_ave).subs(Ep_integral, Ep_ave).\
subs(psip_integral, 2*psip_ave).subs(E_psip_integral, 2*E_psip_ave)
pd5
```


```python

```


```python

```

258d76bd069cc25f0d04c07baad1e383064a0f81
ipynb
Jupyter Notebook
Variational/Parameter_Optimization.ipynb
QMCPACK/qmc_algorithms
015fd1973e94f98662149418adc6b06dcd78946d
MIT
2018-02-06T06:15:19.000Z
2019-11-26T23:54:53.000Z
Variational/Parameter_Optimization.ipynb
chrinide/qmc_algorithms
015fd1973e94f98662149418adc6b06dcd78946d
MIT
Variational/Parameter_Optimization.ipynb
chrinide/qmc_algorithms
015fd1973e94f98662149418adc6b06dcd78946d
MIT
2017-11-14T20:25:00.000Z
2022-02-28T06:02:01.000Z
Qwen/Qwen-72B
1. YES
2. YES