
import numpy as np

def comm(A, B):
    '''Calculate the commutator of two matrices

    '''
    return A @ B - B @ A

def D(c, rho):
    '''Calculate the application of the diffusion superoperator D[c] to rho

    '''
    c_dag = c.conjugate().T
    return c @ rho @ c_dag - (c_dag @ c @ rho + rho @ c_dag @ c) / 2

def euler_integrate(rho_0, rho_dot_fn, times):
    rhos = [rho_0]
    dts = np.diff(times)
    for dt, t in zip(dts, times[:-1]):
        rho_dot = rho_dot_fn(rhos[-1], t)
        rhos.append(rhos[-1] + dt * rho_dot)
    return np.array(rhos)


import numpy as np

def comm(A, B):
    '''Calculate the commutator of two matrices

    '''
    return A @ B - B @ A

def D(c, rho):
    '''Calculate the application of the diffusion superoperator D[c] to rho

    '''
    c_dag = c.conjugate().T
    return c @ rho @ c_dag - (c_dag @ c @ rho + rho @ c_dag @ c) / 2

def euler_integrate(rho_0, rho_dot_fn, times):
    rhos = [rho_0]
    dts = np.diff(times)
    for dt, t in zip(dts, times[:-1]):
        rho_dot = rho_dot_fn(rhos[-1], t)
        rhos.append(rhos[-1] + dt * rho_dot)
    return rhos

Change euler integrator to return list, not array
Change euler integrator to return list, not array

The state of the system is a heterogeneous data type for some
applications, so the array isn't appropriate.

  
  import numpy as np
  
  def comm(A, B):
      '''Calculate the commutator of two matrices
  
      '''
      return A @ B - B @ A
  
  def D(c, rho):
      '''Calculate the application of the diffusion superoperator D[c] to rho
  
      '''
      c_dag = c.conjugate().T
      return c @ rho @ c_dag - (c_dag @ c @ rho + rho @ c_dag @ c) / 2
  
  def euler_integrate(rho_0, rho_dot_fn, times):
      rhos = [rho_0]
      dts = np.diff(times)
      for dt, t in zip(dts, times[:-1]):
          rho_dot = rho_dot_fn(rhos[-1], t)
          rhos.append(rhos[-1] + dt * rho_dot)
-     return np.array(rhos)
+     return rhos
  
Change euler integrator to return list, not array
## Code Before:

import numpy as np

def comm(A, B):
    '''Calculate the commutator of two matrices

    '''
    return A @ B - B @ A

def D(c, rho):
    '''Calculate the application of the diffusion superoperator D[c] to rho

    '''
    c_dag = c.conjugate().T
    return c @ rho @ c_dag - (c_dag @ c @ rho + rho @ c_dag @ c) / 2

def euler_integrate(rho_0, rho_dot_fn, times):
    rhos = [rho_0]
    dts = np.diff(times)
    for dt, t in zip(dts, times[:-1]):
        rho_dot = rho_dot_fn(rhos[-1], t)
        rhos.append(rhos[-1] + dt * rho_dot)
    return np.array(rhos)

## Instruction:
Change euler integrator to return list, not array
## Code After:

import numpy as np

def comm(A, B):
    '''Calculate the commutator of two matrices

    '''
    return A @ B - B @ A

def D(c, rho):
    '''Calculate the application of the diffusion superoperator D[c] to rho

    '''
    c_dag = c.conjugate().T
    return c @ rho @ c_dag - (c_dag @ c @ rho + rho @ c_dag @ c) / 2

def euler_integrate(rho_0, rho_dot_fn, times):
    rhos = [rho_0]
    dts = np.diff(times)
    for dt, t in zip(dts, times[:-1]):
        rho_dot = rho_dot_fn(rhos[-1], t)
        rhos.append(rhos[-1] + dt * rho_dot)
    return rhos
