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

QCQMC Part 5: Add Trial Wavefunction #347

Merged
merged 21 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
37 changes: 37 additions & 0 deletions recirq/qcqmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,40 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from functools import lru_cache
from typing import Optional

from cirq.protocols.json_serialization import DEFAULT_RESOLVERS, ObjectFactory

from .fermion_mode import FermionicMode
from .hamiltonian import HamiltonianData, HamiltonianFileParams, PyscfHamiltonianParams
from .layer_spec import LayerSpec
from .trial_wf import PerfectPairingPlusTrialWavefunctionParams, TrialWavefunctionData


@lru_cache()
def _resolve_json(cirq_type: str) -> Optional[ObjectFactory]:
"""Resolve the types of `recirq.qcqmc.` json objects.

This is a Cirq JSON resolver suitable for appending to
`cirq.protocols.json_serialization.DEFAULT_RESOLVERS`.
"""
if not cirq_type.startswith("recirq.qcqmc."):
return None

cirq_type = cirq_type[len("recirq.qcqmc.") :]
return {
k.__name__: k
for k in [
HamiltonianFileParams,
HamiltonianData,
PyscfHamiltonianParams,
FermionicMode,
LayerSpec,
PerfectPairingPlusTrialWavefunctionParams,
TrialWavefunctionData,
]
}.get(cirq_type, None)


DEFAULT_RESOLVERS.append(_resolve_json)
Loading
Loading