propagator fails to dimension check for composite system
See original GitHub issueHi, I report a strange behavior of propagator
method.
propagator
with collapse operator fails to dimension validation on composite system.
At first, single system works correctly.
import qutip as qt
H = qt.sigmaz()
c_ops = [np.sqrt(1) * qt.sigmam()]
tlist = np.linspace(0, 10, 201)
rho0 = qt.ket2dm(qt.basis(2, 0)).unit()
# mesolve
rho_f = qt.mesolve(H, rho0, tlist, c_ops=c_ops).states[-1]
# using propagator
F = qt.propagator(H, tlist, c_op_list=c_ops)[-1]
rho_f_prop = qt.vector_to_operator(F * qt.operator_to_vector(rho0))
rho_f.overlap(rho_f_prop)
The output is
0.9999092149599982
(I’m not sure why this is not 1. I guess it’s limited by the numerical precision.)
However, same code on composite system fails.
The differences are only H
, c_ops
, and rho0
, using qt.tensor(*, qt.qeye(2))
H = qt.tensor(qt.sigmaz(), qt.qeye(2))
c_ops = [np.sqrt(1) * qt.tensor(qt.sigmam(), qt.qeye(2))]
tlist = np.linspace(0, 10, 201)
rho0 = qt.ket2dm(qt.tensor(qt.basis(2, 0), qt.basis(2, 0))).unit()
# mesolve
rho_f = qt.mesolve(H, rho0, tlist, c_ops=c_ops).states[-1]
# using propagator
F = qt.propagator(H, tlist, c_op_list=c_ops)[-1]
rho_f_prop = qt.vector_to_operator(F * qt.operator_to_vector(rho0))
rho_f.overlap(rho_f_prop)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-551bcc27bcfa> in <module>
8
9 # using propagator
---> 10 F = qt.propagator(H, tlist, c_op_list=c_ops)[-1]
11 rho_f_prop = qt.vector_to_operator(F * qt.operator_to_vector(rho0))
12
c:\users\mizuno\research\py38\lib\site-packages\qutip\propagator.py in propagator(H, t, c_op_list, args, options, unitary_mode, parallel, progress_bar, _safe_mode, **kwargs)
239 rho0 = Qobj(sp.csr_matrix(([1], ([row_idx], [col_idx])),
240 shape=(N, N), dtype=complex))
--> 241 output = mesolve(H, rho0, tlist, c_op_list, [], args, options,
242 _safe_mode=False)
243 for k, t in enumerate(tlist):
c:\users\mizuno\research\py38\lib\site-packages\qutip\mesolve.py in mesolve(H, rho0, tlist, c_ops, e_ops, args, options, progress_bar, _safe_mode)
263 raise Exception("Invalid H type")
264
--> 265 func, ode_args = ss.makefunc(ss, rho0, args, e_ops, options)
266
267 if _safe_mode:
c:\users\mizuno\research\py38\lib\site-packages\qutip\mesolve.py in _qobjevo_set(HS, rho0, args, e_ops, opt)
349 # Should be caught earlier in mesolve.
350 raise ValueError("rho0 must be a ket, density matrix or superoperator")
--> 351 _test_liouvillian_dimensions(H_td.cte.dims, rho0.dims)
352 return func, ()
353
c:\users\mizuno\research\py38\lib\site-packages\qutip\mesolve.py in _test_liouvillian_dimensions(L_dims, rho_dims)
330 raise ValueError("Liouvillian had nonsquare dims: " + str(L_dims))
331 if not ((L_dims[1] == rho_dims) or (L_dims[1] == rho_dims[0])):
--> 332 raise ValueError("".join([
333 "incompatible Liouvillian and state dimensions: ",
334 str(L_dims), " and ", str(rho_dims),
ValueError: incompatible Liouvillian and state dimensions: [[[2, 2], [2, 2]], [[2, 2], [2, 2]]] and [[4], [4]]
My environment is following.
QuTiP: Quantum Toolbox in Python
================================
Copyright (c) QuTiP team 2011 and later.
Current admin team: Alexander Pitchford, Nathan Shammah, Shahnawaz Ahmed, Neill Lambert, Eric Giguère, Boxi Li, Jake Lishman and Simon Cross.
Board members: Daniel Burgarth, Robert Johansson, Anton F. Kockum, Franco Nori and Will Zeng.
Original developers: R. J. Johansson & P. D. Nation.
Previous lead developers: Chris Granade & A. Grimsmo.
Currently developed through wide collaboration. See https://github.com/qutip for details.
QuTiP Version: 4.6.2
Numpy Version: 1.19.5
Scipy Version: 1.6.2
Cython Version: 0.29.22
Matplotlib Version: 3.4.1
Python Version: 3.8.9
Number of CPUs: 16
BLAS Info: OPENBLAS
OPENMP Installed: False
INTEL MKL Ext: False
Platform Info: Windows (AMD64)
Installation path: c:\users\mizuno\research\py38\lib\site-packages\qutip
================================================================================
Please cite QuTiP in your publication.
================================================================================
For your convenience a bibtex reference can be easily generated using `qutip.cite()`
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
A method to determine propagation direction of compressive ...
It was found that the size, distribution and position of the splits could be used to determine the direction of crack propagation.
Read more >Inference by Belief Propagation in Composite Systems
Inference by Belief Propagation in Composite Systems ... the system size, accommodate variable and measurement uncertainties and readily provide confidence.
Read more >Failure Propagation Controlling for Frangible Composite ...
The complexity in predicting the damage initiation and failure propagation controlling in composite structures is challenging. The focus of this paper is to ......
Read more >Guide to Uncertainty Propagation and Error Analysis
This allows you to determine whether or not such an error is important. To a rough approximation, you can get a sense of...
Read more >Failure propagation in composite laminated plate (with ...
Flat and singly curved composite plates have been modelled in ANSYS 15.0. The governing parameter includes: (i) size, shape and eccentricity of hole,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, this feels like a bug in
propagator
- I bet at some point we doqeye(L.shape[0])
instead ofqeye(L.dims[0])
. There’s sometimes quite a bit of that in older code - it used to slip through because we weren’t super strict about dimension handling, so in certain cases (like this one), we’d accept bad dimensions.I might try and have a look tonight (UK time), if I have time - I’ve wanted to break up the large
propagator
monolith into smaller components for quite a while.About numerical precision: if you want to try increasing the precision of the integrators, try passing
options=qutip.Options(nsteps=1_000_000, atol=1e-12, rtol=1e-10)
topropagator
.atol
andrtol
are absolute and relative tolerances respectively, andnsteps
is the number of subdivisions the integrator is allowed to take (if it reaches its tolerance goals, it won’t take all of them). You’ll find thatatol
andrtol
will have only a loose relation to the tolerance of your fidelity value, because there’s a lot of floating-point operations between those points in which the errors compound, and there’s a hard limit on the tolerances the integrator can achieve, so you might not be able to get a perfect answer. The fidelity calculation involves finding the square root of a density operator, so that’s another large possible source of error.About times: if you only care about the state at the last time, setting
tlist = np.linspace(0, x, 201)
is quite inefficient. Instead, settlist = [0, x]
, and then passoptions=qutip.Options(nsteps=<very very big integer>)
. It’s more efficient because it doesn’t need to achieve tolerance goals and construct/storeQobj
instances at every intermediate timestep.Temporary workaround: this is very temporary, and generally a bad idea in QuTiP, but you can “flatten” all your operators into a single space for now, while we implement a fix. To do that:
Thanks for the fix! Just running into this on 4.6.2, working on ‘4.7.0.dev0+b71625e’ 😃