Skip to content

Commit

Permalink
Adjust bipartite hamming counts generation interface
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-johnson committed Sep 13, 2024
1 parent cc0978a commit 762ecb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 6 additions & 6 deletions qiskit_addon_sqd/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def generate_counts_uniform(
def generate_counts_bipartite_hamming(
num_samples: int,
num_bits: int,
hamming_left: int,
hamming_right: int,
hamming_left: int,
rand_seed: None | int = None,
) -> dict[str, int]:
"""
Expand All @@ -100,8 +100,8 @@ def generate_counts_bipartite_hamming(
Args:
num_samples: The number of samples to draw
num_bits: The number of bits in the bitstrings
hamming_left: The hamming weight on the left half of each bitstring
hamming_right: The hamming weight on the right half of each bitstring
hamming_left: The hamming weight on the left half of each bitstring
rand_seed: A seed for controlling randomness
Returns:
Expand All @@ -128,17 +128,17 @@ def generate_counts_bipartite_hamming(
sample_dict: dict[str, int] = {}
for _ in range(num_samples):
# Pick random bits to flip such that the left and right hamming weights are correct
up_flips = np.random.choice(np.arange(num_bits // 2), hamming_left, replace=False).astype(
up_flips = np.random.choice(np.arange(num_bits // 2), hamming_right, replace=False).astype(
"int"
)
dn_flips = np.random.choice(np.arange(num_bits // 2), hamming_right, replace=False).astype(
dn_flips = np.random.choice(np.arange(num_bits // 2), hamming_left, replace=False).astype(
"int"
)

# Create a bitstring with the chosen bits flipped
bts_arr = np.zeros(num_bits)
bts_arr[up_flips] = 1
bts_arr[dn_flips + num_bits // 2] = 1
bts_arr[dn_flips] = 1
bts_arr[up_flips + num_bits // 2] = 1
bts_arr = bts_arr.astype("int")
bts = np.array2string(bts_arr, separator="")[1:-1]

Expand Down
10 changes: 9 additions & 1 deletion releasenotes/notes/subsample-hamming-76674dbaf6f411c2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ prelude: >
upgrade:
- |
The :func:`qiskit_addon_sqd.subsampling.postselect_and_subsample` and :func:`qiskit_addon_sqd.configuration_recovery.post_select_by_hamming_weight` now take the ``hamming_right`` positional argument before the ``hamming_left`` argument to better match the rest of the workflow.
The :func:`qiskit_addon_sqd.counts.generate_counts_bipartite_hamming`, :func:`qiskit_addon_sqd.subsampling.postselect_and_subsample`, and :func:`qiskit_addon_sqd.configuration_recovery.post_select_by_hamming_weight` now take the ``hamming_right`` positional argument before the ``hamming_left`` argument to better match the rest of the workflow.
To upgrade
.. code-block:: python
from qiskit_addon_sqd.configuration_recovery import post_select_by_hamming_weight
from qiskit_addon_sqd.subsampling import postselect_and_subsample
from qiskit_addon_sqd.counts import generate_counts_bipartite_hamming
counts = generate_counts_bipartite_hamming(num_samples, num_bits, num_elec_b, num_elec_a)
...
bs_mat = post_select_by_hamming_weight(bs_mat_full, num_elec_b, num_elec_a)
Expand All @@ -33,6 +38,9 @@ upgrade:
from qiskit_addon_sqd.configuration_recovery import post_select_by_hamming_weight
from qiskit_addon_sqd.subsampling import postselect_and_subsample
from qiskit_addon_sqd.counts import generate_counts_bipartite_hamming
counts = generate_counts_bipartite_hamming(num_samples, num_bits, num_elec_a, num_elec_b)
bs_mat = post_select_by_hamming_weight(bs_mat_full, num_elec_a, num_elec_b)
Expand Down

0 comments on commit 762ecb3

Please sign in to comment.