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

Commit 9028458

Browse files
authored
Organize into submodules (#196)
* 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
1 parent 6a70122 commit 9028458

40 files changed

+670
-1148
lines changed

qhbmlib/__init__.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
"""Import QHBM library modules.*"""
15+
"""Defines the qhbmlib package."""
1616

17-
from qhbmlib import architectures
18-
from qhbmlib import circuit_infer
19-
from qhbmlib import circuit_infer_utils
20-
from qhbmlib import circuit_model
21-
from qhbmlib import circuit_model_utils
22-
from qhbmlib import energy_infer
23-
from qhbmlib import energy_infer_utils
24-
from qhbmlib import energy_model
25-
from qhbmlib import energy_model_utils
26-
from qhbmlib import hamiltonian_infer
27-
from qhbmlib import hamiltonian_infer_utils
28-
from qhbmlib import hamiltonian
29-
from qhbmlib import qmhl_loss
30-
from qhbmlib import quantum_data
17+
from qhbmlib import data
18+
from qhbmlib import inference
19+
from qhbmlib import models
3120
from qhbmlib import utils
32-
from qhbmlib import vqt_loss

qhbmlib/architectures.py

Lines changed: 0 additions & 197 deletions
This file was deleted.

qhbmlib/data/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2021 The QHBM Library Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Defines the qbmlib.data package."""
16+
17+
from qhbmlib.data.qhbm_data import QHBMData
18+
from qhbmlib.data.quantum_data import QuantumData
19+
20+
__all__ = [
21+
"QHBMData",
22+
"QuantumData",
23+
]

qhbmlib/data/qhbm_data.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2021 The QHBM Library Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Interface to quantum data sources defined by QHBMs."""
16+
17+
from typing import Union
18+
19+
import tensorflow as tf
20+
21+
from qhbmlib.data import quantum_data
22+
from qhbmlib.inference import qhbm
23+
from qhbmlib.models import hamiltonian
24+
25+
26+
class QHBMData(quantum_data.QuantumData):
27+
"""QuantumData defined by a QHBM."""
28+
29+
def __init__(self, input_qhbm: qhbm.QHBM):
30+
"""Initializes a QHBMData.
31+
32+
Args:
33+
qhbm: An inference engine for a QHBM.
34+
"""
35+
self.qhbm = input_qhbm
36+
37+
def expectation(self, observable: Union[tf.Tensor, hamiltonian.Hamiltonian]):
38+
"""See base class docstring."""
39+
return tf.squeeze(self.qhbm.expectation(observable), 0)

qhbmlib/quantum_data.py renamed to qhbmlib/data/quantum_data.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919

2020
import tensorflow as tf
2121

22-
from qhbmlib import hamiltonian_infer
23-
from qhbmlib import hamiltonian_model
22+
from qhbmlib.models import hamiltonian
2423

2524

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

2928
@abc.abstractmethod
30-
def expectation(self, observable: Union[tf.Tensor,
31-
hamiltonian_model.Hamiltonian]):
29+
def expectation(self, observable: Union[tf.Tensor, hamiltonian.Hamiltonian]):
3230
"""Take the expectation value of an observable against this dataset.
3331
3432
Args:
@@ -41,19 +39,3 @@ def expectation(self, observable: Union[tf.Tensor,
4139
this quantum data source.
4240
"""
4341
raise NotImplementedError()
44-
45-
46-
class QHBMData(QuantumData):
47-
"""QuantumData defined by a QHBM."""
48-
49-
def __init__(self, qhbm: hamiltonian_infer.QHBM):
50-
"""Initializes a QHBMData.
51-
52-
Args:
53-
qhbm: An inference engine for a QHBM.
54-
"""
55-
self.qhbm = qhbm
56-
57-
def expectation(self, observable):
58-
"""See base class docstring."""
59-
return tf.squeeze(self.qhbm.expectation(observable), 0)

0 commit comments

Comments
 (0)