Skip to content

Commit

Permalink
remove deprecated classes from variational module (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung authored Oct 30, 2024
1 parent 8e2645a commit 21eac0f
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 1,738 deletions.
6 changes: 0 additions & 6 deletions python/ffsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@
)
from ffsim.variational import (
GivensAnsatzOp,
GivensAnsatzOperator,
HopGateAnsatzOperator,
NumNumAnsatzOpSpinBalanced,
RealUCJOperator,
UCCSDOpRestrictedReal,
UCJOperator,
UCJOpSpinBalanced,
UCJOpSpinless,
UCJOpSpinUnbalanced,
Expand All @@ -112,13 +109,11 @@
"FermionAction",
"FermionOperator",
"GivensAnsatzOp",
"GivensAnsatzOperator",
"HopGateAnsatzOperator",
"MolecularData",
"MolecularHamiltonian",
"NumNumAnsatzOpSpinBalanced",
"ProductStateSum",
"RealUCJOperator",
"SingleFactorizedHamiltonian",
"Spin",
"StateVector",
Expand All @@ -129,7 +124,6 @@
"SupportsLinearOperator",
"SupportsTrace",
"UCCSDOpRestrictedReal",
"UCJOperator",
"UCJOpSpinBalanced",
"UCJOpSpinUnbalanced",
"UCJOpSpinless",
Expand Down
6 changes: 0 additions & 6 deletions python/ffsim/qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from ffsim.qiskit.gates import (
DiagCoulombEvolutionJW,
DiagCoulombEvolutionSpinlessJW,
GivensAnsatzOperatorJW,
GivensAnsatzOperatorSpinlessJW,
GivensAnsatzOpJW,
GivensAnsatzOpSpinlessJW,
NumNumAnsatzOpSpinBalancedJW,
Expand All @@ -30,7 +28,6 @@
PrepareSlaterDeterminantSpinlessJW,
SimulateTrotterDiagCoulombSplitOpJW,
SimulateTrotterDoubleFactorizedJW,
UCJOperatorJW,
UCJOpSpinBalancedJW,
UCJOpSpinlessJW,
UCJOpSpinUnbalancedJW,
Expand All @@ -57,8 +54,6 @@
"FfsimSampler",
"GivensAnsatzOpJW",
"GivensAnsatzOpSpinlessJW",
"GivensAnsatzOperatorJW",
"GivensAnsatzOperatorSpinlessJW",
"MergeOrbitalRotations",
"NumNumAnsatzOpSpinBalancedJW",
"NumOpSumEvolutionJW",
Expand All @@ -72,7 +67,6 @@
"PrepareSlaterDeterminantSpinlessJW",
"SimulateTrotterDiagCoulombSplitOpJW",
"SimulateTrotterDoubleFactorizedJW",
"UCJOperatorJW",
"UCJOpSpinBalancedJW",
"UCJOpSpinUnbalancedJW",
"UCJOpSpinlessJW",
Expand Down
6 changes: 0 additions & 6 deletions python/ffsim/qiskit/gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
SimulateTrotterDoubleFactorizedJW,
)
from ffsim.qiskit.gates.givens_ansatz import (
GivensAnsatzOperatorJW,
GivensAnsatzOperatorSpinlessJW,
GivensAnsatzOpJW,
GivensAnsatzOpSpinlessJW,
)
Expand All @@ -44,15 +42,12 @@
UCJOpSpinlessJW,
UCJOpSpinUnbalancedJW,
)
from ffsim.qiskit.gates.ucj_operator import UCJOperatorJW

__all__ = [
"DiagCoulombEvolutionJW",
"DiagCoulombEvolutionSpinlessJW",
"GivensAnsatzOpJW",
"GivensAnsatzOpSpinlessJW",
"GivensAnsatzOperatorJW",
"GivensAnsatzOperatorSpinlessJW",
"NumNumAnsatzOpSpinBalancedJW",
"NumOpSumEvolutionJW",
"NumOpSumEvolutionSpinlessJW",
Expand All @@ -64,7 +59,6 @@
"PrepareSlaterDeterminantSpinlessJW",
"SimulateTrotterDiagCoulombSplitOpJW",
"SimulateTrotterDoubleFactorizedJW",
"UCJOperatorJW",
"UCJOpSpinBalancedJW",
"UCJOpSpinUnbalancedJW",
"UCJOpSpinlessJW",
Expand Down
92 changes: 1 addition & 91 deletions python/ffsim/qiskit/gates/givens_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import annotations

import itertools
import math
from collections.abc import Iterator, Sequence

Expand All @@ -25,97 +24,8 @@
Qubit,
)
from qiskit.circuit.library import PhaseGate, XXPlusYYGate
from typing_extensions import deprecated

from ffsim.variational import GivensAnsatzOp, GivensAnsatzOperator


@deprecated("GivensAnsatzOperatorJW is deprecated. Use GivensAnsatzOpJW instead.")
class GivensAnsatzOperatorJW(Gate):
"""Givens rotation ansatz operator under the Jordan-Wigner transformation.
.. warning::
This class is deprecated. Use :class:`ffsim.qiskit.GivensAnsatzOpJW` instead.
See :class:`ffsim.GivensAnsatzOperator` for a description of this gate's unitary.
"""

def __init__(
self, givens_ansatz_operator: GivensAnsatzOperator, *, label: str | None = None
):
"""Create a new Givens ansatz operator gate.
Args:
givens_ansatz_operator: The Givens rotation ansatz operator.
label: The label of the gate.
"""
self.givens_ansatz_operator = givens_ansatz_operator
super().__init__(
"givens_ansatz_jw", 2 * givens_ansatz_operator.norb, [], label=label
)

def _define(self):
"""Gate decomposition."""
qubits = QuantumRegister(self.num_qubits)
circuit = QuantumCircuit(qubits, name=self.name)
norb = len(qubits) // 2
alpha_qubits = qubits[:norb]
beta_qubits = qubits[norb:]
for instruction in _givens_ansatz_operator_jw(
alpha_qubits, self.givens_ansatz_operator
):
circuit.append(instruction)
for instruction in _givens_ansatz_operator_jw(
beta_qubits, self.givens_ansatz_operator
):
circuit.append(instruction)
self.definition = circuit


@deprecated(
"GivensAnsatzOperatorSpinlessJW is deprecated. "
"Use GivensAnsatzOpSpinlessJW instead."
)
class GivensAnsatzOperatorSpinlessJW(Gate):
"""Givens rotation ansatz operator under the Jordan-Wigner transformation, spinless.
Like :class:`GivensAnsatzOperatorJW` but only acts on a single spin species.
"""

def __init__(
self, givens_ansatz_operator: GivensAnsatzOperator, *, label: str | None = None
):
"""Create a new Givens ansatz operator gate.
Args:
givens_ansatz_operator: The Givens rotation ansatz operator.
label: The label of the gate.
"""
self.givens_ansatz_operator = givens_ansatz_operator
super().__init__(
"givens_ansatz_jw", givens_ansatz_operator.norb, [], label=label
)

def _define(self):
"""Gate decomposition."""
qubits = QuantumRegister(self.num_qubits)
self.definition = QuantumCircuit.from_instructions(
_givens_ansatz_operator_jw(qubits, self.givens_ansatz_operator),
qubits=qubits,
name=self.name,
)


def _givens_ansatz_operator_jw(
qubits: Sequence[Qubit], givens_ansatz_operator: GivensAnsatzOperator
) -> Iterator[CircuitInstruction]:
for (i, j), theta in zip(
itertools.cycle(givens_ansatz_operator.interaction_pairs),
givens_ansatz_operator.thetas,
):
yield CircuitInstruction(
XXPlusYYGate(2 * theta, -0.5 * math.pi), (qubits[i], qubits[j])
)
from ffsim.variational import GivensAnsatzOp


class GivensAnsatzOpJW(Gate):
Expand Down
84 changes: 0 additions & 84 deletions python/ffsim/qiskit/gates/ucj_operator.py

This file was deleted.

24 changes: 6 additions & 18 deletions python/ffsim/qiskit/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
from ffsim.qiskit.gates import (
DiagCoulombEvolutionJW,
DiagCoulombEvolutionSpinlessJW,
GivensAnsatzOperatorJW,
GivensAnsatzOperatorSpinlessJW,
GivensAnsatzOpJW,
GivensAnsatzOpSpinlessJW,
OrbitalRotationJW,
OrbitalRotationSpinlessJW,
PrepareHartreeFockJW,
PrepareHartreeFockSpinlessJW,
PrepareSlaterDeterminantJW,
PrepareSlaterDeterminantSpinlessJW,
SimulateTrotterDoubleFactorizedJW,
UCJOperatorJW,
UCJOpSpinBalancedJW,
UCJOpSpinlessJW,
UCJOpSpinUnbalancedJW,
Expand Down Expand Up @@ -136,14 +135,14 @@ def _evolve_state_vector_spinless(
)
return states.StateVector(vec=vec, norb=norb, nelec=nelec)

if isinstance(op, GivensAnsatzOperatorSpinlessJW):
if isinstance(op, GivensAnsatzOpSpinlessJW):
if not consecutive_sorted:
raise ValueError(
f"Gate of type '{op.__class__.__name__}' must be applied to "
"consecutive qubits, in ascending order."
)
vec = protocols.apply_unitary(
vec, op.givens_ansatz_operator, norb=norb, nelec=nelec, copy=False
vec, op.givens_ansatz_op, norb=norb, nelec=nelec, copy=False
)
return states.StateVector(vec=vec, norb=norb, nelec=nelec)

Expand Down Expand Up @@ -206,14 +205,14 @@ def _evolve_state_vector_spinful(
)
return states.StateVector(vec=vec, norb=norb, nelec=nelec)

if isinstance(op, GivensAnsatzOperatorJW):
if isinstance(op, GivensAnsatzOpJW):
if not consecutive_sorted:
raise ValueError(
f"Gate of type '{op.__class__.__name__}' must be applied to "
"consecutive qubits, in ascending order."
)
vec = protocols.apply_unitary(
vec, op.givens_ansatz_operator, norb=norb, nelec=nelec, copy=False
vec, op.givens_ansatz_op, norb=norb, nelec=nelec, copy=False
)
return states.StateVector(vec=vec, norb=norb, nelec=nelec)

Expand Down Expand Up @@ -263,17 +262,6 @@ def _evolve_state_vector_spinful(
)
return states.StateVector(vec=vec, norb=norb, nelec=nelec)

if isinstance(op, UCJOperatorJW):
if not consecutive_sorted:
raise ValueError(
f"Gate of type '{op.__class__.__name__}' must be applied to "
"consecutive qubits, in ascending order."
)
vec = protocols.apply_unitary(
vec, op.ucj_operator, norb=norb, nelec=nelec, copy=False
)
return states.StateVector(vec=vec, norb=norb, nelec=nelec)

if isinstance(op, Barrier):
return state_vector

Expand Down
2 changes: 0 additions & 2 deletions python/ffsim/random/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
random_ucj_op_spin_balanced,
random_ucj_op_spin_unbalanced,
random_ucj_op_spinless,
random_ucj_operator,
random_unitary,
)

Expand All @@ -49,7 +48,6 @@
"random_t2_amplitudes",
"random_two_body_tensor",
"random_uccsd_restricted",
"random_ucj_operator",
"random_ucj_op_spin_balanced",
"random_ucj_op_spin_unbalanced",
"random_ucj_op_spinless",
Expand Down
Loading

0 comments on commit 21eac0f

Please sign in to comment.