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

Attribute functions operating on Qobj #155

Merged
merged 37 commits into from
Jun 8, 2024

Conversation

ytdHuang
Copy link
Member

@ytdHuang ytdHuang commented Jun 3, 2024

close #148

This PR supports most of the attribute functions in Python qutip.Qobj class.

Summary of this PR:

  • add missing @doc raw in front of each docstirings.
  • add missing docstrings for several LinearAlgebra functions
  • always throw DimensionMismatch exception if A.dims != B.dims
  • introduce isherm (same as LinearAlgebra.ishermitian)
  • support generalized LinearAlgebra.dot(i, A, j): returns $\langle i | A | j \rangle$
    • if A is in the type of Operator, i and j need to be Ket
    • if A is in the type of SuperOperator, i and j need to be OperatorKet
  • introduce matrix_element(i, A, j) (same as LinearAlgebra.dot(i, A, j))
  • introduce trans (same as LinearAlgebra.transpose)
  • introduce dag (same as LinearAlgebra.adjoint)
  • introduce unit (same as LinearAlgebra.normalize)
  • allow normalize(A, p) and normalize!(A, p) to normalize the QuantumObject so that p-norm of A equals to unity. Support for the following types of QuantumObject:
    • If A is Ket or Bra, default p = 2
    • If A is Operator, default p = 1
  • introduce expm (same as LinearAlgebra.exp)
  • support LinearAlgebra.sin and LinearAlgebra.cos
  • only support exp, expm, sin, sinm, cos, cosm for Operator and SuperOperator types of QuantumObject as input
  • introduce LinearAlgebra.diag
  • introduce LinearAlgebra.log and logm (same as LinearAlgebra.log)
  • introduce purity: $\textrm{Tr}(\rho^2)$
  • introduce proj: the projector of a Ket or Bra

Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.89%. Comparing base (ce251c5) to head (ea57987).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
+ Coverage   92.68%   92.89%   +0.21%     
==========================================
  Files          26       27       +1     
  Lines        1913     1956      +43     
==========================================
+ Hits         1773     1817      +44     
+ Misses        140      139       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ytdHuang ytdHuang mentioned this pull request Jun 3, 2024
13 tasks
docs/src/api.md Outdated
LinearAlgebra.normalize!
LinearAlgebra.inv
LinearAlgebra.diag
sinm
Copy link
Member

Choose a reason for hiding this comment

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

Can you convert also sinm and cosm to LinearAlgebra.sinandLinearAlgebra.cosand them putsinmandcosm` as synonyms?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh, I didn't notice that there is also matrix sin and cos in LinearAlgebra.
Will implement it right away !

Copy link
Member Author

Choose a reason for hiding this comment

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

This could be more efficient compared to the original way

Copy link
Member

Choose a reason for hiding this comment

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

No I don’t think that it will work with the LinearAlgebra functions, because we have sparse matrices, and (at least at the time) there wasn’t an implementation for such functions. That’s why I implemented the exp function by myself. When SparseArrays will export their exp sin cos functions, we can delete our definition of exp function.

What I mean here is to do the same as the exp case also for sin and cos, and then define sinm and cosm as synonyms.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, just to make sure I understand correctly, you mean:

LinearAlgebra.sin(A::QuantumObject) = (exp(1im * A) - exp(-1im * A)) / 2im
sinm(A::QuantumObject) = sin(A)

docs/src/api.md Outdated
tidyup
tidyup!
get_data
get_coherence
partial_transpose
```

## [Synonyms for Qobj attribute functions](@id doc-API:Synonyms-for-Qobj-attribute-functions)
```@docs
Copy link
Member

Choose a reason for hiding this comment

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

I think that also isherm should be moved here

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, thanks for the reminder

@albertomercurio albertomercurio merged commit 7332577 into qutip:main Jun 8, 2024
14 checks passed
@ytdHuang ytdHuang deleted the dev/qobj-attribute branch June 8, 2024 15:47
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.

Attribute functions operating on Qobj
2 participants