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

Stochastic solver using v5 class interface #2131

Merged
merged 61 commits into from Apr 19, 2023
Merged

Conversation

Ericgig
Copy link
Member

@Ericgig Ericgig commented Mar 21, 2023

Checklist
This rewrite the stochastic solver to use the class interface.

  • smesolve, ssesolve have been rewritten to match other solver with matching class interface SMESolver, SSESolver. The main change is that the options used to be passed as keywords (**kwargs) and are now passed as an options dict.

    • m_ops and dW_factors are properties of the classes, but not available to overwrite through the function interface.
    • The multiples end condition (target_tol, timeout) are added.
    • The solver keyword is now method options, as it is in other solver.
    • The method that was referring the homodyne or heterodyne detection is now the heterodyne keyword. ie before method="heterodyne" now heterodyne=True.
    • The default integration method is now rouchon, instead of taylor1.5. ie the method coming from a physic paper and not a mathematics textbook.
  • The stochastic integration methods have been spitted in smaller chunk instead of the huge classes in _stochastic.pyx. I kept most methods, only skipping the taylor order 2.0 method. The python interface is kept very similar to the Integrator as SIntegrator, the main difference being that set_state and get_state use an extra random number generator with the time and state. The integration methods are usually 5%~10% slower than they where for medium size problems (shape ~100). Most method are computed the same way as before, but the rouchon method no longer use super operator, but keep the density matrix as a matrix and not an oper-ket.

  • The derivative computation for used by the integration method has also been split into multiple functions and made only available for smesolve. For there methods to be valid, the each diffusion contribution must commute. For smesolve, this means that each sc_ops must commute, as documented. For ssesolve, each sc_ops must not only commute, but also commute with other sc_ops's adjoint, this last part being missing from v4's documentation. It also meant that the sc_ops needed to commute with it's own adjoint when using heterodyne detection...

  • ssepdpsolve, smepdpsolve, photocurrent_mesolve, photocurrent_sesolve removed. They are all less efficient variants of mcsolve. mcsolve already include the photocurrent in the output.

  • general_stochastic, removed. It is a mostly generic stochastic equation solver. The user to define their equations to integrate, but the results are forced into Results with expectation values and dims checks, making it hard to use.

@coveralls
Copy link

coveralls commented Mar 21, 2023

Coverage Status

Coverage: 77.683% (+2.07%) from 75.613% when pulling 8cee3c2 on Ericgig:stochastic.v5 into f31688d on qutip:master.

@Ericgig
Copy link
Member Author

Ericgig commented Mar 23, 2023

I changed back the default integration method to taylor1.5 for smesolve and platen for ssesolve.
The property that the state stay physical of rouchon is actually problematic since even when the dt is too large, the state still look fine but is totally wrong. Whereas other methods will get negative eigenvalues or Nan.

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

The original giant .pyx from QuTiP 4 was way too big. I think more reorganizing could be done, but let's leave that for the future. For now let's just finish cleaning this up and merge it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the idea is to use mcsolve instead of the stochastic solver for photocurrent work now, I think we should add a small section to the mcsolve guide that covers how to do that.

doc/guide/dynamics/dynamics-stochastic.rst Show resolved Hide resolved
qutip/solver/__init__.py Outdated Show resolved Hide resolved
qutip/solver/sode/_sode.pyx Outdated Show resolved Hide resolved
qutip/solver/sode/_sode.pyx Outdated Show resolved Hide resolved
qutip/tests/solver/test_stochastic.py Outdated Show resolved Hide resolved
qutip/tests/solver/test_stochastic.py Outdated Show resolved Hide resolved
qutip/tests/solver/test_stochastic.py Outdated Show resolved Hide resolved
qutip/tests/solver/test_stochastic.py Outdated Show resolved Hide resolved
qutip/tests/solver/test_stochastic.py Show resolved Hide resolved
@Ericgig
Copy link
Member Author

Ericgig commented Apr 19, 2023

@hodgestar
I added the information about photocurrent in the mcsolve documentation and answered the comment.
Is there anything else missing?

@hodgestar
Copy link
Contributor

@Ericgig Thank you for adding the mcsolve photocurrent docs. I just left one more question about the qutip.solver.sode import.

@Ericgig Ericgig merged commit fc9c580 into qutip:master Apr 19, 2023
11 of 12 checks passed
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.

None yet

3 participants