Skip to content
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

Make Complex observables evaluable #13

Merged

Conversation

hz-xiaxz
Copy link
Contributor

related to (#12 )
After some searching, I found this package BinningAnalysis.jl implements likewise jackknife resampling method from QMC results, and he follows the julia convention to calculate var(x) = var(real(x))+var(imag(x)). I think this is reasonable enough then.

In this PR I made the type of error be alway :<Real and fixed some issue in reading the complex observable from the json result file.

Copy link
Owner

@lukas-weber lukas-weber left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

Apart from the comments on the code, could you also run JuliaFormatter.jl on it and sign your commit?

src/evaluable.jl Outdated
end
error = sqrt.((sample_count - 1) .* error ./ sample_count)
error = real.(sqrt.((sample_count - 1) .* error ./ sample_count))
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe error in line 40 should already be created as a real array, then we do not need to convert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. I implement error = real.(zero(complete_eval)) here, is there better way?

src/evaluable.jl Outdated Show resolved Hide resolved
@@ -16,9 +16,20 @@ function measurement_from_obs(obsname, obs)
end

mean = obs["mean"]
if mean isa Dict
Copy link
Owner

Choose a reason for hiding this comment

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

Can we integrate all of this into one dispatch of sanitize?

Like

sanitize(m::AbstractDict, e) = isnothing(e) ? missing : complex(m["re"] ± e, m["im"])

This should also already catch the vector case because sanitize is called with a dot below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems good but I got the error track

ERROR: ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reserved
Stacktrace:
  [1] broadcastable(::Dict{String, Any})
    @ Base.Broadcast ./broadcast.jl:744
  [2] broadcasted(::Carlo.ResultTools.var"#sanitize#11", ::Dict{String, Any}, ::Float64)
    @ Base.Broadcast ./broadcast.jl:1344
  [3] measurement_from_obs(obsname::String, obs::Dict{String, Any})
    @ Carlo.ResultTools ~/.julia/dev/Carlo/src/resulttools/ResultTools.jl:23
  [4] (::Carlo.ResultTools.var"#3#5"{Dict{String, Any}})(obsname::String)
    @ Carlo.ResultTools ./essentials.jl:0
  [5] iterate
    @ ./generator.jl:47 [inlined]
  [6] _all(f::Base.var"#384#386", itr::Base.Generator{Vector{String}, Carlo.ResultTools.var"#3#5"{Dict{String, Any}}}, ::Colon)
    @ Base ./reduce.jl:1297
  [7] all
    @ ./reduce.jl:1283 [inlined]
  [8] Dict(kv::Base.Generator{Vector{String}, Carlo.ResultTools.var"#3#5"{Dict{String, Any}}})
    @ Base ./dict.jl:111
  [9] dataframe(result_json::String)
    @ Carlo.ResultTools ~/.julia/dev/Carlo/src/resulttools/ResultTools.jl:35

The broadcast will have an issue when m is a single dict. So I guess we should deal it first.

@hz-xiaxz
Copy link
Contributor Author

Thanks for the review. As I'm new to Github, how can I sign for my commit?

@lukas-weber lukas-weber merged commit 824998e into lukas-weber:main Jul 29, 2024
2 of 7 checks passed
@lukas-weber
Copy link
Owner

https://docs.github.com/authentication/managing-commit-signature-verification/about-commit-signature-verification

But, since signing existing commits can be a bit tricky, we can skip signatures for this one. :)

I also noticed CI is failing for nightly, but it seems unrelated to your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants