-
Notifications
You must be signed in to change notification settings - Fork 419
Use local random seeds in slater determinant tests #1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,3 @@ | ||||||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| # you may not use this file except in compliance with the License. | ||||||||||
| # You may obtain a copy of the License at | ||||||||||
|
|
@@ -137,13 +137,16 @@ | |||||||||
| class JWGetGaussianStateTest(unittest.TestCase): | ||||||||||
| def setUp(self): | ||||||||||
| self.n_qubits_range = range(2, 10) | ||||||||||
| self.rng = numpy.random.default_rng(5387) | ||||||||||
| self.hamiltonian_seed_sequence = numpy.random.SeedSequence(5387) | ||||||||||
|
|
||||||||||
| def test_ground_state_particle_conserving(self): | ||||||||||
| """Test getting the ground state of a Hamiltonian that conserves | ||||||||||
| particle number.""" | ||||||||||
| for n_qubits in self.n_qubits_range: | ||||||||||
| # Initialize a particle-number-conserving Hamiltonian | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, True) | ||||||||||
| hamiltonian_seed = self.hamiltonian_seed_sequence.spawn(1)[0].generate_state(1)[0] | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, True, seed=hamiltonian_seed) | ||||||||||
|
Comment on lines
+148
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling
Suggested change
|
||||||||||
|
|
||||||||||
| # Compute the true ground state | ||||||||||
| sparse_operator = get_sparse_operator(quadratic_hamiltonian) | ||||||||||
|
|
@@ -165,7 +168,8 @@ | |||||||||
| conserve particle number.""" | ||||||||||
| for n_qubits in self.n_qubits_range: | ||||||||||
| # Initialize a non-particle-number-conserving Hamiltonian | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, False) | ||||||||||
| hamiltonian_seed = self.hamiltonian_seed_sequence.spawn(1)[0].generate_state(1)[0] | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, False, seed=hamiltonian_seed) | ||||||||||
|
Comment on lines
+171
to
+172
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling
Suggested change
|
||||||||||
|
|
||||||||||
| # Compute the true ground state | ||||||||||
| sparse_operator = get_sparse_operator(quadratic_hamiltonian) | ||||||||||
|
|
@@ -187,11 +191,12 @@ | |||||||||
| particle number.""" | ||||||||||
| for n_qubits in self.n_qubits_range: | ||||||||||
| # Initialize a particle-number-conserving Hamiltonian | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, True) | ||||||||||
| hamiltonian_seed = self.hamiltonian_seed_sequence.spawn(1)[0].generate_state(1)[0] | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, True, seed=hamiltonian_seed) | ||||||||||
|
Comment on lines
+194
to
+195
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling
Suggested change
|
||||||||||
|
|
||||||||||
| # Pick some orbitals to occupy | ||||||||||
| num_occupied_orbitals = numpy.random.randint(1, n_qubits + 1) | ||||||||||
| occupied_orbitals = numpy.random.choice(range(n_qubits), num_occupied_orbitals, False) | ||||||||||
| num_occupied_orbitals = self.rng.integers(1, n_qubits + 1) | ||||||||||
| occupied_orbitals = self.rng.choice(range(n_qubits), num_occupied_orbitals, False) | ||||||||||
|
|
||||||||||
| # Compute the Gaussian state | ||||||||||
| circuit_energy, gaussian_state = jw_get_gaussian_state( | ||||||||||
|
|
@@ -219,11 +224,12 @@ | |||||||||
| particle number.""" | ||||||||||
| for n_qubits in self.n_qubits_range: | ||||||||||
| # Initialize a non-particle-number-conserving Hamiltonian | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, False) | ||||||||||
| hamiltonian_seed = self.hamiltonian_seed_sequence.spawn(1)[0].generate_state(1)[0] | ||||||||||
| quadratic_hamiltonian = random_quadratic_hamiltonian(n_qubits, False, seed=hamiltonian_seed) | ||||||||||
|
Comment on lines
+227
to
+228
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling
Suggested change
|
||||||||||
|
|
||||||||||
| # Pick some orbitals to occupy | ||||||||||
| num_occupied_orbitals = numpy.random.randint(1, n_qubits + 1) | ||||||||||
| occupied_orbitals = numpy.random.choice(range(n_qubits), num_occupied_orbitals, False) | ||||||||||
| num_occupied_orbitals = self.rng.integers(1, n_qubits + 1) | ||||||||||
| occupied_orbitals = self.rng.choice(range(n_qubits), num_occupied_orbitals, False) | ||||||||||
|
|
||||||||||
| # Compute the Gaussian state | ||||||||||
| circuit_energy, gaussian_state = jw_get_gaussian_state( | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
SeedSequenceis redundant here becauseself.rng(aGenerator) can be used to produce seeds for the Hamiltonian construction. Additionally, using the same seed (5387) for bothdefault_rngandSeedSequencecan lead to correlated random streams. It is recommended to use a single generator for all random choices in the test to ensure independence and simplify the code.