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

QMC code restructuring #433

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

Atomyka
Copy link
Contributor

@Atomyka Atomyka commented Oct 1, 2022

Streamlining and restructuring QMC code.

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2022

Codecov Report

Merging #433 (d664212) into master (d281f22) will decrease coverage by 0.72%.
The diff coverage is 22.81%.

@@            Coverage Diff             @@
##           master     #433      +/-   ##
==========================================
- Coverage   62.27%   61.55%   -0.73%     
==========================================
  Files          63       79      +16     
  Lines        3632     4789    +1157     
==========================================
+ Hits         2262     2948     +686     
- Misses       1370     1841     +471     
Impacted Files Coverage Δ
lib/BloqadeQMC/src/BloqadeQMC.jl 0.00% <ø> (ø)
lib/BloqadeQMC/src/datastructures/Rydberg.jl 0.00% <0.00%> (ø)
lib/BloqadeQMC/src/datastructures/alias.jl 0.00% <0.00%> (ø)
lib/BloqadeQMC/src/datastructures/hamiltonian.jl 0.00% <0.00%> (ø)
...oqadeQMC/src/datastructures/improved_op_sampler.jl 0.00% <0.00%> (ø)
lib/BloqadeQMC/src/datastructures/operators.jl 0.00% <0.00%> (ø)
...BloqadeQMC/src/datastructures/probabilityvector.jl 0.00% <0.00%> (ø)
lib/BloqadeQMC/src/datastructures/qmc_state.jl 0.00% <0.00%> (ø)
lib/BloqadeQMC/src/ising/TFIM.jl 35.29% <ø> (+16.68%) ⬆️
lib/BloqadeQMC/src/updates/multibranch.jl 0.00% <0.00%> (ø)
... and 32 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@weinbe58
Copy link
Member

weinbe58 commented Oct 1, 2022

Looking good so far! BTW you have access to the QuEraComputing repo for Bloqade so you can push your own branches with name/branch_name

First[st] = v + num_sites
end

@simd for i in 1:num_legs
Copy link
Member

Choose a reason for hiding this comment

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

Can we check if the simd is actually useful here? By measuring the time - simd optimization is not very reliable so it'd be great to check that while developing

end
end

if qmc_state isa BinaryGroundState
Copy link
Member

Choose a reason for hiding this comment

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

I think this if else is an easy abstraction to separate out using multiple dispatch.

#############################################################################


@inline function _map_back_operator_list!(ocount::Int, qmc_state::BinaryQMCState, H::AbstractIsing, d::Diagnostics)
Copy link
Member

Choose a reason for hiding this comment

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

I think we would just remove the beginning underscore from the name.

Comment on lines +281 to +296
in_cluster[leg] = ccount # add the new leg and flip it
push!(current_cluster, leg)
if qmc_state isa BinaryGroundState
lnA += trialstate_weight_change(qmc_state, lsize, Ns, i)
end
a = Associates[leg]

a == 0 && continue
# from this point on, we know we're on a bond op
op = operator_list[op_indices[leg]]
w = getweightindex(H, op) - getoperatortype(H, op)
preflip_bond_type, postflip_bond_type = update_kernel!(qmc_state, H, ccount, leg, a)
lnA += (
getlogweight(H.op_sampler, w + postflip_bond_type)
- getlogweight(H.op_sampler, w + preflip_bond_type)
)
Copy link
Member

Choose a reason for hiding this comment

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

I'd separate this to a function (at least to start with) it's always beneficial to wrap a loop kernel into a function

ocount = _map_back_basis_states!(rng, lsize, qmc_state, H)
_map_back_operator_list!(ocount, qmc_state, H, d)

return lsize
Copy link
Member

Choose a reason for hiding this comment

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

It probably worth thinking if this return value can be a state object - it would be nice the MC iteration can roughly follow an iterator interface in Julia. But this is not a blocking comment.

Copy link
Member

Choose a reason for hiding this comment

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

Also it seems lsize is the same as input here? If I'm not missing something what's the point of returning the same value?


if !(runstats isa NoStats)
fit!(runstats, :diag_update_fails, failures/count)
end
Copy link
Member

Choose a reason for hiding this comment

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

Can we be explicit on what return value is of this function?

resize!(qmc_state.leg_sites, len)
resize!(qmc_state.op_indices, len)
resize!(qmc_state.in_cluster, len)
end
Copy link
Member

Choose a reason for hiding this comment

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

The return value should be the state not the vector

# Now, add the 2M operators to the linked list. Each has either 2 or 4 legs
@inbounds for (n, op) in enumerate(qmc_state.operator_list)
if issiteoperator(H, op)
site = getsite(H, op)
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if we can seperate out the code block for each different operator (site and bond)

@Roger-luo
Copy link
Member

There are some general name conventions are not consistent with what we use in Bloqade. So it would be nice if you could just rename them when you spot them (so we will just check them in the end when the development is almost done). In general, we only use Camel case for types and all other things should be in snake case. And we don't usually use starting underscore to denote private function (unless you really having a hard time figuring out a proper name)

@Atomyka
Copy link
Contributor Author

Atomyka commented Oct 3, 2022

Haven't addressed comments above yet but the ltfim test is running now with restructured update rules :)

@Atomyka Atomyka changed the title QMC code restructuring QMC updates restructuring Oct 4, 2022
@Atomyka Atomyka changed the title QMC updates restructuring QMC code restructuring Oct 4, 2022
@Atomyka
Copy link
Contributor Author

Atomyka commented Oct 4, 2022

Suggestion for overall code structure:

  • datastructures/: the structs ProbabilityAlias and (Improved)OperatorSampler (and hence the hamiltonians) are all built on top of AbstractProbabilityVector. To make this clear, we could have them all in one file. For now, I also added qmc_state. Overall, this folder bundles the files where we need to think about integration with BloqadeExpr.
  • updates/: all QMC update rules
  • lattices/: to be removed since Phil & John have almost finished the necessary upgrades to BloqadeLattices
  • trialstate/: to be removed if we have no intention of combining the QMC ground state simulation with other variational algorithms
  • diagnostics/: we can keep it for now, mainly useful for us but definitely a blackbox for user (tracks cluster sizes, acceptance rates etc.)

The only top-level file left (apart from BloqadeQMC.jl) is still measurements.jl. Here, we need to discuss how many of the functions we really need for Bloqade. Will probably shrink significantly.

@Atomyka
Copy link
Contributor Author

Atomyka commented Oct 4, 2022

Also important: run a Rydberg QMC. Currently, the QMC test uses a LTFIM.

Code should be pretty much the same. And we can use the ED values from exact_diag.jl for comparison.

@Atomyka
Copy link
Contributor Author

Atomyka commented Oct 5, 2022

Note: Expansion order fluctuates in finite-T-case but stays fixed for zero-T.
In the current implementation, full_diagonal_update!() hence does not return anything, while full_diagonal_update_beta!() does return num_ops. This makes calling mc_step!() stlightly different from mc_step_beta!() --> Should we make them the same s.t. the user only has one interface (where she needs to specify beta = finite value or inf)

@Atomyka
Copy link
Contributor Author

Atomyka commented Oct 5, 2022

Also important: run a Rydberg QMC. Currently, the QMC test uses a LTFIM.

Code should be pretty much the same. And we can use the ED values from exact_diag.jl for comparison.

Got started on this in new PR

@Atomyka
Copy link
Contributor Author

Atomyka commented Oct 5, 2022

Note: Expansion order fluctuates in finite-T-case but stays fixed for zero-T. In the current implementation, full_diagonal_update!() hence does not return anything, while full_diagonal_update_beta!() does return num_ops. This makes calling mc_step!() stlightly different from mc_step_beta!() --> Should we make them the same s.t. the user only has one interface (where she needs to specify beta = finite value or inf)

Will leave this unchanged until we get properly started on user interface

@weinbe58
Copy link
Member

@Atomyka Can I close this PR?

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.

4 participants