<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://spindynamics.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Cavity_QED_and_spin-boson_simulations</id>
	<title>Cavity QED and spin-boson simulations - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://spindynamics.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Cavity_QED_and_spin-boson_simulations"/>
	<link rel="alternate" type="text/html" href="https://spindynamics.org/wiki/index.php?title=Cavity_QED_and_spin-boson_simulations&amp;action=history"/>
	<updated>2026-08-13T13:19:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.15</generator>
	<entry>
		<id>https://spindynamics.org/wiki/index.php?title=Cavity_QED_and_spin-boson_simulations&amp;diff=9892&amp;oldid=prev</id>
		<title>Kuprov: Getting started guide for cavity QED and spin-boson simulations (Spinach 2.12, PR 195)</title>
		<link rel="alternate" type="text/html" href="https://spindynamics.org/wiki/index.php?title=Cavity_QED_and_spin-boson_simulations&amp;diff=9892&amp;oldid=prev"/>
		<updated>2026-08-06T04:45:34Z</updated>

		<summary type="html">&lt;p&gt;Getting started guide for cavity QED and spin-boson simulations (Spinach 2.12, PR 195)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
This tutorial builds a spin-boson simulation from nothing: a spin coupled to an electromagnetic cavity mode, then the same cavity made lossy and given a temperature, and finally a pulse sequence run through the device context. The reference material is the [[Spin system specification#Bosonic modes|bosonic modes]] section of the spin system specification and the [[device.m]] page; the shipped examples live in the examples/quantum_tech folder of the ''Spinach'' distribution.&lt;br /&gt;
&lt;br /&gt;
==Declaring a cavity mode==&lt;br /&gt;
&lt;br /&gt;
''Spinach'' would refuse to run in script mode, so the calculation starts with a function declaration:&lt;br /&gt;
&lt;br /&gt;
     function cavity_tutorial()&lt;br /&gt;
&lt;br /&gt;
Bosonic modes are declared in [[sys]].isotopes alongside spins. The label carries the number of Fock states to keep: 'C5' is a cavity mode truncated at five population levels. Here it is accompanied by an electron in a 0.33 Tesla magnet:&lt;br /&gt;
&lt;br /&gt;
     % Magnet field&lt;br /&gt;
     [[sys]].magnet=0.33;&lt;br /&gt;
 &lt;br /&gt;
     % An electron and a five-level cavity mode&lt;br /&gt;
     [[sys]].isotopes={'E','C5'};&lt;br /&gt;
&lt;br /&gt;
The number of levels is a convergence parameter. Five is generous for a calculation that never puts more than one photon into the cavity, and far too few for a coherent state of amplitude three; the safe procedure is to repeat the calculation with more levels and watch the answer stop moving.&lt;br /&gt;
&lt;br /&gt;
The mode frequency goes into [[inter]].modes.frqs, in Hz, with an empty cell for every particle that is not a mode. Making the cavity resonant with the electron Larmor frequency is the standard starting point:&lt;br /&gt;
&lt;br /&gt;
     % Cavity resonant with the electron Larmor frequency&lt;br /&gt;
     [[inter]].modes.frqs={[] -sys.magnet*spin('E')/(2*pi)};&lt;br /&gt;
&lt;br /&gt;
The coupling between the spin and the mode is an exchange coupling, declared in the upper triangle of a cell array with one row and column per particle:&lt;br /&gt;
&lt;br /&gt;
     % Jaynes-Cummings coupling of 2.828 MHz&lt;br /&gt;
     [[inter]].modes.exchange=cell(2,2);&lt;br /&gt;
     [[inter]].modes.exchange{1,2}=2.828e6;&lt;br /&gt;
&lt;br /&gt;
==Formalism and basis set==&lt;br /&gt;
&lt;br /&gt;
A two-particle system of this size is comfortable in complete Hilbert space:&lt;br /&gt;
&lt;br /&gt;
     % Basis set&lt;br /&gt;
     [[bas]].formalism='zeeman-hilb';&lt;br /&gt;
     [[bas]].approximation='none';&lt;br /&gt;
 &lt;br /&gt;
     % Spinach housekeeping&lt;br /&gt;
     spin_system=[[create.m|create]](sys,inter);&lt;br /&gt;
     spin_system=[[basis.m|basis]](spin_system,bas);&lt;br /&gt;
&lt;br /&gt;
At this point ''Spinach'' prints three console tables that are worth reading: mode parameters, mode couplings by channel, and, when they are present, the modulation blocks. If a number is not where it was intended to be, it will be visible there.&lt;br /&gt;
&lt;br /&gt;
==Choosing a frame==&lt;br /&gt;
&lt;br /&gt;
Spin-boson systems accept three [[assume.m|assumption sets]]. The 'cavity' set places spins and modes in a common rotating frame and applies the rotating wave approximation, which is what cavity QED usually means:&lt;br /&gt;
&lt;br /&gt;
     % Rotating frame Hamiltonian&lt;br /&gt;
     spin_system=[[assume.m|assume]](spin_system,'cavity');&lt;br /&gt;
     H_JC=[[hamiltonian.m|hamiltonian]](spin_system);&lt;br /&gt;
&lt;br /&gt;
In this frame the mode energy becomes a detuning from the carrier, and the exchange coupling keeps only its flip-flop part. The 'labframe' set retains everything, including the counter-rotating terms, and is the reference against which the approximation should be checked. The 'spin-phonon' set keeps the spins in their usual rotating frames and the modes in the laboratory frame; it is the one to use when longitudinal or modulation couplings are present, because those average to zero in the cavity frame and are refused there.&lt;br /&gt;
&lt;br /&gt;
==The avoided crossing==&lt;br /&gt;
&lt;br /&gt;
The physics of the Jaynes-Cummings model is visible in the one-excitation manifold: the spin excitation and the photon are degenerate at zero detuning, and the coupling splits them. Sweeping the spin detuning and diagonalising that manifold produces the familiar hyperbolae:&lt;br /&gt;
&lt;br /&gt;
     % Electron detuning operator&lt;br /&gt;
     Ez=[[operator.m|operator]](spin_system,{'Lz'},{1});&lt;br /&gt;
 &lt;br /&gt;
     % Locate the one-excitation manifold&lt;br /&gt;
     spin_exc=[[state.m|state]](spin_system,{'ZL2','BL1'},{1,2});&lt;br /&gt;
     cav_exc=[[state.m|state]](spin_system,{'ZL1','BL2'},{1,2});&lt;br /&gt;
     one_quant=speye(size(H_JC,1));&lt;br /&gt;
     one_quant=one_quant(:,[find(diag(spin_exc)&amp;gt;0.5)...&lt;br /&gt;
                            find(diag(cav_exc)&amp;gt;0.5)]);&lt;br /&gt;
 &lt;br /&gt;
     % Detuning range and eigenvalue array&lt;br /&gt;
     delta=2*pi*linspace(-15e6,15e6,100);&lt;br /&gt;
     eig_array=zeros(2,100);&lt;br /&gt;
 &lt;br /&gt;
     % Loop over detunings&lt;br /&gt;
     for n=1:numel(delta)&lt;br /&gt;
         H=delta(n)*Ez+H_JC; H=(H+H')/2;&lt;br /&gt;
         eig_array(:,n)=eig(full(one_quant'*H*one_quant));&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     % Plot the one-photon case&lt;br /&gt;
     kfigure(); plot(1e-6*delta/(2*pi),1e-6*eig_array/(2*pi));&lt;br /&gt;
     axis tight; kxlabel('detuning, MHz');&lt;br /&gt;
     kylabel('energy levels, MHz'); kgrid;&lt;br /&gt;
&lt;br /&gt;
Bosonic states use their own labels: 'BL#' is the projector onto the #-th Fock level, counted from 1, so 'BL1' is the vacuum and 'BL2' is the one-photon state. Spin energy levels use the parallel 'ZL#' notation. The minimum splitting at zero detuning is twice the declared coupling.&lt;br /&gt;
&lt;br /&gt;
==A lossy cavity at finite temperature==&lt;br /&gt;
&lt;br /&gt;
Real resonators leak. Damping is declared with the mode, as a lifetime, a linewidth, or a quality factor, and a temperature must be supplied because the thermal occupation of the mode bath is part of the physics:&lt;br /&gt;
&lt;br /&gt;
     % Microwave resonator with five Fock levels&lt;br /&gt;
     [[sys]].magnet=0; [[sys]].isotopes={'C5'};&lt;br /&gt;
     [[inter]].modes.frqs={6.02e9};&lt;br /&gt;
     [[inter]].modes.lifetimes={10e-9};&lt;br /&gt;
     [[inter]].modes.t2_times={9.9e-9};&lt;br /&gt;
     [[inter]].temperature=0.050;&lt;br /&gt;
 &lt;br /&gt;
     % Dissipation needs Liouville space&lt;br /&gt;
     [[bas]].formalism='zeeman-liouv';&lt;br /&gt;
     [[bas]].approximation='none';&lt;br /&gt;
&lt;br /&gt;
Dissipators cannot be represented in Hilbert space, so a Liouville space formalism is mandatory here; ''Spinach'' warns and omits the mode dissipation if this is forgotten. The evolution generator is assembled in the usual way:&lt;br /&gt;
&lt;br /&gt;
     % Dissipative evolution generator&lt;br /&gt;
     H=[[hamiltonian.m|hamiltonian]](assume(spin_system,'labframe'));&lt;br /&gt;
     R=[[relaxation.m|relaxation]](spin_system);&lt;br /&gt;
     G=-1i*H+R;&lt;br /&gt;
&lt;br /&gt;
A Fock state and a coherent state make instructive initial conditions: the Fock state cascades down the ladder, and the coherent state decays with its Poisson structure largely intact. Both settle into the thermal state of the mode.&lt;br /&gt;
&lt;br /&gt;
     % Fock state and coherent state&lt;br /&gt;
     rho_fock=[[state.m|state]](spin_system,'BL5',1);&lt;br /&gt;
     rho_coh=[[coherent.m|coherent]](spin_system,1,1.5);&lt;br /&gt;
&lt;br /&gt;
[[coherent.m]] reports the norm that the Fock space truncation removed from the Poisson tail. If that number is not small, the mode needs more levels - this is the truncation convergence check in its most convenient form.&lt;br /&gt;
&lt;br /&gt;
==Running a pulse sequence: the device context==&lt;br /&gt;
&lt;br /&gt;
Spin-boson systems are devices rather than molecules in magnets: the spin subsystem has an orientation, the cavity does not. They are therefore run through [[device.m]] rather than [[liquid.m]] or [[powder.m]]. The example below is a spin coupled longitudinally to a phonon mode, which produces both spin coherence modulation and a spin-conditioned displacement of the oscillator:&lt;br /&gt;
&lt;br /&gt;
     % An electron and a seven-level phonon mode&lt;br /&gt;
     [[sys]].magnet=0; [[sys]].isotopes={'E','V7'};&lt;br /&gt;
     [[inter]].modes.frqs={[] 20e6};&lt;br /&gt;
 &lt;br /&gt;
     % Longitudinal coupling: row 1 carries the spin&lt;br /&gt;
     % projection, column 2 carries the quadrature&lt;br /&gt;
     [[inter]].modes.longitudinal=cell(2,2);&lt;br /&gt;
     [[inter]].modes.longitudinal{1,2}=4e6*sqrt(2);&lt;br /&gt;
 &lt;br /&gt;
     % Sequence parameters&lt;br /&gt;
     parameters.sweep=5e8; parameters.npoints=501;&lt;br /&gt;
     parameters.rho0=state(spin_system,{'Lx','BL1'},{1,2});&lt;br /&gt;
 &lt;br /&gt;
     % Trajectory through the device context&lt;br /&gt;
     traj=[[device.m|device]](spin_system,@traject,parameters,'spin-phonon');&lt;br /&gt;
&lt;br /&gt;
The context builds the Hamiltonian at the requested orientation of the spin subsystem, adds relaxation and kinetics, applies transmitter offsets to the spin channels and parameters.mode_offset detunings to the modes, and hands the generators to the sequence. Drives on a mode are not a context matter: the sequence builds them from the creation and annihilation operators of the mode it drives.&lt;br /&gt;
&lt;br /&gt;
==Exercises==&lt;br /&gt;
&lt;br /&gt;
# Repeat the avoided crossing calculation with 'labframe' instead of 'cavity' and compare the splitting. How large does the coupling have to become before the counter-rotating terms matter?&lt;br /&gt;
# Increase the Fock truncation of the resonator from five levels to ten and watch the coherent state decay again. At which amplitude does the truncation start to distort the answer?&lt;br /&gt;
# Replace the electron in the first calculation with a proton, adjust the cavity frequency accordingly, and confirm that the vacuum Rabi oscillation still transfers the excitation completely.&lt;br /&gt;
# Declare a transmon instead of a cavity mode, obtain its frequency and anharmonicity from Josephson and charging energies with [[ejec2duffing.m]], and look at the anharmonic ladder.&lt;br /&gt;
# Add a dispersive coupling between a spin and a cavity and watch the cavity frequency shift with the spin state - the mechanism behind circuit QED readout.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[[Spin system specification]], [[Relaxation theory parameters]], [[Basis set specification]], [[device.m]], [[coherent.m]], [[rlx_modes.m]], [[assume.m]], [[create.m]], [[Kernel contexts]]&lt;br /&gt;
&lt;br /&gt;
''Version 2.12, authors: [[Ilya Kuprov]]''&lt;/div&gt;</summary>
		<author><name>Kuprov</name></author>
		
	</entry>
</feed>