-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated structural changes * Modified docstrings --------- Co-authored-by: Greshma Shaji <[email protected]>
- Loading branch information
1 parent
62a87b5
commit 21fa376
Showing
26 changed files
with
3,822 additions
and
3,720 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2021 The QUARK 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 | ||
# | ||
# http://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. | ||
|
||
from abc import ABC, abstractmethod | ||
from modules.Core import Core | ||
|
||
|
||
class Circuit(Core, ABC): | ||
""" | ||
This module is abstract base class for the library-agnostic gate sequence, that define a quantum circuit. | ||
""" | ||
|
||
@abstractmethod | ||
def generate_gate_sequence(self, input_data: dict, config: any) -> dict: | ||
""" | ||
Generates the library agnostic gate sequence, a well-defined definition of the quantum circuit. | ||
:param input_data: Input data required to generate the gate sequence | ||
:param config: Configuration for the gate sequence | ||
:return: Generated gate sequence | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright 2021 The QUARK 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 | ||
# | ||
# http://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. | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
import pandas as pd | ||
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator | ||
|
||
|
||
class DataHandler(ABC): | ||
""" | ||
Abstract base class for DataHandler. This class defines the | ||
necessary methods that both supervised and unsupervised QML applciations | ||
must implement. | ||
""" | ||
|
||
@abstractmethod | ||
def data_load(self, gen_mod: dict, config: dict) -> tuple[any, float]: | ||
""" | ||
Helps to ensure that the model can effectively learn the underlying | ||
patterns and structure of the data, and produce high-quality outputs. | ||
:param gen_mod: Dictionary with collected information of the previous modules | ||
:param config: Config specifying the parameters of the data handler | ||
:return: Mapped problem and the time it took to create the mapping | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def evaluate(self, solution: any) -> tuple[any, float]: | ||
""" | ||
Computes the best loss values. | ||
:param solution: Solution data | ||
:return: Evaluation data and the time it took to create it | ||
""" | ||
pass | ||
|
||
@staticmethod | ||
def tb_to_pd(logdir: str, rep: str) -> None: | ||
""" | ||
Converts TensorBoard event files in the specified log directory | ||
into a pandas DataFrame and saves it as a pickle file. | ||
:param logdir: Path to the log directory containing TensorBoard event files | ||
:param rep: Repetition counter | ||
""" | ||
event_acc = EventAccumulator(logdir) | ||
event_acc.Reload() | ||
tags = event_acc.Tags() | ||
data = [] | ||
tag_data = {} | ||
for tag in tags['scalars']: | ||
data = event_acc.Scalars(tag) | ||
tag_values = [d.value for d in data] | ||
tag_data[tag] = tag_values | ||
data = pd.DataFrame(tag_data, index=[d.step for d in data]) | ||
data.to_pickle(f"{logdir}/data_{rep}.pkl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2021 The QUARK 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 | ||
# | ||
# http://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 | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Model(ABC): | ||
""" | ||
Abstract base class for any quantum model. This class defines the necessary methods | ||
that models like 'LibraryGenerative' must implement. | ||
""" | ||
|
||
@abstractmethod | ||
def sequence_to_circuit(self, input_data: dict) -> dict: | ||
""" | ||
Abstract method to convert a sequence into a quantum circuit. | ||
:param input_data: Input data representing the gate sequence | ||
:return: A dictionary representing the quantum circuit | ||
""" | ||
pass | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def get_execute_circuit(circuit: any, backend: any, config: str, config_dict: dict) -> tuple[any, any]: | ||
""" | ||
This method combines the circuit implementation and the selected backend and returns a function that will be | ||
called during training. | ||
:param circuit: Implementation of the quantum circuit | ||
:param backend: Configured qiskit backend | ||
:param config: Name of a backend | ||
:param config_dict: Dictionary including the number of shots | ||
:return: Tuple that contains a method that executes the quantum circuit for a given set of parameters and the | ||
transpiled circuit | ||
""" | ||
pass | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def select_backend(config: str, n_qubits: int) -> any: | ||
""" | ||
This method configures the backend. | ||
:param config: Name of a backend | ||
:param n_qubits: Number of qubits | ||
:return: Configured backend | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2021 The QUARK 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 | ||
# | ||
# http://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. | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Training(ABC): | ||
""" | ||
Abstract base class for training QML models. | ||
""" | ||
|
||
@abstractmethod | ||
def start_training(self, input_data: dict, config: any, **kwargs: dict) -> dict: | ||
""" | ||
This function starts the training of QML model or deploys a pretrained model. | ||
:param input_data: A representation of the quantum machine learning model that will be trained | ||
:param config: Config specifying the parameters of the training (dict-like Config type defined in children) | ||
:param kwargs: Optional additional settings | ||
:return: Solution, the time it took to compute it and some optional additional information | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.