-
Notifications
You must be signed in to change notification settings - Fork 11
Add block-spin update sampler #44
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
Open
kevinchern
wants to merge
20
commits into
dwavesystems:main
Choose a base branch
from
kevinchern:feature/block-spin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+802
−1
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1b5123b
Add block-spin update sampler
kevinchern 58f7155
Add disclaimer about metropolis vs gibbs
kevinchern 026d2b7
Add tests and documentation for block-spin sampler
kevinchern 344886b
Rename to block-spin sampler
kevinchern aa5cf08
Test averages for Metropolis and Gibbs updates
kevinchern 096de85
Add license
kevinchern 8678925
Add documentation
kevinchern c11172f
Add release note for block-spin sampler
kevinchern 4f1ae8f
Test, document, and move helper functions
kevinchern 3b5f68d
Fix kwargs and dtype bugs
kevinchern 6e4f017
Move things around and add an init file
kevinchern 43dba74
Add functional module docstring
kevinchern 73eb09d
Add explicit named-args and rename to randspin
kevinchern 3d7a55b
Improve documentation and method/variable names
kevinchern fe56978
Allow user-input initial states
kevinchern 63313c6
Move initial state preparation into a method
kevinchern 6d09efe
Add missing documentation and type hints
kevinchern bf11755
Move schedule into constructor and add `to` method
kevinchern 501c1a7
Fix and improve coding aesthetics
kevinchern ec67223
State that randspin wraps randint in docstring
kevinchern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Copyright 2025 D-Wave | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Functional interface.""" | ||
|
|
||
| import torch | ||
|
|
||
| __all__ = ["bit2spin_soft", "spin2bit_soft"] | ||
|
|
||
|
|
||
| def bit2spin_soft(b: torch.Tensor) -> torch.Tensor: | ||
| """Maps input :math:`b` to :math:`2b-1`. | ||
|
|
||
| The mapping does not require :math:`b` to be binary, only that it is in the interval :math:`[0, 1]`. | ||
|
|
||
| Args: | ||
| b (torch.Tensor): Input tensor of values in :math:`[0, 1]`. | ||
|
|
||
| Raises: | ||
| ValueError: If not all ``b`` values are in :math:`[0, 1]`. | ||
|
|
||
| Returns: | ||
| torch.Tensor: A tensor with values :math:`2b-1`. | ||
| """ | ||
| if not ((b >= 0) & (b <= 1)).all(): | ||
| raise ValueError(f"Not all inputs are in [0, 1]: {b}") | ||
| return b * 2 - 1 | ||
|
|
||
|
|
||
| def spin2bit_soft(s: torch.Tensor) -> torch.Tensor: | ||
| """Maps input :math:`s` to :math:`(s+1)/2`. | ||
|
|
||
| The mapping does not require :math:`s` to be spin-valued, only that it is in the interval :math:`[-1, 1]`. | ||
|
|
||
| Args: | ||
| s (torch.Tensor): Input tensor of values in :math:`[-1, 1]`. | ||
|
|
||
| Raises: | ||
| ValueError: If not all ``s`` values are in `[-1, 1]`. | ||
|
|
||
| Returns: | ||
| torch.Tensor: A tensor with values :math:`(s+1)/2`. | ||
| """ | ||
| if (s.abs() > 1).any(): | ||
| raise ValueError(f"Not all inputs are in [-1, 1]: {s}") | ||
| return (s + 1) / 2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright 2025 D-Wave | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from dwave.plugins.torch.samplers.block_spin_sampler import * |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.