Skip to content

Commit

Permalink
Minor things (#22)
Browse files Browse the repository at this point in the history
* Ignore extra kwargs

* Pretty-printing of multiconfigurational equations

* Bump version
  • Loading branch information
jagot authored Oct 25, 2022
1 parent de16997 commit 151ed12
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EnergyExpressions"
uuid = "f4b57a2e-27c7-11e9-0cb0-edd185b706f6"
authors = ["Stefanos Carlström <[email protected]>"]
version = "0.1.3"
version = "0.1.4"

[deps]
AtomicLevels = "10933b4c-d60f-11e8-1fc6-bd9035a249a1"
Expand Down
2 changes: 1 addition & 1 deletion src/bit_configurations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ function NBodyMatrixElement(bcs::BitConfigurations, op::LinearCombinationOperato
NBodyMatrixElement(terms)
end

function Base.Matrix(bcs::BitConfigurations, rows, op::QuantumOperator, cols; verbosity=0)
function Base.Matrix(bcs::BitConfigurations, rows, op::QuantumOperator, cols; verbosity=0, kwargs...)
m,n = length(rows), length(cols)

I = [Int[] for i in 1:Threads.nthreads()]
Expand Down
21 changes: 21 additions & 0 deletions src/multi_configurational_equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function Base.show(io::IO, oeq::OrbitalEquation)
write(io, "\n")
end

Base.iszero(oeq::OrbitalEquation) = iszero(oeq.equation)

"""
MCEquationSystem(equations, integrals)
Expand All @@ -64,6 +66,25 @@ struct MCEquationSystem
integrals
end

function Base.show(io::IO, mceqs::MCEquationSystem)
neq = length(mceqs.equations)
nnzeq = count(!iszero, mceqs.equations)
nint = length(mceqs.integrals)

write(io, "$(neq)-equation MCEquationSystem, $(nnzeq) non-zero equations, $(nint) common integrals")
end

function Base.show(io::IO, mime::MIME"text/plain", mceqs::MCEquationSystem)
show(io, mceqs)
println(io)
nd = length(digits(length(mceqs.equations)))
for (i,eq) in enumerate(mceqs.equations)
iszero(eq) && continue
printfmt(io, "- {1:>$(nd)d}: ", i)
show(io, mime, eq)
end
end

"""
pushifmissing!(vector, element)
Expand Down
2 changes: 2 additions & 0 deletions test/bit_configurations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -605,5 +605,7 @@ end

@test Matrix(bcs, h, left=1, right=2) == reshape([ome(3, h, 6)*s],1,1)
@test Matrix(bcs, h, left=1, right=1:2) == reshape([ome(1, h, 1) + ome(2, h, 2) + ome(3, h, 3),ome(3, h, 6)*s],1,2)

@test Matrix(bcs, h, left=1, right=2, my_kwarg=1) == reshape([ome(3, h, 6)*s],1,1)
end
end
15 changes: 15 additions & 0 deletions test/multi_configurational_equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,19 @@

@test occursin("[ Info: Deriving equations for $(norb) orbitals\n", err)
end

@testset "Pretty-printing" begin
cfgs = spin_configurations(c"1s 2p")
bcs = BitConfigurations(cfgs)
h = FieldFreeOneBodyHamiltonian()
E = Matrix(bcs, h)
a,b = so"1s₀α",so"2p₀β"
mceqs = diff(E, conj([a,b]))

@test string(mceqs) == "2-equation MCEquationSystem, 2 non-zero equations, 0 common integrals"
test_value_and_output(nothing, "2-equation MCEquationSystem, 2 non-zero equations, 0 common integrals
- 1: $(mceqs.equations[1])- 2: $(mceqs.equations[2])") do
show(stdout, "text/plain", mceqs)
end
end
end

2 comments on commit 151ed12

@jagot
Copy link
Member Author

@jagot jagot commented on 151ed12 Nov 8, 2022

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/71883

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.4 -m "<description of version>" 151ed122bdcb078d2449fdaa023f2b22db0149e9
git push origin v0.1.4

Please sign in to comment.