-
Notifications
You must be signed in to change notification settings - Fork 49
QuTiPv5 Paper Notebook: smesolve #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c82e911
Added smesolve notebook according to paper
Langhaarzombie b5d8cce
Corrected typos, added tests
Langhaarzombie ade19b7
Fixed test, faster computation, content fixes
Langhaarzombie 634993e
Added reference to docs
Langhaarzombie ceb2fe7
Fixed Latex formatting issue with dagger
Langhaarzombie b5c5a73
Merge branch 'qutip:main' into feature/ntbk_smesolve
Langhaarzombie 78a8cdc
Typos
pmenczel cd8b688
Added v5 paper ref
Langhaarzombie 305e0da
Merge remote-tracking branch 'upstream/main' into feature/ntbk_smesolve
nwlambert a5df6a5
Merge branch 'qutip:main' into feature/ntbk_smesolve
Langhaarzombie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.13.8 | ||
kernelspec: | ||
display_name: qutip-tutorials-v5 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# QuTiPv5 Paper Example: Stochastic Solver - Homodyne Detection | ||
|
||
Authors: Maximilian Meyer-Mölleringhof ([email protected]) | ||
|
||
## Introduction | ||
|
||
When modelling an open quantum system, stochastic noise can be used to simulate a large range of phenomena. | ||
In the `smesolve()` solver, noise appears because of continuous measurement. | ||
It allows us to generate the trajectory evolution of a quantum system conditioned on a noisy measurement record. | ||
Historically speaking, such models were used by the quantum optics community to model homodyne and heterodyne detection of light emitted from a cavity. | ||
However, this solver is of course quite general and can thus also be applied to other problems. | ||
|
||
In this example we look at an optical cavity whose output is subject to homodyne detection. | ||
Such a cavity obeys the general stochastic master equation | ||
|
||
$d \rho(t) = -i [H, \rho(t)] dt + \mathcal{D}[a] \rho (t) dt + \mathcal{H}[a] \rho dW(t)$ | ||
|
||
with the Hamiltonian | ||
|
||
$H = \Delta a^\dag a$ | ||
Langhaarzombie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
and the Lindblad dissipator | ||
|
||
$\mathcal{D}[a] = a \rho a^\dag - \dfrac{1}{2} a^\dag a \rho - \dfrac{1}{2} \rho a^\dag a$. | ||
|
||
The stochastic part | ||
|
||
$\mathcal{H}[a]\rho = a \rho + \rho a^\dag - tr[a \rho + \rho a^\dag]$ | ||
|
||
captures the conditioning of the trajectory through continious monitoring of the operator $a$. | ||
The term $dW(t)$ is the increment of a Wiener process that obeys $\mathbb{E}[dW] = 0$ and $\mathbb{E}[dW^2] = dt$. | ||
|
||
```python | ||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
from qutip import about, coherent, destroy, mesolve, smesolve | ||
|
||
%matplotlib inline | ||
``` | ||
|
||
## Problem Parameters | ||
|
||
```python | ||
N = 20 # dimensions of Hilbert space | ||
delta = 10 * np.pi # cavity detuning | ||
kappa = 1 # decay rate | ||
A = 4 # initial coherent state intensity | ||
``` | ||
|
||
```python | ||
a = destroy(N) | ||
x = a + a.dag() # operator for expectation value | ||
H = delta * a.dag() * a # Hamiltonian | ||
mon_op = np.sqrt(kappa) * a # continiously monitored operators | ||
``` | ||
|
||
## Solving for the Time Evolution | ||
|
||
We calculate the predicted trajectory conditioned on the continious monitoring of operator $a$. | ||
This is compared to the regular `mesolve()` solver for the same model but without resolving conditioned trajectories. | ||
|
||
```python | ||
rho_0 = coherent(N, np.sqrt(A)) # initial state | ||
times = np.arange(0, 1, 0.0025) | ||
num_traj = 500 # number of computed trajectories | ||
opt = {"dt": 0.00125, "store_measurement": True} | ||
``` | ||
Langhaarzombie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```python | ||
me_solution = mesolve(H, rho_0, times, c_ops=[mon_op], e_ops=[x]) | ||
``` | ||
|
||
```python | ||
stoc_solution = smesolve( | ||
H, rho_0, times, sc_ops=[mon_op], e_ops=[x], ntraj=num_traj, options=opt | ||
) | ||
``` | ||
|
||
## Comparison of Results | ||
|
||
We plot the averaged homodyne current $J_x = \langle x \rangle + dW / dt$ and the average system behaviour $\langle x \rangle$ for 500 trajectories. | ||
This is compared with the prediction of the regular `mesolve()` solver that does not include the conditioned trajectories. | ||
Since the conditioned expectation values do not depend on the trajectories, we expect that this reproduces the result of the standard `me_solve`. | ||
|
||
```python | ||
stoc_meas_mean = np.array(stoc_solution.measurement).mean(axis=0)[0, :].real | ||
``` | ||
|
||
```python | ||
plt.figure() | ||
plt.plot(times[1:], stoc_meas_mean, lw=2, label=r"$J_x$") | ||
plt.plot(times, stoc_solution.expect[0], label=r"$\langle x \rangle$") | ||
plt.plot( | ||
times, | ||
me_solution.expect[0], | ||
"--", | ||
color="gray", | ||
label=r"$\langle x \rangle$ mesolve", | ||
) | ||
|
||
plt.legend() | ||
plt.xlabel(r"$t \cdot \kappa$") | ||
plt.show() | ||
``` | ||
|
||
## About | ||
|
||
```python | ||
about() | ||
``` | ||
|
||
## Testing | ||
|
||
```python | ||
Langhaarzombie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert np.allclose( | ||
stoc_solution.expect[0] == me_solution.expect[0] | ||
), "The smesolve and mesolve do not preoduce the same trajectory." | ||
``` | ||
Langhaarzombie marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.