Skip to content

Conversation

jiegillet
Copy link
Member

  • Added split-op
  • Added energy in quantum systems
  • Added gnuplot script to render the wave function outputs
@jiegillet jiegillet added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Aug 19, 2018
@leios
Copy link
Member

leios commented Sep 10, 2018

It doesn't look like anyone is stepping up to review this one. Mind if I do it?

@jiegillet
Copy link
Member Author

I'd be honored. Feel free to ask me to walk you through things you don't understand.

@leios
Copy link
Member

leios commented Sep 10, 2018

I almost certainly will. Thanks!

@Butt4cak3
Copy link
Contributor

I'll assign you real quick for a better overview in the PR list.

Copy link
Member

@leios leios left a 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
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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 #-}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replicate?

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

@jiegillet jiegillet Sep 25, 2018

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.

leios and others added 5 commits September 24, 2018 12:59
* 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
@jiegillet
Copy link
Member Author

Whoops, seems I messed up my commit. Please hold.

@leios
Copy link
Member

leios commented Sep 25, 2018

So, to be clear: You are happy with the code, we just need to make sure it can merge in to the master branch?

@jiegillet
Copy link
Member Author

jiegillet commented Sep 25, 2018

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 .md files or should I make a dedicated folder? Maybe contents/split-operator_method/plot or contents/split-operator_method/code/gnuplot

@leios
Copy link
Member

leios commented Sep 25, 2018

yeah contents/split-operator_method/code/gnuplot is preferred here.

@jiegillet
Copy link
Member Author

jiegillet commented Sep 26, 2018

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.

@leios
Copy link
Member

leios commented Sep 26, 2018

Hey @jiegillet are the line numbers in the .md file correct?

@jiegillet
Copy link
Member Author

Whoops. Should be good now

@leios
Copy link
Member

leios commented Sep 28, 2018

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?

@jiegillet
Copy link
Member Author

It happened before. Turned out OK. All "changes" that show in the other files have already been applied.

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good.

@leios leios merged commit 7f7fd3b into algorithm-archivists:master Sep 28, 2018
@jiegillet jiegillet deleted the haskell-split-op branch September 29, 2018 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)

4 participants