Beispiel #1
0
def compute_parity_eigenstates(
    state1: numpy.ndarray,
    state2: numpy.ndarray,
) -> Tuple[numpy.ndarray, numpy.ndarray]:
    opr = compute_parity_operator(state1, state2)
    evals, evecs = diagonalize_1b_operator(opr, 2)
    return evals, numpy.array(evecs)
Beispiel #2
0
        def action_write_wave_function(targets: List[str]):
            with h5py.File(self.path_matrix, "r") as fptr:
                matrix = fptr["matrix"][:, :]

            energies, spfs = diagonalize_1b_operator(matrix, -1)

            indices = numpy.nonzero(
                (energies > self.threshold) if self.above_threshold else
                (energies < self.threshold), )[0]
            m = indices.max() - indices.min() + 1
            if self.max_number > 0:
                m = min(self.max_number, m)
            self.logger.info("use m = %d spfs", m)
            self.logger.info("spf indices: %d to %d", indices.min(),
                             indices.min() + m)
            spfs = spfs[indices.min():indices.min() + m]
            spfs_arr = numpy.array(spfs)
            energies = energies[indices.min():indices.min() + m]

            with h5py.File(targets[1], "w") as fptr:
                dset = fptr.create_dataset(
                    "energies",
                    (len(energies), ),
                    dtype=numpy.float64,
                )
                dset[:] = energies

                dset = fptr.create_dataset(
                    "spfs",
                    spfs_arr.shape,
                    dtype=numpy.complex128,
                )
                dset[:, :] = spfs_arr

            grid_points = matrix.shape[0]
            tape = (
                -10,
                self.number_of_particles,
                +1,
                len(energies),
                -1,
                1,
                1,
                0,
                grid_points,
                -2,
            )
            self.number_state = numpy.zeros(len(energies), dtype=numpy.int64)
            self.number_state[0] = self.number_of_particles
            wfn = WaveFunction(tape=tape)
            wfn.init_coef_sing_spec_B(
                self.number_state,
                spfs,
                1e-15,
                1e-15,
                full_spf=True,
            )

            save_wave_function(self.path, wfn)
Beispiel #3
0
        def action_compute(targets):
            del targets

            with h5py.File(self.path_matrix, "r") as fp:
                matrix = fp["matrix"][:, :]

            energies, spfs = diagonalize_1b_operator(matrix, self.num_spfs)
            spfs_arr = numpy.array(spfs)
            write_spectrum(self.path, energies, spfs_arr)
Beispiel #4
0
        def action_write_wave_function(targets: List[str]):
            del targets

            all_spfs = []
            for m, path_matrix, path_basis in zip(
                    self.number_of_spfs,
                    self.path_matrices,
                    self.path_bases,
            ):
                with h5py.File(path_matrix, "r") as fptr:
                    matrix = fptr["matrix"][:, :]

                energies, spfs = diagonalize_1b_operator(matrix, m)
                spfs_arr = numpy.array(spfs)
                all_spfs += spfs

                with h5py.File(path_basis, "w") as fptr:
                    dset = fptr.create_dataset("energies", (m, ),
                                               dtype=numpy.float64)
                    dset[:] = energies

                    dset = fptr.create_dataset(
                        "spfs",
                        spfs_arr.shape,
                        dtype=numpy.complex128,
                    )
                    dset[:, :] = spfs_arr[-1]

            grid_points = matrix.shape[0]
            tape = (
                -10,
                self.number_of_particles,
                +1,
                sum(self.number_of_spfs),
                -1,
                1,
                1,
                0,
                grid_points,
                -2,
            )
            wfn = WaveFunction(tape=tape)
            wfn.init_coef_sing_spec_B(
                self.number_state,
                all_spfs,
                1e-15,
                1e-15,
                full_spf=True,
            )

            save_wave_function(self.path, wfn)
Beispiel #5
0
def main():
    # parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("path",
                        help="path to the one body operator matrix file")
    parser.add_argument(
        "--min",
        dest="min_",
        type=int,
        default=0,
        help="minimum index of the eigenstate",
    )
    parser.add_argument(
        "--max",
        dest="max_",
        type=int,
        default=None,
        help="maximum index of the eigenstate",
    )

    args = parser.parse_args()

    # load operator matrix
    with h5py.File(args.path, "r") as fp:
        matrix = fp["matrix"][:, :]
        grid = fp["grid_1"][:]
        weights = fp["weights_1"][:]

    # diagonalize
    energies, spfs = diagonalize_1b_operator(matrix, matrix.shape[0])
    min_ = args.min_
    max_ = args.max_
    if max_ is None:
        max_ = 10

    # create app
    app = QApplication(sys.argv)
    GUI(min_, max_, grid, weights, energies[min_:max_ + 1],
        spfs[min_:max_ + 1])

    # run app
    sys.exit(app.exec_())
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("path", type=Path, help="path to the one-body operator matrix")
    parser.add_argument(
        "index",
        type=int,
        help="index of the eigenfunction to write out",
    )
    parser.add_argument("output", type=Path, help="name of the output file")
    args = parser.parse_args()

    index = args.index

    _, _, matrix = read_one_body_operator_matrix(args.path)
    evals, evecs = diagonalize_1b_operator(matrix, index + 1)

    LOGGER.info("eigenvalue = %f", evals[index])
    with h5py.File(args.output, "w") as fptr:
        fptr.create_dataset(
            "wave_function",
            shape=evecs[index].shape,
            dtype=evecs[index].dtype,
        )[:] = evecs[index]
Beispiel #7
0
        def action_write_wave_function(targets: List[str]) -> Dict[str, Any]:
            with h5py.File(self.path_matrix_A, "r") as fptr:
                matrix_A = fptr["matrix"][:, :]

            with h5py.File(self.path_matrix_B, "r") as fptr:
                matrix_B = fptr["matrix"][:, :]

            energies_A, spfs_A = diagonalize_1b_operator(
                matrix_A, self.num_spfs_A)
            spfs_arr_A = numpy.array(spfs_A)

            energies_B, spfs_B = diagonalize_1b_operator(
                matrix_B, self.num_spfs_B)
            spfs_arr_B = numpy.array(spfs_B)

            with h5py.File(self.path_basis_A, "w") as fptr:
                fptr.create_dataset(
                    "energies",
                    (self.num_spfs_A, ),
                    dtype=numpy.float64,
                )[:] = energies_A
                fptr.create_dataset(
                    "spfs", spfs_arr_A.shape,
                    dtype=numpy.complex128)[:, :, ] = spfs_arr_A

            with h5py.File(self.path_basis_B, "w") as fptr:
                fptr.create_dataset(
                    "energies",
                    (self.num_spfs_B, ),
                    dtype=numpy.float64,
                )[:] = energies_B
                fptr.create_dataset(
                    "spfs", spfs_arr_B.shape,
                    dtype=numpy.complex128)[:, :, ] = spfs_arr_B

            n_A = matrix_A.shape[0]
            n_B = matrix_B.shape[0]
            assert n_A == n_B

            tape = (
                -10,
                2,
                0,
                self.num_sbs_A,
                self.num_sbs_B,
                -1,
                1,
                self.num_particles_A,
                1,
                self.num_spfs_A,
                -1,
                1,
                1,
                0,
                n_A,
                0,
                0,
                -1,
                2,
                self.num_particles_B,
                1,
                self.num_spfs_B,
                -1,
                1,
                1,
                0,
                n_B,
                -2,
            )

            wfn = WaveFunction(tape=tape)
            wfn.init_coef_multi_spec(
                2,
                [self.ns_A, self.ns_B],
                [spfs_A, spfs_B],
                1e-15,
                1e-15,
                full_spf=True,
            )
            save_wave_function(self.path, wfn)
 def diagonalize(
     self,
     number_eigenfunctions: Optional[int] = None,
 ) -> Tuple[numpy.ndarray, numpy.ndarray]:
     evals, evecs = diagonalize_1b_operator(self.get_matrix(), number_eigenfunctions)
     return evals, numpy.array(evecs)