Skip to content
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

Dot product for QuArray's. #36

Merged
merged 1 commit into from
Jun 29, 2015
Merged

Dot product for QuArray's. #36

merged 1 commit into from
Jun 29, 2015

Conversation

amitjamadagni
Copy link
Contributor

I was going through the material on Krylov propagator, as it requires the dot of QuArray's I have added this, I am not really sure if we require this , any comments on this would be helpful.

@acroy
Copy link
Contributor

acroy commented May 25, 2015

+1 for dot. We should also have this for QuMatrix. Related JuliaLang/LinearAlgebra.jl#206.

@acroy
Copy link
Contributor

acroy commented May 25, 2015

The Travis error for 0.4 seems unrelated, but we should have a closer look.

# dot product of QuArray's
dot{B<:OrthonormalBasis}(vec1::AbstractQuVector{B}, vec2::AbstractQuVector{B}) = dot(coeffs(vec1), coeffs(vec2))
# Reference : http://en.wikipedia.org/wiki/Dot_product#Dyadics_and_matrices
dot{B<:OrthonormalBasis}(qm1::AbstractQuMatrix{B}, qm2::AbstractQuMatrix{B}) = trace(coeffs(qm1')*coeffs(qm2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use trace(coeffs(qm1'*qm2)) here. If you want you can also steal trace for QuMatrix from #32. We have to check the issue I linked to if there is a more efficient way to do this dot product.

@amitjamadagni
Copy link
Contributor Author

@acroy @jrevels I have made an attempt at dot (considering dual vectors as well) and trace, added tests for the same. A review would be helpful.

@@ -37,3 +37,8 @@ v1 = [0.5+0*im, 0.+0.*im]
qv1 = normalize!(QuArray(v1))
@assert coeffs(\(sigmax,qv1)) == [0.+0.*im, 1.+0.*im]
@assert coeffs(\(sigmaz, sigmax)) == [0. 1.;-1. 0.]

# tests for trace, dot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the tests being easier to understand on a first glance, which implies more comments. If one doesn't know about Pauli matrices it is unclear what the tests are doing. I think it is better to say for instance

# Pauli matrices sigmax, sigmay, sigmaz are traceless (see ... )
@assert trace(sigmax) == zero(eltype(sigmax))
@assert trace(sigmaz) == zero(eltype(sigmaz))

and so on.

@acroy
Copy link
Contributor

acroy commented Jun 8, 2015

Apart from the comment on the tests, I think this looks good.

@amitjamadagni
Copy link
Contributor Author

@acroy edits done. If this is fine, I will squash the commits ?

# Being defined both for vectors and dual vectors
# Related Ref : https://github.com/JuliaLang/julia/issues/11064
@assert dot(qv,qv) == dot(qv',qv')
@assert dot(sigmax, sigmay) == trace(sigmaz)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line also needs an explanation ...

@amitjamadagni
Copy link
Contributor Author

@acroy done!

@acroy
Copy link
Contributor

acroy commented Jun 8, 2015

Good. Please squash the commits and then we can merge I would say.

@acroy
Copy link
Contributor

acroy commented Jun 8, 2015

Sorry. I just noticed that you squashed already :-)

@amitjamadagni
Copy link
Contributor Author

@acroy can we merge this ?

@acroy
Copy link
Contributor

acroy commented Jun 16, 2015

Basically yes. I was just thinking if we should generalize dot to allow for two AbstractQuVectors (and giving an error in the mixed case)?

@amitjamadagni
Copy link
Contributor Author

@acroy I have tried creating a common dot for AbstractQuVector.

@acroy
Copy link
Contributor

acroy commented Jun 16, 2015

I see, but what I meant was the following

dot{B<:OrthonormalBasis}(vec1::AbstractQuVector{B}, vec2::AbstractQuVector{B}) = ...
dot{B<:OrthonormalBasis}(vec1::DualVector{B}, vec2::DualVector{B}) = ...
dot{B<:OrthonormalBasis}(vec1::DualVector{B}, vec2::AbstractQuVector{B}) = error("Inner product of a dual vector and a vector is not supported.")
dot{B<:OrthonormalBasis}(vec1::AbstractQuVector{B}, vec2::DualVector{B}) = error("Inner product of a dual vector and a vector is not supported.")

and maybe similar for AbstractQuMatrix.

@amitjamadagni
Copy link
Contributor Author

@acroy the latest commit covers the cases, please do let me know if I am missing something here.

@acroy
Copy link
Contributor

acroy commented Jun 16, 2015

You are checking if the element types of the two vectors are the same, while I simply want to prevent a DualVector and an AbstractQuVector as parameters.

@amitjamadagni
Copy link
Contributor Author

Sorry my bad I understand what I did here. So what would be the best way out, the initial version or the latest version ?

@acroy
Copy link
Contributor

acroy commented Jun 16, 2015

Either you revert it to your original version and we sort it out later or you just take the code I posted above and replace the ... with the code you provided originally.

@amitjamadagni
Copy link
Contributor Author

Would be good if we compare the types of vectors i.e., typeof(vec1) == typeof(vec2) which would then generalize to comparing QuArray and CTranspose ?

@acroy
Copy link
Contributor

acroy commented Jun 16, 2015

You don't need to compare the types. dot{B<:OrthonormalBasis}(vec1::AbstractQuVector{B}, vec2::AbstractQuVector{B}) actually applies to all vectors (including dual vectors). Now we have to provide more specific versions to exclude the cases with mixed parameters. All the work will be done by the compiler.

@amitjamadagni
Copy link
Contributor Author

@acroy a review would be helpful.

@acroy
Copy link
Contributor

acroy commented Jun 29, 2015

@amitjamadagni : Could you please squash and rebase?

@amitjamadagni amitjamadagni reopened this Jun 29, 2015
@amitjamadagni
Copy link
Contributor Author

@acroy done !

@acroy
Copy link
Contributor

acroy commented Jun 29, 2015

@amitjamadagni : Thanks!

acroy added a commit that referenced this pull request Jun 29, 2015
Dot product for AbstractQuVectors and AbstractQuMatrix.
@acroy acroy merged commit e38e0cc into JuliaAttic:master Jun 29, 2015
@amitjamadagni amitjamadagni deleted the dot branch July 3, 2015 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants