Python Forum
Cannot plot without high machine precision problems on small numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot plot without high machine precision problems on small numbers
#1
Photo 
Hi, I am trying to plot the solution of the Lindblad equation, for a Bell state probability density matrix, however I get non-zero entropy at t=0, which has to be zero.

All calculations show that the y-axis value of the plot should be 0 at t=0, but I still get a plot that starts at 0.032.

I think this is caused by numerical precision problems, of very very small numbers, such as 1.11022302e-16 . Why this is nonzero is strange it self, however, how can I round-up this to give zero ?

The code is attached



Thanks

Attached Files

Thumbnail(s)
   

.py   entropyPSI.py (Size: 4.06 KB / Downloads: 4)
Reply
#2
I think the problem is here:
# Evolve the systems and compute entropy at each time step
for t in times:
    rho1 = lindblad_step(rho1, dt, gamma, H, C)
    entropy_values_psi_plus.append(entropy(rho1))
    
    rho2 = lindblad_step(rho2, dt, gamma, H, C)
    entropy_values_psi_minus.append(entropy(rho2))
This does not give rho1 or rho2 values for t == 0. The first rho1/2 value is for t == dt.

There's also a problem here:
# Time evolution
time_steps = 1000
dt = 0.01
times = np.linspace(0, time_steps * dt, time_steps)
I think you want times to be [0, 0.01, 0.02, ... 9.99, 10.0], but what you get is [0, 0.01001001, 0.02002002...9.97997998, 9.98998999, 10.0].

It is difficult to use a for loop because of how you compute rho. I might write your loop like this:
dt = 0.01
rho1 = rho_psi_plus
rho2 = rho_psi_minus
times = []
entropy_values_psi_plus = []
entropy_values_psi_minus = []
for t in range(1001):
    times.append(t * dt)
    entropy_values_psi_plus.append(entropy(rho1))
    entropy_values_psi_minus.append(entropy(rho2))
    rho1 = lindblad_step(rho1, dt, gamma, H, C)
    rho2 = lindblad_step(rho2, dt, gamma, H, C)
Or this:
dt = 0.01
rho1 = rho_psi_plus
rho2 = rho_psi_minus
times = np.linspace(0.0, 10.0, 1001)
entropy_values_psi_plus = []
entropy_values_psi_minus = []
for _ in times:
    entropy_values_psi_plus.append(entropy(rho1))
    entropy_values_psi_minus.append(entropy(rho2))
    rho1 = lindblad_step(rho1, dt, gamma, H, C)
    rho2 = lindblad_step(rho2, dt, gamma, H, C)
The important thing is if you want to plot a point at time == 0, you need to compute a point for time == 0 instead of starting at time = dt.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  precision & recall gracenz 1 1,561 Sep-21-2022, 02:14 AM
Last Post: jefsummers
  Time class with picosecond precision marcocod 5 4,991 Jul-03-2020, 12:12 AM
Last Post: Larz60+
  F-score, Precision, and Recall values Hani 3 3,481 May-09-2020, 08:16 AM
Last Post: ThomasL
  problem to add precision, recall and f1-score edys 7 5,453 May-28-2019, 04:48 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020