ffsim.testing¶
Testing utilities.
- ffsim.testing.assert_allclose_up_to_global_phase(actual, desired, rtol=1e-07, atol=0, equal_nan=True, err_msg='', verbose=True)[source]¶
Check if a == b * exp(i phi) for some real number phi.
- Parameters:
actual (
ndarray) – A Numpy array.desired (
ndarray) – Another Numpy array.rtol (
float) – Relative tolerance.atol (
float) – Absolute tolerance.equal_nan (
bool) – If True, NaNs will compare equal.err_msg (
str) – The error message to be printed in case of failure.verbose (
bool) – If True, the conflicting values are appended to the error message.
- Raises:
AssertionError – If a and b are not equal up to global phase, up to the specified precision.
- ffsim.testing.generate_norb_nelec(norb_range)[source]¶
Generate (norb, nelec) tuples for testing.
Given a range of choices for norb, generates all possible (norb, nelec) pairs.
- Return type:
Iterator[tuple[int,tuple[int,int]]]
- ffsim.testing.generate_norb_nelec_spin(norb_range)[source]¶
Generate (norb, nelec, spin) tuples for testing.
Given a range of choices for norb, generates all possible (norb, nelec, spin) triplets.
- Return type:
Iterator[tuple[int,tuple[int,int],Spin]]
- ffsim.testing.generate_norb_nocc(norb_range)[source]¶
Generate (norb, nocc) tuples for testing.
Given a range of choices for norb, generates all possible (norb, nocc) pairs. nocc refers to the occupation of a single spin species, so it ranges from 0 to norb.
- Return type:
Iterator[tuple[int,int]]
- ffsim.testing.generate_norb_spin(norb_range)[source]¶
Generate (norb, spin) tuples for testing.
Given a range of choices for norb, generates all possible (norb, spin) pairs.
- Return type:
Iterator[tuple[int,Spin]]
- ffsim.testing.random_nelec(norb, *, seed=None)[source]¶
Return a random pair of (n_alpha, n_beta) particle numbers.
- Parameters:
norb (
int) – The number of spatial orbitals.seed – A seed to initialize the pseudorandom number generator. Should be a valid input to
np.random.default_rng.
- Return type:
tuple[int,int]- Returns:
The sampled pair of (n_alpha, n_beta) particle numbers.
- ffsim.testing.random_occupied_orbitals(norb, nelec, *, seed=None)[source]¶
Return a random pair of occupied orbitals lists.
- Parameters:
norb (
int) – The number of spatial orbitals.nelec (
int|tuple[int,int]) – Either a single integer representing the number of fermions for a spinless system, or a pair of integers storing the numbers of spin alpha and spin beta fermions.seed – A seed to initialize the pseudorandom number generator. Should be a valid input to
np.random.default_rng.
- Return type:
list[int] |tuple[list[int],list[int]]- Returns:
The sampled pair of (occ_a, occ_b) occupied orbitals lists.