---
title: configuration_recovery (latest version)
description: API reference for qiskit_addon_sqd.configuration_recovery in the latest version of qiskit-addon-sqd
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit-addon-sqd/configuration-recovery
---

# Configuration recovery

`qiskit_addon_sqd.configuration_recovery`

Functions for performing self-consistent configuration recovery.

### post\_select\_by\_hamming\_weight

`post_select_by_hamming_weight(bitstring_matrix, *, hamming_right, hamming_left)`

[GitHub](https://github.com/Qiskit/qiskit-addon-sqd/tree/stable/0.13/qiskit_addon_sqd/configuration_recovery.py#L26-L56)

Post-select bitstrings based on the hamming weight of each half.

> **Deprecated since version 0.12.0**
>
> The function `qiskit_addon_sqd.configuration_recovery.post_select_by_hamming_weight()` is deprecated as of qiskit-addon-sqd 0.12.0. It will be removed no earlier than v0.13.0. Instead, use the `postselect_by_hamming_right_and_left` function.

**Parameters**

- **bitstring\_matrix** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)) – A 2D array of `bool` representations of bit values such that each row represents a single bitstring
- **hamming\_right** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The target hamming weight of the right half of bitstrings
- **hamming\_left** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The target hamming weight of the left half of bitstrings

**Returns**

A mask signifying which samples (rows) were selected from the input matrix.

**Return type**

[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)

### recover\_configurations

`recover_configurations(bitstring_matrix, probabilities, avg_occupancies, num_elec_a, num_elec_b, rand_seed=None)`

[GitHub](https://github.com/Qiskit/qiskit-addon-sqd/tree/stable/0.13/qiskit_addon_sqd/configuration_recovery.py#L59-L128)

Refine bitstrings based on average orbital occupancy and a target hamming weight.

This function refines each bit in isolation in an attempt to transform the Hilbert space represented by the input `bitstring_matrix` into a space closer to that which supports the ground state.

> **Note**
>
> This function makes the assumption that bit `i` represents the spin-down orbital corresponding to the spin-up orbital in bit `i + N` where `N` is the number of spatial orbitals and `i < N`.

**Parameters**

- **bitstring\_matrix** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)) – A 2D array of `bool` representations of bit values such that each row represents a single bitstring
- **probabilities** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*float*](https://docs.python.org/3/library/functions.html#float)*] |* [*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)) – A 1D array specifying a probability distribution over the bitstrings
- **avg\_occupancies** ([*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)*,* [*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)*]*) – A length-2 tuple of arrays holding the mean occupancy of the spin-up and spin-down orbitals, respectively. The occupancies should be formatted as: `(array([occ_a_0, ..., occ_a_N]), array([occ_b_0, ..., occ_b_N]))`
- **num\_elec\_a** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The number of spin-up electrons in the system.
- **num\_elec\_b** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The number of spin-down electrons in the system.
- **rand\_seed** ([*Generator*](https://numpy.org/doc/stable/reference/random/generator.html#numpy.random.Generator)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – A seed for controlling randomness

**Returns**

A refined bitstring matrix and an updated probability array.

**Return type**

[tuple](https://docs.python.org/3/library/stdtypes.html#tuple)\[[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), [*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)]

**References**

**\[1]: J. Robledo-Moreno, et al., [Chemistry Beyond Exact Solutions on a Quantum-Centric Supercomputer](https://arxiv.org/abs/2405.05068),**

arXiv:2405.05068 \[quant-ph].
