Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: embed_sampleset or similar #501

Open
arcondello opened this issue Oct 30, 2023 · 0 comments
Open

Feature Request: embed_sampleset or similar #501

arcondello opened this issue Oct 30, 2023 · 0 comments
Labels
feature-request/enhancement New feature or request

Comments

@arcondello
Copy link
Member

arcondello commented Oct 30, 2023

It would be useful sometimes to be able to "embed" a sampleset. Something like

import numpy as np


def embed_sampleset(sampleset, embedding, *, num_qubits=None, fill_value=2):

    if num_qubits is None:
        num_qubits = max(max(chain) for chain in embedding.values()) + 1

    num_samples = len(sampleset)

    samples = np.full((num_samples, num_qubits), fill_value)

    for i, v in enumerate(sampleset.variables):
        for c in embedding[v]:
            samples[:, c] = sampleset.record.sample[:, i]

    return samples


if __name__ == '__main__':
    import dimod

    from dwave.system import DWaveSampler, EmbeddingComposite

    bqm = dimod.generators.gnm_random_bqm(100, 1000, "SPIN")

    sampleset = EmbeddingComposite(DWaveSampler()).sample(bqm, return_embedding=True, num_reads=100, answer_mode="raw")

    embedding = sampleset.info["embedding_context"]["embedding"]

    unembedded_samples = embed_sampleset(sampleset, embedding)
@arcondello arcondello added the feature-request/enhancement New feature or request label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant