-
Notifications
You must be signed in to change notification settings - Fork 17
Refactor indexing #230
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
base: master
Are you sure you want to change the base?
Refactor indexing #230
Conversation
Little update on the status here: derivation of equations, averaging and the cumulant expansion all work so far. I haven't checked the results in detail, but the equations look okay. I'll check that by comparing to a "brute-force" approach later, when I can actually get a numerical solution out. The next step would be to implement A couple of things I've learned so far:
Some other notes, that can be addressed in a follow-up PR:
@ChristophHotter anything you'd like to add here? |
That sounds very good, nice!
|
…ssing again -- this shouldn't be necessary
Okay, completing equations now kinda works. However, simplification of sum terms is an issue. They currently don't get fully simplified which leads to "leftover" terms that should actually be 0. Therefore, we add some unnecessary equations when completing a set that has some sums. For documentation purposes, here are my thoughts:
|
…his is really ugly
Alright, significant update here: the following example works, and actually agrees with the results when doing this in a "brute-force" approach, where we create all the Hilbert spaces explicitly and derive all the equations. using QuantumCumulants
using OrdinaryDiffEq, ModelingToolkit
# Hilbertspace
hc = FockSpace(:cavity)
ha = NLevelSpace(:atom,2)
h = hc ⊗ ha
# operators
@qnumbers a::Destroy(h)
σ(α,β,i) = IndexedOperator(Transition(h, :σ, α, β),i)
@cnumbers N Δ κ Γ R ν
g(i) = IndexedVariable(:g, i)
i = Index(h,:i,N,ha)
j = Index(h,:j,N,ha)
k = Index(h,:k,N,ha)
# Hamiltonian
H = -Δ*a'a + Σ(g(i)*( a'*σ(1,2,i) + a*σ(2,1,i) ),i)
# Jump operators with corresponding rates
J = [a, σ(1,2,i), σ(2,1,i), σ(2,2,i)]
rates = [κ, Γ, R, ν]
# Derive equations
ops = [a'*a, σ(2,2,j)]
eqs = meanfield(ops,H,J;rates=rates,order=2)
# custom filter function
φ(x::Average) = φ(x.arguments[1])
φ(::Destroy) = -1
φ(::Create) =1
φ(x::QTerm) = sum(map(φ, x.args_nc))
φ(x::Transition) = x.i - x.j
φ(x::IndexedOperator) = x.op.i - x.op.j
φ(x::Sum) = φ(x.term)
phase_invariant(x) = iszero(φ(x))
# Complete equations
eqs_c = complete(eqs; filter_func=phase_invariant)
N0 = 2
eqs_eval = evaluate(eqs_c; limits=Dict(N => N0))
@named sys = ODESystem(eqs_eval)
u0 = zeros(ComplexF64, length(eqs_eval))
g_ = g(i).arguments[1] # TODO: this is awkward; need a clean way to define the Array that is g without any indices
ps = [
Δ => 0.0;
g_ => [0.5 for i=1:N0];
κ => 1.0;
Γ => 0.1;
R => 0.9;
ν => 0.0;
]
prob = ODEProblem(sys, u0, (0.0, 10.0), ps)
sol = solve(prob, Tsit5())
using PyPlot; pygui(true)
plot(sol.t, sol[a'*a]) |
While the basic idea works, and I'm still in favor of using this approach, there are still some open topics. Especially towards the end, I got a bit sloppy and the code isn't super nice or easy to debug.
Things that still need to be done:
I'll leave it at that for now, however. @ChristophHotter I think now is the time to really have a look at the suggested implementation here. You can also use the above example to test things a bit. I left a whole bunch of Also, basically all the old files are outdated. I didn't delete them, but they are not actually
And, of course, check the changes to other exisiting files such as |
This lays the foundation for refactoring the entire indexing implementation. The basic idea is one we already discussed in the very beginning. Essentially, we want to use the following commutation relation for indexed bosonic operators
Similarly, for transition operators, we have
The problem here is the fact that the original product of transition operators on the left-hand side appears again on the right-hand side. This can potentially lead to infinite recursion. Currently, the solution to this problem is to store the fact that in the latter product$r \neq s$ on any sum expression that may occur. This has other problems, mostly the complex implementation and handling all kinds of special cases.
Instead, here I propose to implement the commutation relations using the above relations directly. To prevent infinite recursion on the transition operators, we store an additional field on indexed operators called
merge_events
, which is just aVector{UUID}
. Whenever two indexed transitions get rewritten according to the above, we generate a random UUID, currently usingUUIDs.uuid4()
, and store that on two copies of the original transition operators. Therefore, the operators behave just as they should when multiplied together with other operators, except when we find a shared UUID in themerge_events
. That can only occur when a product of indexed transitions was returned from the*
implementation and thus they have already been merged.To ensure that in products involving three or more indexed transitions, we also sort by the length of the
merge_events
vector.Since this needs to be a full rewrite, I'm opening this as a draft until we add back all the features. If we don't complete the rewrite within this PR, it at least serves as documentation of the fundamental concept, which seems to work.
Feature list:
FYI, @ChristophHotter and @j-moser