Beispiel #1
0
    def __init__(
        self,
        forbidden_densities,
        system_eval_count,
        cost_eval_step=1,
        cost_multiplier=1.,
    ):
        """
        See class fields for arguments not listed here.

        Arguemnts:
        cost_eval_step
        forbidden_densities
        system_eval_count
        """
        super().__init__(cost_multiplier=cost_multiplier)
        density_count = forbidden_densities.shape[0]
        cost_evaluation_count, _ = np.divmod(system_eval_count - 1,
                                             cost_eval_step)
        self.cost_normalization_constant = cost_evaluation_count * density_count
        self.forbidden_densities_count = np.array([
            forbidden_densities_.shape[0]
            for forbidden_densities_ in forbidden_densities
        ])
        self.forbidden_densities_dagger = conjugate_transpose(
            forbidden_densities)
        self.hilbert_size = forbidden_densities.shape[3]
Beispiel #2
0
def get_lindbladian(
    densities,
    dissipators=None,
    hamiltonian=None,
    operators=None,
):
    """
    Compute the action of the lindblad equation on a single (set of)
    density matrix (matrices). This implementation uses the definiton:
    https://en.wikipedia.org/wiki/Lindbladian.

    Args:
    densities :: ndarray - the probability density matrices
    dissipators :: ndarray - the lindblad dissipators
    hamiltonian :: ndarray
    operators :: ndarray - the lindblad operators
    operation_policy :: qoc.OperationPolicy - how computations should be
        performed, e.g. CPU, GPU, sparse, etc.

    Returns:
    lindbladian :: ndarray - the lindbladian operator acting on the densities
    """
    if hamiltonian is not None:
        lindbladian = -1j * commutator(
            hamiltonian,
            densities,
        )
    else:
        lindbladian = 0

    if dissipators is not None and operators is not None:
        operators_dagger = conjugate_transpose(operators, )
        operators_product = matmuls(
            operators_dagger,
            operators,
        )
        for i, operator in enumerate(operators):
            dissipator = dissipators[i]
            operator_dagger = operators_dagger[i]
            operator_product = operators_product[i]
            lindbladian = (lindbladian + (dissipator * (matmuls(
                operator,
                densities,
                operator_dagger,
            ) - 0.5 * matmuls(
                operator_product,
                densities,
            ) - 0.5 * matmuls(
                densities,
                operator_product,
            ))))
        #ENDFOR
    #ENDIF
    return lindbladian
Beispiel #3
0
def plot_state_population(file_path, 
                          dpi=1000,
                          marker_style="o",
                          save_file_path=None,
                          save_index=None,
                          show=False,
                          state_index=0,
                          time_unit="ns",
                          title=None):
    """
    Plot the evolution of the population levels for a state.

    Arguments:
    file_path :: str - the full path to the H5 file

    dpi
    marker_style
    save_file_path
    show
    state_index
    time_unit

    Returns: None
    """
    # Open file; extract data.
    file_lock_path = "{}.lock".format(file_path)
    try:
        with FileLock(file_lock_path):
            with h5py.File(file_path, "r") as file_:
                evolution_time = file_["evolution_time"][()]
                program_type = file_["program_type"][()]
                system_eval_count = file_["system_eval_count"][()]
                if program_type == ProgramType.EVOLVE.value:
                    intermediate_states = file_["intermediate_states"][:, state_index, :, :]
                else:
                    # If no save index was specified, choose the index that achieved
                    # the lowest error.
                    if save_index is None:
                        save_index = np.argmin(file_["error"])
                    intermediate_states = file_["intermediate_states"][save_index, :, state_index, :, :]
            #ENDWITH
        #ENDWITH
    except Timeout:
        print("Could not access the specified file.")
        return
    file_name = os.path.splitext(ntpath.basename(file_path))[0]
    if title is None:
        title = file_name
    hilbert_size = intermediate_states.shape[-2]
    system_eval_times = np.linspace(0, evolution_time, system_eval_count)

    # Compile data.
    intermediate_densities = np.matmul(intermediate_states, conjugate_transpose(intermediate_states))
    population_data = list()
    for i in range(hilbert_size):
        population_data_ = np.real(intermediate_densities[:, i, i])
        population_data.append(population_data_)

    # Create labels and extra content.
    patches = list()
    labels = list()
    for i in range(hilbert_size):
        label = "{}".format(i)
        labels.append(label)
        color = get_color(i)
        patches.append(mpatches.Patch(label=label, color=color))
    #ENDFOR

    # Plot the data.
    plt.figure()
    plt.suptitle(title)
    plt.figlegend(handles=patches, labels=labels, loc="upper right",
                  framealpha=0.5)
    plt.xlabel("Time ({})".format(time_unit))
    plt.ylabel("Population")
    for i in range(hilbert_size):
        color = get_color(i)
        plt.plot(system_eval_times, population_data[i], marker_style,
                 color=color, ms=2, alpha=0.9)

    # Export.
    if save_file_path is not None:
        plt.savefig(save_file_path, dpi=dpi)

    if show:
        plt.show()