Skip to content

Commit

Permalink
Merge pull request #27 from frankwswang/dev
Browse files Browse the repository at this point in the history
Version 0.2.0 updates finishing up.
  • Loading branch information
frankwswang authored Oct 26, 2021
2 parents d4699ff + 0745c94 commit 620a8f6
Show file tree
Hide file tree
Showing 27 changed files with 1,153 additions and 616 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Quiqbox"
uuid = "7cb8c394-fae1-4ab9-92f2-30189d7746cd"
version = "0.1.2"
version = "0.2.0"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ runHF(bs, nuc, coords)
```julia
pars = uniqueParams!(bs, filterMapping=true)

optimizeParams!(bs, pars[1:4], nuc, coords)
optimizeParams!(bs, pars[end-1:end], nuc, coords)
```

# Documentation
Expand Down
21 changes: 5 additions & 16 deletions docs/src/basis.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ The data structure formularized by Quiqbox in each step, namely the level of dat
| level | objective | product examples | abstract type | type instances |
| :---: | :---: | :---: | :---: | :---: |
| 4 | basis set | Array of basis functions (with reusable integrals) | `Array`, `GTBasis` | `Array{<:BasisFunc, 1}`...|
| 3 | basis functions | single or linear combination of Gaussian functions | `FloatingGTBasisFuncs` | `BasisFunc{:S, 1}`, `BasisFuncs{:P, 3, 3}`...|
| 3 | basis functions | single or linear combination of Gaussian functions | `FloatingGTBasisFuncs` | `BasisFunc{0, 1}`, `BasisFuncs{1, 3, 3}`...|
| 2 | Gaussian functions | (primitive) Gaussian functions | `AbstractGaussFunc` | `GaussFunc`|
| 1 | a pool of parameters | center coordinates, function coefficients | `ParamBox` | `ParamBox{:xpn, Float64}`... |
| 1 | a pool of parameters | center coordinates, function coefficients | `ParamBox` | `ParamBox`... |


Depending on how much control the user wants to have over each step, Quiqbox provides several [methods](https://docs.julialang.org/en/v1/manual/methods/) of related functions to leave the user with the freedom to balance between efficiency and customizability.
Expand Down Expand Up @@ -209,23 +209,12 @@ pb1 = gf4.xpn
pb1.map
```

The `map` field of a `ParamBox` stores a `RefValue{<:Function}`, referencing the `Function` that maps the actual stored value to another value through math operations (``R \to R``). The output value can be access through syntax `()`. In default the variable is mapped to itself:
The `map` field of a `ParamBox` stores a `Function`, referencing the `Function` that can be defined as a mapping of the actual stored data to another output data (``R \to R``). The output value can be access through syntax `()`. In default the variable is mapped to itself:
```@repl 2
pb1[] == pb1()
```

Since `ParamBox` is a `mutable struct` you can redefine your own mapping `Functions` for the parameters; thus gain another layer of control over the basis set parameters:
You can get a clearer view of the mapping relations in a `ParamBox` using `getVarDict`
```@repl 2
squareXpn(x) = x^2
pb1.map = Ref(squareXpn)
pb1[] = 3
pb1()
```

You can get a clearer view of the mapping relations in a `ParamBox` using `getVar`
```@repl 2
getVar(pb1, includeMapping=true)
getVarDict(pb1)
```
74 changes: 55 additions & 19 deletions docs/src/coreFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,64 @@ Exponent
Contraction
```

```@docs
inValOf
```

```@docs
outValOf
```

```@docs
inSymOf
```

```@docs
outSymOf
```

```@docs
dataOf
```

```@docs
mapOf
```

```@docs
outValCopy
```

```@docs
inVarCopy
```

```@docs
enableDiff!
```

```@docs
disableDiff!
```

```@docs
isDiffParam
```

```@docs
toggleDiff!
```

```@docs
genBasisFunc
```

```@docs
centerOf
sortBasisFuncs
```

```@doc
GTBasis(basis::Vector{<:Quiqbox.AbstractGTBasisFuncs})
```@docs
centerOf
```

```@doc
Expand Down Expand Up @@ -57,7 +105,7 @@ getParams
```

```@doc
dataCopy
copyBasis
```

```@docs
Expand All @@ -69,25 +117,20 @@ getVar
```

```@docs
getVars
getVarDict
```

```@docs
expressionOf
```


```@docs
GridBox(nGridPerEdge::Int, spacing::Real=10, centerCoord::Vector{<:Real}=[0.0,0.0,0.0];
canDiff::Bool=true, index::Int=0)
```

```@docs
makeCenter
```

```@docs
gridCoords(gb::GridBox)
gridCoords
```


Expand All @@ -99,12 +142,6 @@ runHF
runHFcore
```


```@docs
Molecule(basis::Vector{<:Quiqbox.FloatingGTBasisFuncs}, nuc::Vector{String},
nucCoords::Vector{<:AbstractArray}, HFfVars::Quiqbox.HFfinalVars)
```

```@docs
getMolOrbitals
```
Expand Down Expand Up @@ -168,8 +205,7 @@ eeInteractions
```

```@docs
Quiqbox.eeInteractionsCore(BSet::Vector{<:Quiqbox.AbstractGTBasisFuncs};
outputUniqueIndices::Bool=false)
Quiqbox.eeInteractionsCore
```

```@docs
Expand Down
6 changes: 5 additions & 1 deletion docs/src/coreType.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Core Types

```@docs
ParamBox{V, T}
ParamBox{V, VI, T}
```

```@docs
Expand All @@ -16,6 +16,10 @@ BasisFunc{S, GN}
BasisFuncs{S, GN, ON}
```

```@docs
Quiqbox.BasisFuncMix{BN, GN}
```

```@docs
GTBasis{N, BT}
```
Expand Down
6 changes: 3 additions & 3 deletions docs/src/optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ unique parameters that can also be optimized later:
pars = uniqueParams!(bs, filterMapping=true)
```

As expected, there are indeed only 3 unique tunable parameters despite the basis set already has 8 basis functions. (note that keyword argument `filterMapping` in `uniqueParams!` is set to `true` because we want the function to only return independent parameters) However, if we take a step further, we can remove ``d`` since each basis function here is just a single Gaussian function, which means the contraction coefficient won't affect the optimization results. Thus, input the intent parameters (along with other necessary arguments) into the Quiqbox function [`optimizeParams!`](@ref) and we can sit and wait for the optimization iterations to complete.
As expected, there are indeed only 3 unique tunable parameters despite the basis set already has 8 basis functions. (note that keyword argument `filterMapping` in `uniqueParams!` is set to `true` because we want the function to only return independent parameters) However, if we take a step further, we can remove ``d`` since each basis function here is just a "unique" Gaussian function. Thus, input the intent parameters (along with other necessary arguments) into the Quiqbox function [`optimizeParams!`](@ref) and we can sit and wait for the optimization iterations to complete.
```@repl 4
parsPartial = [pars[1], pars[3]]
parsPartial = [pars[1], pars[4]]
optimizeParams!(bs, parsPartial, nuc, nucCoords, maxSteps=20);
Es, pars, grads = optimizeParams!(bs, parsPartial, nuc, nucCoords, maxSteps=20);
```

After the optimization, you can check the basis set and we can see the parameters inside of it is also changed. This is because the `!` in the function names indicates that `optimizeParams!` is [a function that modifies its arguments](https://docs.julialang.org/en/v1/manual/style-guide/#bang-convention).
Expand Down
4 changes: 2 additions & 2 deletions examples/Jmol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ prefix = "Example"
for (nuc, nucCoords, molName, iMol) in zip(mols, molCoords, molNames, 1:length(mols)),
(bfCoord, bsName) in zip(bfCoords[iMol:end], bsNames[iMol:end]),
bf in bfs

flag = (bfCoord == nucCoords)
if flag
nucConfig = [(bf, i) for i in nuc]
Expand All @@ -32,7 +32,7 @@ for (nuc, nucCoords, molName, iMol) in zip(mols, molCoords, molNames, 1:length(m
bs = genBasisFunc.(bfCoord, bf) |> flatten
bsName = "-Float"*bsName
end

# Number of spin-orbitals must not be smaller than numbers of electrons.
fVars = try runHF(bs, nuc, nucCoords; printInfo=false) catch; continue end

Expand Down
4 changes: 2 additions & 2 deletions examples/OptimizeParams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ bs = genBasisFunc.(grid.box, Ref([gf1]))

pars = uniqueParams!(bs, filterMapping=true)

parsPartial = [pars[1], pars[3]]
parsPartial = [pars[1], pars[4]]

optimizeParams!(bs, parsPartial, nuc, nucCoords, maxSteps=20)
Es, pars, grads = optimizeParams!(bs, parsPartial, nuc, nucCoords, maxSteps=20)

# # You can also use more advanced optimizers from other packages.
# using Flux # First do `Pkg.add("Flux")` if you haven't installed the package.
Expand Down
3 changes: 3 additions & 0 deletions src/AbstractTypes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
abstract type QuiqboxContainer <: Any end


abstract type ParameterizedFunction <: Function end


abstract type QuiqboxVariableBox <: QuiqboxContainer end

abstract type QuiqboxParameter{ParameterT, ContainerT} <: QuiqboxVariableBox end
Expand Down
Loading

0 comments on commit 620a8f6

Please sign in to comment.