Using hybrid subsamplers in a loop

I'm exploring the use of the hybrid composers, samplers, and decomposers.
One simple hybrid workflow that I'd like to test using these methods would be one that iteratively partitions a BQM and collects subsamples that are merged until all variables are sampled.
 
I believe the code would look something like this?
I'm intentionally misusing the methods, but this is close to what I want.
 
import hybrid

source_bqm = ...
max_subproblem_size = ...

workflow = hybrid.Loop( 

                    hybrid.EnergyImpactDecomposer(size=max_subproblem_size, silent_rewind=False, traversal='bfs') |

                  hybrid.SimulatedAnnealingSubproblemSampler(num_reads=5,initial_states_generator='random') |       

                  hybrid.SplatComposer())

state = hybrid.State.from_problem(source_bqm)
result = workflow.run(state).result()
 
I get "ValueError: mismatch between variables in 'initial_states' and 'bqm'" which makes sense because the decomposer iterates over different subproblems, but the subproblem sampler expects the same BQM as initial_states.
 
What is the right approach to "partition" a BQM between independent subproblems, sample them separately, and stitch them all together to form a solution to the source BQM? I know this is not an optimal approach, but I need it as a starting point.
 
Thanks in advance!
0

Comments

3 comments
  • Hello,

    This sounds a lot like the SplatComposer
    Have you had a chance to look at this one?

    Please let us know what you think.

    0
    Comment actions Permalink
  • Hi David, thanks for the quick reply.

    I actually updated my code to use the SplatComposer. You're right, that one has a closer behaviour to what I need.

    However, I would still get the same error because the SimulatedAnnealingSubproblemSampler  uses

    initial_states=state.subsamples

    I modified the SimulatedAnnealingSubproblemSampler by making initial_states=None inside the class to get it to work. Is there a reason why initial_states is always set to the state subsamples?

    Again, I might be misusing these methods, but this use case seems like a good match.

    0
    Comment actions Permalink
  • Hello,

    Thank you so much for your patience while we looked into this further.

    You are correct that the next iteration uses subsamples from the previous iteration.
    One way to remedy this is to reset the subsamples on each iteration using the following:

    Const(subsamples=None) | SimulatedAnnealingSubproblemSampler(initial_states_generator='random')

    Also see the docs for Const.

    initial_states_generator only generates values missing samples, so setting all subsamples to None as in the above will generate values for all samples.

    Hopefully this helps resolve the issue. 
    Please let us know if you have any follow-up questions.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post