Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Organize into submodules (#196)
Browse files Browse the repository at this point in the history
* model directory

* move model code

* add model init

* moved test files

* update model code

* update import

* update name

* move inference

* move infer tests

* update importsw

* add init

* update infer test imports

* update docstrings

* update test util imports

* update name to modular_hamiltonian

* model circuit tests passing

* model circuit utils tests passing

* model energy tests passing

* model energy utils tests passing

* model hamiltonian tests passing

* infer ebm tests passing

* infer qhbm tests passing

* format

* remove remaining pylint skip file headers

* update pylint version

* revert pylint upgrade

* remove lint

* remove lint

* update loss imports

* more loss import updates

* update names

* revert name change

* remove lint

* change names

* update main imports

* move model to models

* change module name model to models

* update names

* moved inference files

* update infer inports

* move tests

* move losses

* remove architectures and hamiltonian

* revive architectures

* move quantum_data to new data dir

* add needed architectures code to test module

* remove architectures

* change init file docstrings and remove lint

* remove circular import

* remove lint

* fix imports

* update init files

* remove lint

* update import style in some files

* inference test imports updated

* finish updating imports

* format

* improve test file docstrings
  • Loading branch information
zaqqwerty authored Feb 25, 2022
1 parent 6a70122 commit 9028458
Show file tree
Hide file tree
Showing 40 changed files with 670 additions and 1,148 deletions.
20 changes: 4 additions & 16 deletions qhbmlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Import QHBM library modules.*"""
"""Defines the qhbmlib package."""

from qhbmlib import architectures
from qhbmlib import circuit_infer
from qhbmlib import circuit_infer_utils
from qhbmlib import circuit_model
from qhbmlib import circuit_model_utils
from qhbmlib import energy_infer
from qhbmlib import energy_infer_utils
from qhbmlib import energy_model
from qhbmlib import energy_model_utils
from qhbmlib import hamiltonian_infer
from qhbmlib import hamiltonian_infer_utils
from qhbmlib import hamiltonian
from qhbmlib import qmhl_loss
from qhbmlib import quantum_data
from qhbmlib import data
from qhbmlib import inference
from qhbmlib import models
from qhbmlib import utils
from qhbmlib import vqt_loss
197 changes: 0 additions & 197 deletions qhbmlib/architectures.py

This file was deleted.

23 changes: 23 additions & 0 deletions qhbmlib/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 The QHBM Library Authors. All Rights Reserved.
#
# 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
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
# ==============================================================================
"""Defines the qbmlib.data package."""

from qhbmlib.data.qhbm_data import QHBMData
from qhbmlib.data.quantum_data import QuantumData

__all__ = [
"QHBMData",
"QuantumData",
]
39 changes: 39 additions & 0 deletions qhbmlib/data/qhbm_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2021 The QHBM Library Authors. All Rights Reserved.
#
# 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
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
# ==============================================================================
"""Interface to quantum data sources defined by QHBMs."""

from typing import Union

import tensorflow as tf

from qhbmlib.data import quantum_data
from qhbmlib.inference import qhbm
from qhbmlib.models import hamiltonian


class QHBMData(quantum_data.QuantumData):
"""QuantumData defined by a QHBM."""

def __init__(self, input_qhbm: qhbm.QHBM):
"""Initializes a QHBMData.
Args:
qhbm: An inference engine for a QHBM.
"""
self.qhbm = input_qhbm

def expectation(self, observable: Union[tf.Tensor, hamiltonian.Hamiltonian]):
"""See base class docstring."""
return tf.squeeze(self.qhbm.expectation(observable), 0)
22 changes: 2 additions & 20 deletions qhbmlib/quantum_data.py → qhbmlib/data/quantum_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@

import tensorflow as tf

from qhbmlib import hamiltonian_infer
from qhbmlib import hamiltonian_model
from qhbmlib.models import hamiltonian


class QuantumData(abc.ABC):
"""Interface for quantum datasets."""

@abc.abstractmethod
def expectation(self, observable: Union[tf.Tensor,
hamiltonian_model.Hamiltonian]):
def expectation(self, observable: Union[tf.Tensor, hamiltonian.Hamiltonian]):
"""Take the expectation value of an observable against this dataset.
Args:
Expand All @@ -41,19 +39,3 @@ def expectation(self, observable: Union[tf.Tensor,
this quantum data source.
"""
raise NotImplementedError()


class QHBMData(QuantumData):
"""QuantumData defined by a QHBM."""

def __init__(self, qhbm: hamiltonian_infer.QHBM):
"""Initializes a QHBMData.
Args:
qhbm: An inference engine for a QHBM.
"""
self.qhbm = qhbm

def expectation(self, observable):
"""See base class docstring."""
return tf.squeeze(self.qhbm.expectation(observable), 0)
Loading

0 comments on commit 9028458

Please sign in to comment.