Skip to content

Commit

Permalink
The examples were broken by the last update. I fixed them, and added …
Browse files Browse the repository at this point in the history
…reference output to premade matrix
  • Loading branch information
william-dawson committed Aug 1, 2017
1 parent 29ef4d2 commit d18d3b9
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 42 deletions.
21 changes: 11 additions & 10 deletions Examples/GraphTheory/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
PROGRAM GraphTheory
USE DataTypesModule, ONLY : ntreal
USE DistributedSparseMatrixModule, ONLY : &
& WriteToMatrixMarket, DistributedSparseMatrix, ConstructEmpty, &
& WriteToMatrixMarket, DistributedSparseMatrix_t, &
& ConstructEmptyDistributedSparseMatrix, &
& FillFromTripletList, DestructDistributedSparseMatrix, &
& CopyDistributedSparseMatrix, FillDistributedIdentity, &
& IncrementDistributedSparseMatrix
USE InverseSolversModule, ONLY : Invert
USE IterativeSolversModule, ONLY : IterativeSolverParameters
USE IterativeSolversModule, ONLY : IterativeSolverParameters_t
USE ProcessGridModule, ONLY : ConstructProcessGrid
USE TripletListModule, ONLY : TripletList_t, ConstructTripletList, &
& SetTripletAt, AppendToTripletList
Expand All @@ -22,15 +23,15 @@ PROGRAM GraphTheory
CHARACTER(len=80) :: output_file
REAL(ntreal) :: threshold
REAL(ntreal) :: attenuation
TYPE(IterativeSolverParameters) :: solver_parameters
TYPE(IterativeSolverParameters_t) :: solver_parameters
!! MPI Variables
INTEGER :: rank
INTEGER :: total_processors
INTEGER :: ierr
INTEGER :: provided
!! Matrices
TYPE(DistributedSparseMatrix) :: NetworkMat
TYPE(DistributedSparseMatrix) :: ResultMat
TYPE(DistributedSparseMatrix_t) :: NetworkMat
TYPE(DistributedSparseMatrix_t) :: ResultMat
!! Local Part of the Matrix
INTEGER :: number_of_local_nodes
INTEGER, DIMENSION(:), ALLOCATABLE :: local_nodes
Expand Down Expand Up @@ -75,14 +76,14 @@ PROGRAM GraphTheory
& process_slices)

!! Set Up The Solver Parameters.
solver_parameters = IterativeSolverParameters( &
solver_parameters = IterativeSolverParameters_t( &
& be_verbose_in = .TRUE., threshold_in = threshold)

CALL DivideUpWork

!! Fill The Matrix
CALL ConstructEmpty(NetworkMat, number_of_nodes)
CALL ConstructEmpty(ResultMat, number_of_nodes)
CALL ConstructEmptyDistributedSparseMatrix(NetworkMat, number_of_nodes)
CALL ConstructEmptyDistributedSparseMatrix(ResultMat, number_of_nodes)
CALL FillMatrix

!! Solve
Expand Down Expand Up @@ -196,10 +197,10 @@ SUBROUTINE FillMatrix
END SUBROUTINE FillMatrix
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SUBROUTINE SolveMatrix
TYPE(DistributedSparseMatrix) :: ResMat
TYPE(DistributedSparseMatrix_t) :: ResMat

!! Compute attenuation*Identity - Matrix
CALL ConstructEmpty(ResMat, number_of_nodes)
CALL ConstructEmptyDistributedSparseMatrix(ResMat, number_of_nodes)
CALL FillDistributedIdentity(ResMat)
CALL IncrementDistributedSparseMatrix(NetworkMat, ResMat, &
& alpha_in=REAL(-1.0*attenuation,NTREAL))
Expand Down
2 changes: 1 addition & 1 deletion Examples/HydrogenAtom/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are three main points to this example.

In a somewhat unconventional manner, we will do all this using the real space
basis set. Of course, it is normally neither practical nor useful to compute
the density matrix in real space, however the equations in real space are
the full density matrix in real space, however the equations in real space are
very simple and will allow us to demonstrate the concepts.

We need to solve the following equation:
Expand Down
26 changes: 14 additions & 12 deletions Examples/HydrogenAtom/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ PROGRAM HydrogenAtom
USE DataTypesModule, ONLY : ntreal
USE DensityMatrixSolversModule, ONLY : TRS2
USE DistributedSparseMatrixModule, ONLY : &
& WriteToMatrixMarket, DistributedSparseMatrix, ConstructEmpty, &
& WriteToMatrixMarket, DistributedSparseMatrix_t, &
& ConstructEmptyDistributedSparseMatrix, &
& FillFromTripletList, CopyDistributedSparseMatrix, &
& IncrementDistributedSparseMatrix, FillDistributedIdentity
USE IterativeSolversModule, ONLY : IterativeSolverParameters
USE IterativeSolversModule, ONLY : IterativeSolverParameters_t
USE PermutationModule, ONLY : Permutation_t, ConstructRandomPermutation
USE ProcessGridModule, ONLY : ConstructProcessGrid
USE SquareRootSolversModule, ONLY : InverseSquareRoot
Expand All @@ -21,7 +22,7 @@ PROGRAM HydrogenAtom
CHARACTER(len=80) :: density_file_out
INTEGER :: process_rows, process_columns, process_slices
REAL(ntreal) :: threshold, convergence_threshold
TYPE(IterativeSolverParameters) :: solver_parameters
TYPE(IterativeSolverParameters_t) :: solver_parameters
!! MPI Variables
INTEGER :: rank
INTEGER :: total_processors
Expand All @@ -36,11 +37,11 @@ PROGRAM HydrogenAtom
REAL(ntreal) :: grid_spacing
REAL(ntreal), DIMENSION(:), ALLOCATABLE :: x_values
!! Matrices
TYPE(DistributedSparseMatrix) :: KineticEnergy
TYPE(DistributedSparseMatrix) :: PotentialEnergy
TYPE(DistributedSparseMatrix) :: Hamiltonian
TYPE(DistributedSparseMatrix) :: Identity
TYPE(DistributedSparseMatrix) :: Density
TYPE(DistributedSparseMatrix_t) :: KineticEnergy
TYPE(DistributedSparseMatrix_t) :: PotentialEnergy
TYPE(DistributedSparseMatrix_t) :: Hamiltonian
TYPE(DistributedSparseMatrix_t) :: Identity
TYPE(DistributedSparseMatrix_t) :: Density
!! Temporary Variables
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
Expand Down Expand Up @@ -78,7 +79,7 @@ PROGRAM HydrogenAtom
& process_slices)

!! Set Up The Solver Parameters.
solver_parameters = IterativeSolverParameters( be_verbose_in=.TRUE., &
solver_parameters = IterativeSolverParameters_t( be_verbose_in=.TRUE., &
& converge_diff_in=convergence_threshold, threshold_in=threshold)

!! Divide The Work Amongst Processors.
Expand All @@ -88,19 +89,20 @@ PROGRAM HydrogenAtom
CALL ConstructLinearSpace()

!! Construct The Kinetic Energy Operator.
CALL ConstructEmpty(KineticEnergy, grid_points)
CALL ConstructEmptyDistributedSparseMatrix(KineticEnergy, grid_points)
CALL FillKineticEnergy()

!! Construct The Potential Energy Operator.
CALL ConstructEmpty(PotentialEnergy, grid_points)
CALL ConstructEmptyDistributedSparseMatrix(PotentialEnergy, grid_points)
CALL FillPotentialEnergy()

!! Construct The Full Hamiltonian.
CALL CopyDistributedSparseMatrix(KineticEnergy, Hamiltonian)
CALL IncrementDistributedSparseMatrix(PotentialEnergy, Hamiltonian)

!! Overlap Matrix is just the identity.
CALL ConstructEmpty(Identity,Hamiltonian%actual_matrix_dimension)
CALL ConstructEmptyDistributedSparseMatrix(Identity, &
& Hamiltonian%actual_matrix_dimension)
CALL FillDistributedIdentity(Identity)

!! Call the solver routine.
Expand Down
4 changes: 2 additions & 2 deletions Examples/HydrogenAtom/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
# Call the solver routine.
chemical_potential = 0
Density = nt.DistributedSparseMatrix(grid_points)
nt.DensityMatrixSolvers.TRS2(Hamiltonian, Identity, 2,
Density, chemical_potential, solver_parameters)
chemical_potential = nt.DensityMatrixSolvers.TRS2(Hamiltonian, Identity, 2,
Density, solver_parameters)

# Print the density matrix to file.
Density.WriteToMatrixMarket(density_file_out)
2 changes: 1 addition & 1 deletion Examples/HydrogenAtom/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import numpy

# A function that reads in matrix market-esque files produced by the library.
# A function that reads in matrix market files produced by the library.
# @param file_name file to read.
def ReadMM(file_name):
matrix = numpy.zeros((0, 0))
Expand Down
10 changes: 5 additions & 5 deletions Examples/OverlapMatrix/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ PROGRAM OverlapExample
!! Parameters
INTEGER :: process_rows, process_columns, process_slices
REAL(ntreal) :: threshold, convergence_threshold
TYPE(IterativeSolverParameters) :: solver_parameters
TYPE(IterativeSolverParameters_t) :: solver_parameters
INTEGER :: basis_functions
!! Matrices
TYPE(DistributedSparseMatrix) :: Overlap, ISQOverlap
TYPE(DistributedSparseMatrix_t) :: Overlap, ISQOverlap
TYPE(Permutation_t) :: permutation
!! Triplet List
TYPE(TripletList_t) :: triplet_list
Expand Down Expand Up @@ -79,8 +79,8 @@ PROGRAM OverlapExample
end_column = start_column + local_columns - 1

!! Build The Empty Matrices
CALL ConstructEmpty(Overlap, basis_functions)
CALL ConstructEmpty(ISQOverlap, basis_functions)
CALL ConstructEmptyDistributedSparseMatrix(Overlap, basis_functions)
CALL ConstructEmptyDistributedSparseMatrix(ISQOverlap, basis_functions)

!! Compute The Overlap Matrix
CALL StartTimer("Construct Triplet List")
Expand All @@ -105,7 +105,7 @@ PROGRAM OverlapExample
!! Set Up The Solver Parameters.
CALL ConstructRandomPermutation(permutation, &
& Overlap%logical_matrix_dimension)
solver_parameters = IterativeSolverParameters(&
solver_parameters = IterativeSolverParameters_t(&
& converge_diff_in=convergence_threshold, threshold_in=threshold, &
& BalancePermutation_in=permutation, be_verbose_in=.TRUE.)

Expand Down
2 changes: 1 addition & 1 deletion Examples/OverlapMatrix/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy
from matplotlib.colors import LogNorm

# A function that reads in matrix market-esque files produced by the library.
# A function that reads in matrix market files produced by the library.
# @param file_name file to read.
def ReadMM(file_name):
matrix = numpy.zeros((0, 0))
Expand Down
40 changes: 40 additions & 0 deletions Examples/PremadeMatrix/Density-Reference.mtx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
%%MatrixMarket matrix coordinate real general
%
7 7 37
1 1 1.0549095967421220
2 1 -0.23302213379033082
3 1 3.7646419335116699E-002
4 1 3.7646419335116685E-002
6 1 -7.5642046773935134E-003
7 1 -7.5642046773937563E-003
1 2 -0.23302213783309644
2 2 1.0292641102917328
3 2 -0.20982918266288592
4 2 -0.20982918266288578
6 2 -4.3117326895678362E-002
7 2 -4.3117326895676926E-002
1 3 3.7646421361998791E-002
2 3 -0.20982921225444917
3 3 0.46883722812203843
4 3 6.8501651086330564E-002
6 3 0.37466965007376707
7 3 -3.1414239305686278E-002
1 4 3.7646421361998764E-002
2 4 -0.20982921225444895
3 4 6.8501651086330509E-002
4 4 0.46883722812204076
6 4 -3.1414239305686306E-002
7 4 0.37466965007376629
5 5 1.0000000000000000
1 6 -7.5642029235768070E-003
2 6 -4.3117329307985383E-002
3 6 0.37466966035658766
4 6 -3.1414332242094133E-002
6 6 0.32525138744266346
7 6 -8.6663457475723252E-002
1 7 -7.5642029235770195E-003
2 7 -4.3117329307984009E-002
3 7 -3.1414332242094126E-002
4 7 0.37466966035658689
6 7 -8.6663457475723182E-002
7 7 0.32525138744266113
3 changes: 3 additions & 0 deletions Examples/PremadeMatrix/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ computed by these routines.
It is possible to write out a matrix either to either a text or binary format.
Writing to text is slower, but is portable across systems. Writing to binary
should probably only be used to store intermediate results.

The output file can be compared to Density-Reference.mtx to verify its
correctness.
14 changes: 7 additions & 7 deletions Examples/PremadeMatrix/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ PROGRAM PremadeMatrixProgram
USE DataTypesModule, ONLY : ntreal
USE DensityMatrixSolversModule, ONLY : TRS2
USE DistributedSparseMatrixModule, ONLY : ConstructFromMatrixMarket, &
& WriteToMatrixMarket, DistributedSparseMatrix
USE IterativeSolversModule, ONLY : IterativeSolverParameters
& WriteToMatrixMarket, DistributedSparseMatrix_t
USE IterativeSolversModule, ONLY : IterativeSolverParameters_t
USE LoggingModule
USE PermutationModule, ONLY : Permutation_t, ConstructRandomPermutation
USE ProcessGridModule, ONLY : ConstructProcessGrid, IsRoot
Expand All @@ -19,12 +19,12 @@ PROGRAM PremadeMatrixProgram
INTEGER :: process_rows, process_columns, process_slices
REAL(ntreal) :: threshold, convergence_threshold
INTEGER :: number_of_electrons
TYPE(IterativeSolverParameters) :: solver_parameters
TYPE(IterativeSolverParameters_t) :: solver_parameters
TYPE(Permutation_t) :: permutation
!! Matrices
TYPE(DistributedSparseMatrix) :: Hamiltonian, Overlap
TYPE(DistributedSparseMatrix) :: ISQOverlap
TYPE(DistributedSparseMatrix) :: Density
TYPE(DistributedSparseMatrix_t) :: Hamiltonian, Overlap
TYPE(DistributedSparseMatrix_t) :: ISQOverlap
TYPE(DistributedSparseMatrix_t) :: Density
!! Temporary Variables
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
Expand Down Expand Up @@ -88,7 +88,7 @@ PROGRAM PremadeMatrixProgram
!! Set Up The Solver Parameters.
CALL ConstructRandomPermutation(permutation, &
& Hamiltonian%logical_matrix_dimension)
solver_parameters = IterativeSolverParameters(&
solver_parameters = IterativeSolverParameters_t(&
& converge_diff_in=convergence_threshold, threshold_in=threshold, &
& BalancePermutation_in=permutation, be_verbose_in=.TRUE.)

Expand Down
5 changes: 3 additions & 2 deletions Examples/PremadeMatrix/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
# Call the solver routines.
nt.SquareRootSolvers.InverseSquareRoot(
Overlap, ISQOverlap, solver_parameters)
nt.DensityMatrixSolvers.TRS2(Hamiltonian, ISQOverlap, number_of_electrons,
Density, chemical_potential, solver_parameters)
chemical_potential = nt.DensityMatrixSolvers.TRS2(Hamiltonian, ISQOverlap,
number_of_electrons,
Density, solver_parameters)

# Print the density matrix to file.
Density.WriteToMatrixMarket(density_file_out)
3 changes: 2 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Getting Start With Examples
--------------------------------------------------------------------------------
In the examples directory, there are a number of different example programs that
use NTPoly. You can check the ReadMe.md file in each example directory to
learn how to build and run each example.
learn how to build and run each example. The simplest example is PremadeMatrix,
which includes sample output you can compare to.

Feature Outline
--------------------------------------------------------------------------------
Expand Down

0 comments on commit d18d3b9

Please sign in to comment.