dwavesystems / dwave-system

An API for easily incorporating the D-Wave system as a sampler, either directly or through Leap's cloud-based hybrid samplers
https://docs.ocean.dwavesys.com/
Apache License 2.0
90 stars 64 forks source link

Make TilingComposite tile-aware #213

Open jberwald opened 5 years ago

jberwald commented 5 years ago

Current Problem TilingComposite currently treats a tiling of the QPU as a single entity. Based on a too-literally reading of the definition of a tiling (fixed geometric shapes or tiles filling space) I thought one could take a single, small tile, represented by a BQM, tile the QPU with that shape, and run many copies of that BQM. While this is possible using the child sampler, it is not intuitive.

Here's a sample problem: The tiling produced by TilingComposite(DWaveSampler(), 2,2,4) is composed of a bunch 32-qubit tiles. The figure below is a representation where each tile is an 32-qubit RAN-1 problem. download-1 The blank spots are where bum qubits won't allow a perfect tile.

Proposed Solution Make TilingComposite tile-aware. Let tiles = [bqm for a single tile] and define fullBQM = dimod.BQM(linear={all linear terms from tiles}, quadratic={all coupling in tiles}. Something like TilingComposte.sample_tiling(fullBQM) should return a SampleSet. Currently TilingComposte.sample(fullBQM) throws an error: BinaryQuadraticModelStructureError: given bqm does not match the sampler's structure.

arcondello commented 5 years ago

How about

sampler = DWaveSampler()
tiles = find_tiles(sampler.structure, 2, 2, 4)
bqm = dimod.BQM.empty('SPIN')
for tile in tiles:
    bqm.update(dimod.ran_r(1, tile))
sampleset = sampler.sample(bqm)

if we exposed the find_tiles function used by the TilingComposite?

It is worth noting that the original feature request for the TilingComposite was for something like

bqms = [dimod.ran_r(1, dnx.chimera_graph(2, 2, 4)) for _ in range(5)]  # get 5 different C2 BQMs
sampleset = TilingComposite(DWaveSampler()).sample(bqms)

the problem is that the Sampler API does not support accepting multiple BQMs.

jberwald commented 5 years ago

Your first code block basically lays out what I'm doing already (with more code, of course). So yes, that seems like a nice solution.

jberwald commented 5 years ago

As a side note, it seems like the TilingComposite excludes a fair amount of real estate in the example above. Am I understanding it's tiling procedure correctly in relation to inactive qubits and why some regions are not tiled?

arcondello commented 5 years ago

Yes, though it finds the regions in a pretty naive/greedy way so it can miss a lot of realestate.