-
- Notifications
You must be signed in to change notification settings - Fork 359
Split-op in Haskell #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split-op in Haskell #357
Conversation
jiegillet commented Aug 19, 2018
- Added split-op
- Added energy in quantum systems
- Added gnuplot script to render the wave function outputs
Added energy calculations. Added a gnuplotscript to visualize wavefunctions.
It doesn't look like anyone is stepping up to review this one. Mind if I do it? |
I'd be honored. Feel free to ask me to walk you through things you don't understand. |
I almost certainly will. Thanks! |
I'll assign you real quick for a better overview in the PR list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not really qualified to review haskell syntax, but you always have great code so I trust you there...
I mainly just asked a few stupid questions to learn bit more. No changes requested in the code.
calculateEnergy :: Double -> Vector -> Vector -> Vector -> Double | ||
calculateEnergy dx kin pot wfc = (* dx) . sum . map realPart $ elems total | ||
where | ||
total = liftArray2 (+) kineticE potentialE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does liftArray2
do in this case? I assume it's some sort of 2D map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, kineticE
potentialE
are both vectors that I want to add term by term, so I'm mapping (+)
into them.
@@ -0,0 +1,14 @@ | |||
import Data.Array.CArray | |||
import Data.Complex | |||
import Math.FFT (dft, idft) -- Binding to fftw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this require special build instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installing the Haskell package is nothing special if I recall correctly, installing fftw3
is more involved, but you'd need to do that anyway.
@@ -0,0 +1,107 @@ | |||
{-# LANGUAGE FlexibleContexts #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It lets line 71 work. I don't fully understand why or how, basically the compiler told me to use this. It's not like I'm doing anything fancy.
| ||
makeParameters :: Double -> Int -> Double -> Int -> Bool -> Parameters | ||
makeParameters xmax res dt timesteps imTime = | ||
let fi = fromIntegral |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fi = fromIntegral
? I'm just giving fromIntegral
a shorter name so I can fit things on a single line. Maybe it's a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was asking what fromIntegral
does. Sorry that was unclear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It casts an integer into another numerical value. In Haskell you can't add an Int
to a Double
or even an Integer
, which can be a pain point :)
where | ||
splitop op = op {wfc = wfc' op} | ||
wfc' = norm . (rStep .*) . idft . (kStep .*) . dft . (rStep .*) . wfc | ||
a .* b = liftArray2 (*) a b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am having trouble reading this line because I am bad at haskell. Could you just say what it is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a .* b = liftArray2 (*) a b
? It's just defining a shorter notation for liftArray2 (*) a b
. It makes line 69 much easier to understand.
But since I'm defining the same thing somewhere else, I'll refactor this definitions out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I got confused because of functional notation and not really following what liftArray2
was. This is clear now. Thanks!
values = map (map (show . realPart) . elems) [x param, density, v] | ||
in intercalate "\n" $ map (intercalate "\t") $ transpose values | ||
export (i, f) = writeFile ("output" ++ pad (show i) ++ ".dat") f | ||
pad n = replicate (5 - length n) '0' ++ n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replicate
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replicate n x
outputs a list with n
identical x
. I'm using it to pad the integer with zeros.
@@ -0,0 +1,24 @@ | |||
# use like: gnuplot -e "folder='/path/to/output/directory'" plot_output.plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. Should we put it in a more common directory and call it from other languages too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in fact I've placed it in contents/split-operator_method
. I can place it in a dedicated folder if you like.
* adding changes to update all julia code to V1.0 * adding more points to graham.jl
* initial commit * Programming done * Minor style changes. Merge ready * hopefully fix PR * minor edits for code readability * indexed main procedure * fix typo
* implementation and documentary * minor code clean up * fixing git again... * Delete monte_carlo_pi.f90 again fortan file automagically appears. * code style changes * code style * indexed main procedure
* Refactored .*, .+ and normalization operators * Got rid of {-# LANGUAGE FlexibleContexts #-} by giving explicit signature to normalize * Small cosmetic changes
Whoops, seems I messed up my commit. Please hold. |
So, to be clear: You are happy with the code, we just need to make sure it can merge in to the master branch? |
Yes, unless you have more comments after I answered your questions. Actually I have one last question, are you happy with the gnuplot next to the |
yeah |
Should be OK now. I moved the gnuplot script and I've cleaned up the code a bit, refactored some lines and got rid of FlexibleContexts. |
Hey @jiegillet are the line numbers in the |
Whoops. Should be good now |
Cool, I'll build it locally. I am still a bit worried about all the "new" files that seem to be from previous commits, but I checked those locally and it seemed fine? |
It happened before. Turned out OK. All "changes" that show in the other files have already been applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good.