[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
@@ -2,10 +2,10 @@ from typing import Union
|
||||
|
||||
from qibo.config import raise_error
|
||||
|
||||
from qibotn.backends.cutensornet import CuTensorNet # pylint: disable=E0401
|
||||
from qibotn.backends.quimb import QuimbBackend # pylint: disable=E0401
|
||||
from qibotn.backends.qmatchatea import QMatchaTeaBackend # pylint: disable=E0401
|
||||
from qibotn.backends.abstract import QibotnBackend
|
||||
from qibotn.backends.cutensornet import CuTensorNet # pylint: disable=E0401
|
||||
from qibotn.backends.qmatchatea import QMatchaTeaBackend # pylint: disable=E0401
|
||||
from qibotn.backends.quimb import QuimbBackend # pylint: disable=E0401
|
||||
|
||||
QibotnBackend = Union[CuTensorNet, QuimbBackend, QMatchaTeaBackend]
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from qibo.backends.numpy import NumpyBackend
|
||||
from qibo.config import raise_error
|
||||
|
||||
|
||||
DEFAULT_CONFIGURATION = {
|
||||
"MPI_enabled": False, # TODO: cutensornet specific, TBRemoved
|
||||
"NCCL_enabled": False, # TODO: cutensornet specific, TBRemoved
|
||||
@@ -14,7 +14,6 @@ DEFAULT_CONFIGURATION = {
|
||||
}
|
||||
|
||||
|
||||
|
||||
class QibotnBackend(NumpyBackend):
|
||||
|
||||
def __init__(self, runcard: dict = DEFAULT_CONFIGURATION):
|
||||
@@ -37,5 +36,3 @@ class QibotnBackend(NumpyBackend):
|
||||
def configure_tn_simulation(self, **config):
|
||||
"""Configure the TN simulation that will be performed."""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -82,7 +82,6 @@ class CuTensorNet(QibotnBackend): # pragma: no cover
|
||||
if hasattr(self, "cutn"):
|
||||
self.cutn.destroy(self.handle)
|
||||
|
||||
|
||||
def cuda_type(self, dtype="complex64"):
|
||||
"""Get CUDA Type.
|
||||
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
"""Implementation of Quantum Matcha Tea backend"""
|
||||
"""Implementation of Quantum Matcha Tea backend."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from qibo.config import raise_error
|
||||
from qiskit import QuantumCircuit
|
||||
|
||||
from qibotn.backends.abstract import QibotnBackend
|
||||
from qibo.config import raise_error
|
||||
|
||||
|
||||
@dataclass
|
||||
class QMatchaTeaBackend(QibotnBackend):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
import qmatchatea # pylint: disable=import-error
|
||||
import qiskit # pylint: disable=import-error
|
||||
import qmatchatea # pylint: disable=import-error
|
||||
import qtealeaves # pylint: disable=import-error
|
||||
|
||||
self.qmatchatea = qmatchatea
|
||||
self.qiskit = qiskit
|
||||
self.qtleaves = qtealeaves
|
||||
|
||||
|
||||
# Set default configurations
|
||||
self.configure_tn_simulation()
|
||||
# TODO: update this function whenever ``set_device`` and ``set_precision``
|
||||
# are set (?)
|
||||
self._setup_qmatchatea_backend()
|
||||
|
||||
|
||||
def execute_circuit(
|
||||
self, circuit, initial_state=None, nshots=None, return_array=False
|
||||
):
|
||||
@@ -37,7 +37,7 @@ class QMatchaTeaBackend(QibotnBackend):
|
||||
if initial_state is not None:
|
||||
raise_error(
|
||||
NotImplementedError,
|
||||
f"Backend {self.name}-{self.platform} currently does not support initial state."
|
||||
f"Backend {self.name}-{self.platform} currently does not support initial state.",
|
||||
)
|
||||
|
||||
# TODO: do we want to keep it like this or we aim to implement a different
|
||||
@@ -59,14 +59,12 @@ class QMatchaTeaBackend(QibotnBackend):
|
||||
# It does not make sense to reconstruct QuantumState here!
|
||||
return results.measure_probabilities
|
||||
|
||||
|
||||
def configure_tn_simulation(
|
||||
self,
|
||||
convergence_params=None,
|
||||
ansatz: str = "MPS",
|
||||
):
|
||||
"""
|
||||
Configure TN simulation given Quantum Matcha Tea interface.
|
||||
"""Configure TN simulation given Quantum Matcha Tea interface.
|
||||
|
||||
Args:
|
||||
ansatz (str): tensor network ansatz. It can be tree tensor network "TTN"
|
||||
@@ -79,18 +77,25 @@ class QMatchaTeaBackend(QibotnBackend):
|
||||
"""
|
||||
|
||||
# Set configurationsor defaults
|
||||
self.convergence_params = convergence_params or self.qmatchatea.QCConvergenceParameters()
|
||||
self.convergence_params = (
|
||||
convergence_params or self.qmatchatea.QCConvergenceParameters()
|
||||
)
|
||||
self.ansatz = ansatz
|
||||
|
||||
# Initializing the TNObservables according to qmatchatea
|
||||
self.observables = self.qtleaves.observables.TNObservables()
|
||||
|
||||
|
||||
def _setup_qmatchatea_backend(self):
|
||||
"""Configure qmatchatea QCBackend object."""
|
||||
|
||||
self.qmatchatea_device = "cpu" if "CPU" in self.device else "gpu" if "GPU" in self.device else None
|
||||
self.qmatchatea_precision = "C" if self.precision == "single" else "Z" if self.precision == "double" else "A"
|
||||
self.qmatchatea_device = (
|
||||
"cpu" if "CPU" in self.device else "gpu" if "GPU" in self.device else None
|
||||
)
|
||||
self.qmatchatea_precision = (
|
||||
"C"
|
||||
if self.precision == "single"
|
||||
else "Z" if self.precision == "double" else "A"
|
||||
)
|
||||
|
||||
# TODO: once MPI is available for Python, integrate it here
|
||||
self.qmatchatea_backend = self.qmatchatea.QCBackend(
|
||||
@@ -110,7 +115,7 @@ class QMatchaTeaBackend(QibotnBackend):
|
||||
# with the constraint of having only the gates basis_gates
|
||||
qiskit_circuit = self.qmatchatea.preprocessing.preprocess(
|
||||
qiskit_circuit,
|
||||
qk_params=self.qmatchatea.preprocessing.qk_transpilation_params()
|
||||
qk_params=self.qmatchatea.preprocessing.qk_transpilation_params(),
|
||||
)
|
||||
|
||||
return qiskit_circuit
|
||||
@@ -1,4 +1,3 @@
|
||||
from qibo.backends.numpy import NumpyBackend
|
||||
from qibo.config import raise_error
|
||||
from qibo.result import QuantumState
|
||||
|
||||
@@ -38,7 +37,6 @@ class QuimbBackend(QibotnBackend):
|
||||
self.platform = "QuimbBackend"
|
||||
self.versions["quimb"] = self.quimb.__version__
|
||||
|
||||
|
||||
def execute_circuit(
|
||||
self, circuit, initial_state=None, nshots=None, return_array=False
|
||||
): # pragma: no cover
|
||||
|
||||
Reference in New Issue
Block a user