qutip / qutip-qip

The QuTiP quantum information processing package
https://qutip-qip.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
114 stars 63 forks source link

QobjEvo object has no attribute 'tlist' #243

Closed paba92 closed 2 weeks ago

paba92 commented 1 month ago

Bug Description

Generating an QobjEvo object has no attribute tlist. This results in an error for the example code here. A minimal example for reproducing this error is provided.

Code to Reproduce the Bug

import numpy as np
from qutip import QobjEvo, sigmaz
coeff = np.array([0.0, 1.5, 1.0, 0.0])
tlist = [0.0, 0.1, 0.3, 0.4]
qu = QobjEvo([sigmaz(), coeff], tlist=tlist)
qu.tlist

Code Output

AttributeError: 'qutip.core.cy.qobjevo.QobjEvo' object has no attribute 'tlist'. Did you mean: 'to_list'?

Expected Behaviour

[0.0, 0.1, 0.3, 0.4]

Your Environment

QuTiP Version:      5.0.3.post1
Numpy Version:      1.26.4
Scipy Version:      1.14.0
Cython Version:     3.0.10
Matplotlib Version: 3.9.1
Python Version:     3.12.4
Number of CPUs:     8
BLAS Info:          Generic
INTEL MKL Ext:      False
Platform Info:      Linux (x86_64)
Installation path:  */lib/python3.12/site-packages/qutip

Additional Context

No response

Ericgig commented 1 month ago

QobjEvo.tlist was removed and qutip-qip code was updated to match the change, but it seems qutip-qip's documentation is out of sync...

BoxiLi commented 2 weeks ago

Thanks @paba92 for the issue. Yes it is outdated. the correct script is

import numpy as np
from qutip import sigmaz, sigmay
from qutip_qip.device import Processor
from qutip_qip.noise import RandomNoise

# add control Hamiltonians
processor = Processor(1)
processor.add_control(sigmaz(), targets=0, label="sz")

# define pulse coefficients and tlist for all pulses
processor.set_coeffs({"sz": np.array([0.3, 0.5, 0. ])})
processor.set_tlist(np.array([0., np.pi/2., 2*np.pi/2, 3*np.pi/2]))

# define noise, loc and scale are keyword arguments for np.random.normal
gaussnoise = RandomNoise(
            dt=0.01, rand_gen=np.random.normal, loc=0.00, scale=0.02)
processor.add_noise(gaussnoise)

# Plot the ideal pulse
fig1, axis1 = processor.plot_pulses(
    title="Original control amplitude", figsize=(5,3),
    use_control_latex=False)

# Plot the noisy pulse
qobjevo, _ = processor.get_qobjevo(noisy=True)
fig2, axis2 = processor.plot_pulses(
    title="Noisy control amplitude", figsize=(5,3),
    use_control_latex=False)
tlist = np.linspace(0., processor.get_full_tlist()[-1], 300)
noisy_coeff = [qobjevo(t)[0, 0] for t in tlist]
axis2[0].step(tlist, noisy_coeff)

Will make a fix soon.