Hamiltonian

class Hamiltonian(N)[source]

Bases: object

Contains methods for initializing, creating and manipulating Hamiltonian matrices.

Parameters:N (int) – number of nodes to initialize the Hamiltonian object with.
Returns:: creates an unallocated PETSc matrix on communicator petsc4py.PETSc.COMM_WORLD. This is accessed via the attribute Hamiltonian.mat.
Return type:petsc4py.PETSc.Mat
Returns:: an associated EigSolver object is also created at Hamiltonian.EigSolver.
Return type:EigSolver

Method Summary

Hamiltonian.Emax(**kwargs) Returns the maximum Eigenvalue of the matrix.
Hamiltonian.Emin(**kwargs) Returns the minimum Eigenvalue of the matrix.
Hamiltonian.createLine([d, amp]) Create a 1 particle infinite line Hamiltonian.
Hamiltonian.createLine2P([d, amp, interaction]) Create a 2 particle infinite line Hamiltonian.
Hamiltonian.createLine3P([d, amp, interaction]) Create a 3 particle infinite line Hamiltonian.
Hamiltonian.destroy() Destroys all associated PETSc matrices.
Hamiltonian.importAdj(filename, filetype[, ...]) Create a Hamiltonian from an imported adjacency matrix.
Hamiltonian.importAdjToH(filename, filetype) Create a Hamiltonian from an imported adjacency matrix.
Hamiltonian.reinitialize() Destroy and reinitialize the PETSc matrix Hamiltonian.mat.

Method Details

Hamiltonian.Emax(**kwargs)[source]

Returns the maximum Eigenvalue of the matrix.

Example

>>> Emax = Hamiltonian.Emax()
Hamiltonian.Emin(**kwargs)[source]

Returns the minimum Eigenvalue of the matrix.

Example

>>> Emin = Hamiltonian.Emin()
Hamiltonian.createLine(d=[0], amp=[0.0])[source]

Create a 1 particle infinite line Hamiltonian.

Parameters:
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • interaction (float) – the amplitude of interaction between the walkers when located on the same vertex.
Returns:

: Hamiltonian.mat, the Hamiltonian matrix.

Return type:

petsc4py.PETSc.Mat()

Important

  • The length of amp and d must be identical.

Fortran interface

This function calls the Fortran function hamiltonian_p1_line().

Hamiltonian.createLine2P(d=[0], amp=[0.0], interaction=0.0)[source]

Create a 2 particle infinite line Hamiltonian.

Parameters:
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • interaction (float) – the amplitude of interaction between the walkers when located on the same vertex.
Returns:

: Hamiltonian.mat, the Hamiltonian matrix.

Return type:

petsc4py.PETSc.Mat()

Important

  • The length of amp and d must be identical.

Fortran interface

This function calls the Fortran function hamiltonian_p2_line().

Hamiltonian.createLine3P(d=[0], amp=[0.0], interaction=0.0)[source]

Create a 3 particle infinite line Hamiltonian.

Parameters:
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • interaction (float) – the amplitude of interaction between the walkers when located on the same vertex.
Returns:

: Hamiltonian.mat, the Hamiltonian matrix.

Return type:

petsc4py.PETSc.Mat()

Important

  • The length of amp and d must be identical.

Fortran interface

This function calls the Fortran function hamiltonian_p3_line().

Hamiltonian.destroy()[source]

Destroys all associated PETSc matrices.

Hamiltonian.importAdj(filename, filetype, d=[0], amp=[0.0], layout='spring', delimiter=None)[source]

Create a Hamiltonian from an imported adjacency matrix.

Parameters:
  • filename (str) – path to the file containing the adjacency matrix of the graph
  • filetype (str) –

    the filetype of the imported adjacency matrix.

    • 'txt' - an \(N\times N\) dense 2D array in text format.
    • 'bin' - an \(N\times N\) PETSc binary matrix.
  • d (array of ints) – an array containing integers indicating the nodes where diagonal defects are to be placed (e.g. d=[0,1,4]).
  • amp (array of floats) – an array containing floats indicating the diagonal defect amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).
  • layout (str) –

    the format to store the position of the nodes.

    • spring (default) - spring layout.
    • circle - nodes are arranged in a circle.
    • spectral - nodes are laid out according to the spectrum of the graph.
    • random - nodes are arranged in a random pattern.
  • delimiter (str) – this is passed to numpy.genfromtxt in the case of strange delimiters in an imported txt file.
Returns:

:this allocates and builds a Hamiltonian matrix at Hamiltonian.mat.

Return type:

petsc4py.PETSc.Mat()

Returns:

: the original adjacency matrix is also stored as a PETSc matrix at Hamiltonian.Adj.

Return type:

petsc4py.PETSc.Mat()

Important

  • The number of nodes in the imported adjacency matrix must match the number of nodes the Hamiltonian object is initialized with.
  • The length of amp and d must be identical.

Note

  • This function calls Python functions located at pyCTQW.MPI.io, and is somewhat slower than importAdjToH(), but with the advantage of a more flexible text file importer.
  • For the ability to generate 2 or 3 particle Hamiltonians with or without interactions, please see importAdjToH().
Hamiltonian.importAdjToH(filename, filetype, d=[0.0], amp=[0.0], p='1', layout='spring', delimiter=None, interaction=0.0, bosonic=False)[source]

Create a Hamiltonian from an imported adjacency matrix.

Args:

filename (str): path to the file containing the adjacency matrix of the graph

filetype (str): the filetype of the imported adjacency matrix.

  • 'txt' - an \(N\times N\) dense 2D array in text format.
  • 'bin' - an \(N\times N\) PETSc binary matrix.
d (array of ints): an array containing integers indicating the nodes
where diagonal defects are to be placed (e.g. d=[0,1,4]).
amp (array of floats): an array containing floats indicating the diagonal defect
amplitudes corresponding to each element in d (e.g. amp=[0.5,-1,4.2]).

p (str) : ('1'``|‘2’|‘3’``) - specify whether to create a 1, 2 or 3 particle Hamiltonian.

layout (str): the format to store the position of the nodes.

  • spring (default) - spring layout.
  • circle - nodes are arranged in a circle.
  • spectral - nodes are laid out according to the spectrum of the graph.
  • random - nodes are arranged in a random pattern.
delimiter (str): this is passed to numpy.genfromtxt
in the case of strange delimiters in an imported txt file.

interaction (float): the amplitude of interaction between the walkers when located on the same vertex.

bosonic (bool): if true, a Bosonic Hamiltonian is generated.

Returns:
: * Hamiltonian.mat (petsc4py.PETSc.Mat) - the Hamiltonian matrix.
  • Hamiltonian.Adj (petsc4py.PETSc.Mat) - the adjacency matrix stored as a PETSc matrix.
  • Hamiltonian.nodePos (array) - the \((x,y)\) coordinates of the graph vertices.
  • Hamiltonian.lineX (array) - the \(x\) coordinates of the edges connecting graph vertices.
  • Hamiltonian.lineY (array) - the \(y\) coordinates of the edges connecting graph vertices.

Important

  • The number of nodes in the imported adjacency matrix must match the number of nodes the Hamiltonian object is initialized with.
  • The length of amp and d must be identical.

Fortran interface

This function calls the Fortran function importadjtoh() and is faster than importAdjToH(), but with a ‘pickier’ text file importer.

Hamiltonian.reinitialize()[source]

Destroy and reinitialize the PETSc matrix Hamiltonian.mat.