Skip to content

Commit

Permalink
only return spin square, not multiplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Feb 23, 2024
1 parent 63c9fca commit 6c103b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions python/ffsim/states/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,4 @@ def spin_square(fcivec: np.ndarray, norb: int, nelec: tuple[int, int]):
ci1 += 1j * contract_ss(fcivec.imag, norb, nelec)
else:
ci1 = contract_ss(fcivec, norb, nelec)
ss = np.einsum("ij,ij->", fcivec.reshape(ci1.shape), ci1.conj()).real
s = np.sqrt(ss + 0.25) - 0.5
multip = s * 2 + 1
return ss, multip
return np.einsum("ij,ij->", fcivec.reshape(ci1.shape), ci1.conj()).real
4 changes: 2 additions & 2 deletions tests/gates/diag_coulomb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_apply_diag_coulomb_evolution_spin(z_representation: bool):
orbital_rotation = ffsim.random.random_unitary(norb, seed=rng)
vec = ffsim.random.random_statevector(dim, seed=rng)

spin_squared_init, _ = ffsim.spin_square(vec, norb=norb, nelec=nelec)
spin_squared_init = ffsim.spin_square(vec, norb=norb, nelec=nelec)

time = rng.uniform()
result = ffsim.apply_diag_coulomb_evolution(
Expand All @@ -93,7 +93,7 @@ def test_apply_diag_coulomb_evolution_spin(z_representation: bool):
z_representation=z_representation,
)

spin_squared_result, _ = ffsim.spin_square(result, norb=norb, nelec=nelec)
spin_squared_result = ffsim.spin_square(result, norb=norb, nelec=nelec)

np.testing.assert_allclose(spin_squared_result, spin_squared_init)

Expand Down
8 changes: 4 additions & 4 deletions tests/variational/ucj_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_t_amplitudes_spin():
reference_state = ffsim.slater_determinant(
norb=norb, occupied_orbitals=(range(n_alpha), range(n_beta))
)
spin_squared, _ = ffsim.spin_square(reference_state, norb=norb, nelec=nelec)
spin_squared = ffsim.spin_square(reference_state, norb=norb, nelec=nelec)
np.testing.assert_allclose(spin_squared, 0)

# Apply the operator to the reference state
Expand All @@ -222,7 +222,7 @@ def test_t_amplitudes_spin():
np.testing.assert_allclose(energy, -108.595692)

# Compute the spin of the ansatz state
spin_squared, _ = ffsim.spin_square(ansatz_state, norb=norb, nelec=nelec)
spin_squared = ffsim.spin_square(ansatz_state, norb=norb, nelec=nelec)
np.testing.assert_allclose(spin_squared, 0, atol=1e-12)


Expand Down Expand Up @@ -407,7 +407,7 @@ def test_real_ucj_t_amplitudes_spin():
reference_state = ffsim.slater_determinant(
norb=norb, occupied_orbitals=(range(n_alpha), range(n_beta))
)
spin_squared, _ = ffsim.spin_square(reference_state, norb=norb, nelec=nelec)
spin_squared = ffsim.spin_square(reference_state, norb=norb, nelec=nelec)
np.testing.assert_allclose(spin_squared, 0)

# Apply the operator to the reference state
Expand All @@ -421,7 +421,7 @@ def test_real_ucj_t_amplitudes_spin():
np.testing.assert_allclose(energy, -108.595692)

# Compute the spin of the ansatz state
spin_squared, _ = ffsim.spin_square(ansatz_state, norb=norb, nelec=nelec)
spin_squared = ffsim.spin_square(ansatz_state, norb=norb, nelec=nelec)
np.testing.assert_allclose(spin_squared, 0, atol=1e-12)


Expand Down

0 comments on commit 6c103b6

Please sign in to comment.