dwavesystems / dwave-hybrid

Hybrid Asynchronous Decomposition Sampler prototype framework.
https://docs.ocean.dwavesys.com/projects/hybrid/en/stable/
Apache License 2.0
84 stars 51 forks source link

How should the `racing_context` parameter be used with a third-party framework? #244

Closed speller26 closed 3 years ago

speller26 commented 3 years ago

Attempting to use BraketDWaveSampler from amazon-braket-ocean-plugin fails because the parameter racing_context is unsupported; the code snippet

braket_sampler = BraketDWaveSampler(s3_destination_folder, device_arn)
subproblem_sampler = EmbeddingComposite(braket_sampler)

# Create a Runnable from a Sampler to be used in the dwave-hybrid workflow
# As explained at https://docs.ocean.dwavesys.com/en/stable/docs_hybrid/intro/developing.html
# and https://docs.ocean.dwavesys.com/en/stable/docs_hybrid/reference/conversion.html#hybrid.core.HybridRunnable
subproblem_runnable = hybrid.HybridRunnable(subproblem_sampler, fields=('subproblem', 'subsamples'))

bqm: dimod.BQM = dimod.generators.ran_r(0, 10)

# Setup the flow of a single iteration with racing branches
# Introduction and snippet at https://docs.ocean.dwavesys.com/en/stable/docs_hybrid/intro/using.html#racingbranches1
hybrid_iteration = hybrid.RacingBranches(
    hybrid.InterruptableTabuSampler(),
    hybrid.EnergyImpactDecomposer(size=MAX_SIZE)
    | subproblem_runnable
    | hybrid.SplatComposer()
) | hybrid.ArgMin()

# Setup the hybrid workflow such that the iterations loop until there's no improvement in the solution
hybrid_workflow = hybrid.LoopUntilNoImprovement(hybrid_iteration, convergence=3)

# Initialize the problem state from which to start the iterations
init_state = hybrid.State.from_problem(bqm)

# Run the hybrid workflow and retrieve the result
sampleset = hybrid_workflow.run(init_state).result()

fails because the racing_context parameter is not included in the plugin's supported parameters. However, these parameters are defined in the SAPI reference, which has no reference to racing_context. There doesn't seem to be any documentation about what this parameter does, and if it hits SAPI at all, so it's unclear if this problem would be solved even if the parameter were added to the Amazon Braket service.

Do you have any information about how this parameter is used, and what the path forward for supporting it should be?

randomir commented 3 years ago

This looks like a bug in dwave-hybrid. Thanks for reporting it!