Add a method for reordering the variables in a sample set

Open Beginner friendly
#1,325 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start with the SampleSet API and review the existing samples, vartype, variable-order, and data_vectors behavior shown in the issue. Add a reorder_variables(order) entry point that returns the same sampleset information with variables in the requested order, then verify that the reordered samples and metadata match the documented manual approach.

Written by the indexing model from the issue text.

Description

enhancement

It would be good to have something like

reordered_sampleset = sampleset.reorder_variables(order)

Additional Context
This can currently be done "manually"

# Get the samples as an unlabelled array, but with the columns ordered by variable_order
samples_array = sampleset.samples(sorted_by=None)[:, variable_order]

# Construct a new sampleset with that array and variable order, keeping everything else the
# same
reordered_sampleset = dimod.SampleSet.from_samples(
    (samples_array, variable_order),  # the samples array, with the new order
    vartype=sampleset.vartype,  # vartype is the same
    sort_labels=False,  # don't sort the labels
    **sampleset.data_vectors,  # energy, num_occurances, etc are all the same
    )

but it might be nice to have it all bundled into a method

Dominant language
Python
Stars
143
Forks
91
Avg merge
1h 24m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dwavesystems/dimod

All issues in dwavesystems/dimod

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.