-
Notifications
You must be signed in to change notification settings - Fork 6
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
WIP : Spin Operators, Tests. WD : +,-,ops added. #22
Changes from 1 commit
0fe8886
98fec4b
f3b5be2
d9574c2
722fbc5
0dc1e40
d9007d7
62145d3
879e9f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,9 @@ end | |
|
||
*(dm1::DualMatrix, dm2::DualMatrix) = (dm1.qarr*dm2.qarr)' | ||
|
||
+(qarr1::Union(QuArray,CTranspose), qarr2::Union(QuArray,CTranspose)) = bases(qarr1) == bases(qarr2) ? (return QuArray(coeffs(qarr1)+coeffs(qarr2), bases(qarr1))) : "Not compatible" | ||
-(qarr1::Union(QuArray,CTranspose), qarr2::Union(QuArray,CTranspose)) = bases(qarr1) == bases(qarr2) ? (return QuArray(coeffs(qarr1)-coeffs(qarr2), bases(qarr1))) : "Not compatible" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that we already have this pattern in the code, but maybe we should be annotating arguments as Thoughts, @acroy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could, as QuArray and CTranspose are subtypes of AbstractQuArray. But could we compare bases if we used such a construct ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Your new method signature for -{B<:OrthonormalBasis,N}(qarr1::AbstractQuArray{B,N},qarr2::AbstractQuArray{B,N}) ...and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jrevels : That would be nicer. I guess we haven't really specified the interface for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep - I think Edit: Though defining the interface for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. That should be a separate PR and maybe we should also document the interface somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we don't want to always return a |
||
# scaling | ||
Base.scale!(num::Number, qarr::QuArray) = (scale!(num, rawcoeffs(qarr)); return qarr) | ||
Base.scale!(num::Number, ct::CTranspose) = CTranspose(scale!(num', ct.qarr)) | ||
|
@@ -90,18 +93,18 @@ normalize(qarr::Union(QuArray,CTranspose)) = normalize!(copy(qarr)) | |
|
||
# General tensor product definitions for orthonormal bases | ||
function tensor{B<:OrthonormalBasis,T1,T2,N}(qarr1::AbstractQuArray{B,T1,N}, qarr2::AbstractQuArray{B,T2,N}) | ||
return QuArray(kron(coeffs(qarr1), coeffs(qarr2)), | ||
return QuArray(kron(coeffs(qarr1), coeffs(qarr2)), | ||
map(tensor, bases(qarr1), bases(qarr2))) | ||
end | ||
|
||
function tensor{B<:OrthonormalBasis,T1,T2,N}(qarr1::CTranspose{B,T1,N}, qarr2::CTranspose{B,T2,N}) | ||
return QuArray(kron(rawcoeffs(qarr1), rawcoeffs(qarr2)), | ||
return QuArray(kron(rawcoeffs(qarr1), rawcoeffs(qarr2)), | ||
map(tensor, rawbases(qarr1), rawbases(qarr2)))' | ||
end | ||
|
||
function tensor{B<:OrthonormalBasis}(ket::QuVector{B}, bra::DualVector{B}) | ||
return QuArray(kron(coeffs(ket), coeffs(bra)), | ||
bases(ket,1), | ||
return QuArray(kron(coeffs(ket), coeffs(bra)), | ||
bases(ket,1), | ||
bases(bra,1)) | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
########################### | ||
# Ladder Operator Methods # | ||
########################### | ||
# n specifies which particle (a.k.a tensor product | ||
########################### | ||
# n specifies which particle (a.k.a tensor product | ||
# factor) the operator acts on | ||
raiseop(b::AbstractBasis, n=1) = QuArray(raisematrix(size(b), n), b, b) | ||
raiseop(lens, n=1) = raiseop(FiniteBasis(lens), n) | ||
|
||
lowerop(b::AbstractBasis, n=1) = QuArray(lowermatrix(size(b), n), b, b) | ||
lowerop(lens, n=1) = lowerop(FiniteBasis(lens), n) | ||
|
||
|
@@ -22,10 +22,22 @@ | |
before_eye(lens, pivot) = speye(prod(lens[[1:pivot-1]])) | ||
after_eye(lens, pivot) = speye(prod(lens[[pivot+1:length(lens)]])) | ||
function eye_sandwich(lens, pivot, op) | ||
return kron(before_eye(lens, pivot), | ||
op, | ||
return kron(before_eye(lens, pivot), | ||
op, | ||
after_eye(lens, pivot)) | ||
end | ||
|
||
function positionop(n::Int) | ||
cop = raiseop(n) | ||
return (cop+cop')/sqrt(2.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acroy Ah! Once again, I comment only to find that you've beat me to it by the time I'm done writing. I'm starting to believe that you are, in fact, a ninja... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I just realized we won't be able to perform an in-place scaling of the Float64 array by a complex number; see my edit on my comment below. |
||
end | ||
|
||
function momentumop(n::Int) | ||
cop = raiseop(n) | ||
return im*(cop-cop')/sqrt(2.) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple of points here:
function momentumop(n::Int)
cop = raiseop(n)
return scale!(im/sqrt(2.), cop-cop')
end Edit: Actually, we can't scale the momentum operator in-place with an imaginary number, as it'll throw an function positionop(n::Int)
cop = raiseop(n)
return scale!(1/sqrt(2.), cop+cop')
end
function momentumop(n::Int)
cop = raiseop(n)
return scale(im/sqrt(2.), cop-cop')
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jrevels if I my understanding of the first comment is right it meant that we should be able to track intermediate steps in producing the final answer. In specific have functions which produce the intermediate results and reuse them as necessary ?? But in these case it is a straight forward implementation. Please do correct me if I am missing something. |
||
export raiseop, | ||
lowerop | ||
lowerop, | ||
positionop, | ||
momentumop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to use
error("Bases not compatible.")
here. Should we use type parameters (for the basis andN
) to restrict the functions in the first place?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acroy something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that way we get e
MethodError
"for free" if someone tries to add say a QuVector and a QuMatrix. Nevertheless we have to check that the bases are the same (I am not sure if==
works though).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
==
is the right thing to do here, since it can be overloaded to work properly for each basis type - "value" equality is what we're looking for here, yes? Also, all we need to do to support mixed-basis type operations is to simply define some promotion rules between the various basis types, of which there aren't that many.