Skip to content
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

consolidate project_state methods to same name across QubitTapering a… #185

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
546 changes: 275 additions & 271 deletions notebooks/2. Applications/2.3 CS-VQE for Electronic Structure.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion symmer/projection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def perform_projection(self,
# ...and finally perform the stabilizer subspace projection
return self._perform_projection(operator=op_rotated)

def project_state(self, state: QuantumState) -> QuantumState:
def _project_state(self, state: QuantumState) -> QuantumState:
"""
Project a state into the stabilizer subspace.

Expand Down
6 changes: 3 additions & 3 deletions symmer/projection/contextual_subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def project_onto_subspace(self, operator_to_project:PauliwordOp=None) -> Pauliwo
else:
return cs_operator

def project_state_onto_subspace(self,
def project_state(self,
state_to_project: QuantumState = None
) -> QuantumState:
"""
Expand Down Expand Up @@ -359,6 +359,6 @@ def project_state_onto_subspace(self,
else:
rotation_generator = sum([R*angle*.5*1j for R,angle in self.noncontextual_operator.unitary_partitioning_rotations])
rotation = trotter(rotation_generator)
return self.project_state(rotation * state_to_project)
return self._project_state(rotation * state_to_project)
else:
return self.project_state(state_to_project)
return self._project_state(state_to_project)
5 changes: 2 additions & 3 deletions symmer/projection/qubit_subspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ def project_auxiliary_state(self, state: QuantumState) -> QuantumState:
if self._n_qubits < self.hamiltonian.n_qubits:

if self.run_qubit_tapering:
state = self.QT.project_state(state)

state = self.QT.project_state(state_to_project=state)
if self.run_contextual_subspace:
state = self.CS.project_state_onto_subspace(state_to_project=state)
state = self.CS.project_state(state_to_project=state)

return state

Expand Down
5 changes: 5 additions & 0 deletions symmer/projection/qubit_tapering.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ def taper_it(self,
self.tapered_ref_state = self.project_state(ref_state)

return tapered_operator

def project_state(self, state_to_project: QuantumState) -> QuantumState:
"""
"""
return self._project_state(state_to_project)
8 changes: 4 additions & 4 deletions tests/test_projection/test_contextual_subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ def test_unitary_partitioning_method(up_method):
assert abs(exact_gs_energy(H_cs.to_sparse_matrix)[0] - fci_energy) < 0.0005

@pytest.mark.parametrize("up_method", ['LCU', 'seq_rot'])
def test_project_state_onto_subspace(up_method):
def test_project_state(up_method):
CS = ContextualSubspace(
H_taper, noncontextual_strategy='SingleSweep_magnitude',
unitary_partitioning_method=up_method
)
CS.update_stabilizers(3, aux_operator=CC_taper, strategy='aux_preserving')
CS.project_onto_subspace()
projected_state = CS.project_state_onto_subspace(QT.tapered_ref_state)
projected_state = CS.project_state(QT.tapered_ref_state)
assert projected_state == QuantumState([[0,0,0]], [-1])

def test_project_state_onto_subspace_before_operator():
def test_project_state_before_operator():
CS = ContextualSubspace(H_taper, noncontextual_strategy='StabilizeFirst')
CS.update_stabilizers(3, aux_operator=CC_taper, strategy='aux_preserving')
with pytest.raises(AssertionError):
CS.project_state_onto_subspace(QT.tapered_ref_state)
CS.project_state(QT.tapered_ref_state)
Loading