qiskit-documentation/docs/api/qiskit-addon-sqd/configuration-recovery.mdx

78 lines
4.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: configuration_recovery (latest version)
description: API reference for qiskit_addon_sqd.configuration_recovery in the latest version of qiskit-addon-sqd
in_page_toc_min_heading_level: 2
python_api_type: module
python_api_name: qiskit_addon_sqd.configuration_recovery
---
<span id="module-qiskit_addon_sqd.configuration_recovery" />
<span id="configuration-recovery-qiskit-addon-sqd-configuration-recovery" />
# Configuration recovery
`qiskit_addon_sqd.configuration_recovery`
Functions for performing self-consistent configuration recovery.
### post\_select\_by\_hamming\_weight
<Function id="qiskit_addon_sqd.configuration_recovery.post_select_by_hamming_weight" github="https://github.com/Qiskit/qiskit-addon-sqd/tree/main/qiskit_addon_sqd/configuration_recovery.py#L24-L48" signature="post_select_by_hamming_weight(bitstring_matrix, *, hamming_right, hamming_left)">
Post-select bitstrings based on the hamming weight of each half.
**Parameters**
* **bitstring\_matrix** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)")) 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 "(in Python v3.13)")) The target hamming weight of the right half of bitstrings
* **hamming\_left** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) 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 "(in NumPy v2.1)")
</Function>
### recover\_configurations
<Function id="qiskit_addon_sqd.configuration_recovery.recover_configurations" github="https://github.com/Qiskit/qiskit-addon-sqd/tree/main/qiskit_addon_sqd/configuration_recovery.py#L51-L117" signature="recover_configurations(bitstring_matrix, probabilities, avg_occupancies, num_elec_a, num_elec_b, rand_seed=None)">
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.
<Admonition title="Note" type="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`.
</Admonition>
<Admonition title="Note" type="note">
The output configurations may not necessarily have correct hamming weight, as each bit is flipped in isolation from the other bits in the bitstring.
</Admonition>
**Parameters**
* **bitstring\_matrix** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)")) 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 "(in Python v3.13)")*\[*[*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")*]*) A 1D array specifying a probability distribution over the bitstrings
* **avg\_occupancies** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)")) A 1D array containing the mean occupancy of each orbital. It is assumed that `avg_occupancies[i]` corresponds to the orbital represented by column `i` in `bitstring_matrix`.
* **num\_elec\_a** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) The number of spin-up electrons in the system.
* **num\_elec\_b** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) The number of spin-down electrons in the system.
* **rand\_seed** ([*Generator*](https://numpy.org/doc/stable/reference/random/generator.html#numpy.random.Generator "(in NumPy v2.1)") *|*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *| 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 "(in Python v3.13)")\[[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)"), [*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.1)")]
**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].
</Function>