Skip to content

Commit

Permalink
Merge branch 'qiskit-community:main' into mpo
Browse files Browse the repository at this point in the history
  • Loading branch information
bartandrews authored Jan 16, 2025
2 parents e352701 + 5a6aac7 commit cdb5341
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
- name: Build wheels
uses: pypa/[email protected]

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}
path: ./wheelhouse/*.whl

build_sdist:
Expand All @@ -37,8 +38,9 @@ jobs:
- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

upload_pypi:
Expand All @@ -51,11 +53,15 @@ jobs:
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
pattern: wheel-*
path: dist
merge-multiple: true

- uses: actions/download-artifact@v4
with:
name: sdist
path: dist

- uses: pypa/gh-action-pypi-publish@release/v1
10 changes: 6 additions & 4 deletions python/ffsim/random/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,22 +584,24 @@ def random_ucj_op_spinless(


def random_diagonal_coulomb_hamiltonian(
norb: int, *, seed=None
norb: int, *, real: bool = False, seed=None
) -> hamiltonians.DiagonalCoulombHamiltonian:
"""Sample a random diagonal Coulomb Hamiltonian.
Args:
norb: The number of spatial orbitals.
rank: The desired number of terms in the two-body part of the Hamiltonian.
If not specified, it will be set to ``norb * (norb + 1) // 2``.
real: Whether to sample a real-valued object rather than a complex-valued one.
seed: A seed to initialize the pseudorandom number generator.
Should be a valid input to ``np.random.default_rng``.
Returns:
The sampled diagonal Coulomb Hamiltonian.
"""
rng = np.random.default_rng(seed)
one_body_tensor = random_hermitian(norb, seed=rng)
if real:
one_body_tensor = random_real_symmetric_matrix(norb, seed=rng)
else:
one_body_tensor = random_hermitian(norb, seed=rng)
diag_coulomb_mat_a = random_real_symmetric_matrix(norb, seed=rng)
diag_coulomb_mat_b = random_real_symmetric_matrix(norb, seed=rng)
diag_coulomb_mats = np.stack([diag_coulomb_mat_a, diag_coulomb_mat_b])
Expand Down
11 changes: 11 additions & 0 deletions tests/python/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ def test_random_density_matrix(dim: int):
np.testing.assert_allclose(np.trace(mat), 1)


def test_random_diagonal_coulomb_hamiltonian():
"""Test random diagonal Coulomb Hamiltonian."""
norb = 5

dc_ham = ffsim.random.random_diagonal_coulomb_hamiltonian(norb, seed=rng)
assert dc_ham.one_body_tensor.dtype == complex

dc_ham = ffsim.random.random_diagonal_coulomb_hamiltonian(norb, seed=rng, real=True)
assert dc_ham.one_body_tensor.dtype == float


def test_raise_errors():
"""Test errors are raised as expected."""
with pytest.raises(ValueError, match="Dimension"):
Expand Down

0 comments on commit cdb5341

Please sign in to comment.