Skip to content

Commit

Permalink
Refactor Max amplitudes argument and bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
brenjohn committed May 7, 2021
1 parent 5d1c8d5 commit 165e028
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QXContexts"
uuid = "04c26001-d4a1-49d2-b090-1d469cf06784"
authors = ["QuantEx team"]
version = "0.1.8"
version = "0.1.9"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
3 changes: 1 addition & 2 deletions src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ function execute(dsl_file::String,
# produce bitstrings to compute amplitudes for.
commands = parse_dsl(dsl_file)
sampler_args, partition_params = parse_parameters(param_file,
max_amplitudes=max_amplitudes,
max_parameters=max_parameters)

# Create a context to execute the commands in.
Expand All @@ -347,7 +346,7 @@ function execute(dsl_file::String,

# Create a sampler to produce bitstrings to get amplitudes for and a variable to store
# the results.
sampler = QXContexts.Sampling.create_sampler(sampler_args, ctx)
sampler = QXContexts.Sampling.create_sampler(sampler_args, ctx, max_amplitudes)
results = Samples()

# For each bitstring produced by the sampler, compute its amplitude and accept or reject
Expand Down
7 changes: 2 additions & 5 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import Base.Iterators: take

"""
parse_parameters(filename::String;
max_parameters::Union{Int, Nothing}=nothing,
max_amplitudes::Union{Int, Nothing}=nothing)
max_parameters::Union{Int, Nothing}=nothing)
Parse the parameters yml file to read information about partition parameters and output
sampling method.
Expand All @@ -29,8 +28,7 @@ output:
- "10101"
"""
function parse_parameters(filename::String;
max_parameters::Union{Int, Nothing}=nothing,
max_amplitudes::Union{Int, Nothing}=nothing)
max_parameters::Union{Int, Nothing}=nothing)
param_dict = YAML.load_file(filename, dicttype=OrderedDict{String, Any})

# parse the partition paramters section of the parameter file
Expand All @@ -41,7 +39,6 @@ function parse_parameters(filename::String;
# parse the output method section of the parameter file
method_params = OrderedDict{Symbol, Any}(Symbol(x[1]) => x[2] for x in param_dict["output"])
method_params[:params] = OrderedDict{Symbol, Any}(Symbol(x[1]) => x[2] for x in method_params[:params])
max_amplitudes === nothing || (method_params[:params][:num_samples] = max_amplitudes)

return method_params, partition_params
end
Expand Down
9 changes: 7 additions & 2 deletions src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ end
Returns a sampler whose type is specified in `params`.
"""
create_sampler(params) = get_constructor(params[:method])(;params[:params]...)
get_constructor(func_name::String) = getfield(Main, Symbol(func_name*"Sampler"))

create_sampler(params, ctx::QXContext{T}) where T = create_sampler(params)

function create_sampler(params, ctx::QXMPIContext)
Expand All @@ -215,4 +213,11 @@ function create_sampler(params, ctx::QXMPIContext)
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

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

end

0 comments on commit 165e028

Please sign in to comment.