Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
brenjohn committed May 12, 2021
1 parent 165e028 commit 3e7919f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,6 @@ function execute(dsl_file::String,
ctx = QXContext(commands, partition_params, input_file)
if comm !== nothing
ctx = QXMPIContext(ctx, comm, sub_comm_size)

# # Variables needed by a sampler to divide work evenly amongst groups of nodes.
# sampler_args[:params][:rank] = MPI.Comm_rank(comm) ÷ sub_comm_size
# sampler_args[:params][:comm_size] = MPI.Comm_size(comm) ÷ sub_comm_size
end

# Create a sampler to produce bitstrings to get amplitudes for and a variable to store
Expand Down
1 change: 1 addition & 0 deletions src/mpi_execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ General utility functions for working with MPI and partitions

export get_rank_size
export get_rank_start
export get_rank_range

"""
get_rank_size(n::Integer, size::Integer, rank::Integer)
Expand Down
8 changes: 4 additions & 4 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ sampling method.
Example Parameter file
======================
partitions:
parameters:
v1: 2
v2: 2
output:
method: List
params:
bitstrings:
- "01000"
- "01110"
- "10101"
partitions:
parameters:
v1: 2
v2: 2
"""
function parse_parameters(filename::String;
max_parameters::Union{Int, Nothing}=nothing)
Expand Down
26 changes: 12 additions & 14 deletions src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function ListSampler(;bitstrings::Vector{String}=String[],
rank::Integer=0,
comm_size::Integer=1,
kwargs...)
bitstrings = bitstrings[rank+1:comm_size:end]
range = get_rank_range(length(bitstrings), comm_size, rank)
bitstrings = bitstrings[range]
if haskey(kwargs, :num_samples)
num_amplitudes = kwargs[:num_samples]
num_amplitudes = get_rank_size(num_amplitudes, comm_size, rank)
Expand All @@ -48,12 +49,6 @@ function ListSampler(;bitstrings::Vector{String}=String[],
end

"""Iterator interface functions for ListSampler"""
# Base.iterate(sampler::ListSampler) = (first(sampler.list), 1)

# function Base.iterate(sampler::ListSampler, ind::Integer)
# ind < length(sampler.list) || (return nothing)
# (sampler.list[ind+1], ind+1)
# end
Base.iterate(sampler::ListSampler) = Base.iterate(sampler.list)
Base.iterate(sampler::ListSampler, state) = Base.iterate(sampler.list, state)

Expand Down Expand Up @@ -202,21 +197,24 @@ end
"""
create_sampler(params)
Returns a sampler whose type is specified in `params`.
Returns a sampler whose type and parameters are specified in the Dict `params`.
Additional parameters that determine load balancing and totale amout of work to be done
are set by `max_amplitudes` and the Context `ctx`.
"""
create_sampler(params) = get_constructor(params[:method])(;params[:params]...)
create_sampler(params, ctx::QXContext{T}) where T = create_sampler(params)
function create_sampler(params, ctx, max_amplitudes=nothing)
max_amplitudes === nothing || (params[:params][:num_samples] = max_amplitudes)
create_sampler(params, ctx)
end

function create_sampler(params, ctx::QXMPIContext)
params[:rank] = MPI.Comm_rank(ctx.comm) ÷ MPI.Comm_size(ctx.sub_comm)
params[:comm_size] = MPI.Comm_size(ctx.comm) ÷ MPI.Comm_size(ctx.sub_comm)
create_sampler(params)
end

function create_sampler(params, ctx, max_amplitudes=nothing)
max_amplitudes === nothing || (params[:params][:num_samples] = max_amplitudes)
create_sampler(params, ctx)
end
create_sampler(params, ctx::QXContext{T}) where T = create_sampler(params)
create_sampler(params) = get_constructor(params[:method])(;params[:params]...)

get_constructor(func_name::String) = getfield(Main, Symbol(func_name*"Sampler"))

Expand Down

0 comments on commit 3e7919f

Please sign in to comment.