chore: rerun pre-commit

This commit is contained in:
MatteoRobbiati
2025-01-29 14:44:44 +01:00
parent ad40a8ba7a
commit a609dfaa10
2 changed files with 41 additions and 60 deletions

View File

@@ -19,7 +19,7 @@ repos:
- id: isort - id: isort
args: ["--profile", "black"] args: ["--profile", "black"]
- repo: https://github.com/PyCQA/docformatter - repo: https://github.com/PyCQA/docformatter
rev: v1.7.5 rev: master
hooks: hooks:
- id: docformatter - id: docformatter
additional_dependencies: [tomli] additional_dependencies: [tomli]

View File

@@ -27,25 +27,49 @@ class QMatchaTeaBackend(QibotnBackend):
# TODO: update this function whenever ``set_device`` and ``set_precision`` # TODO: update this function whenever ``set_device`` and ``set_precision``
# are set (?) # are set (?)
self._setup_qmatchatea_backend() self._setup_qmatchatea_backend()
self._observables = qtealeaves.observables.TNObservables()
@property def configure_tn_simulation(
def observables(self): self,
"""Observables measured after TN execution.""" ansatz: str = "MPS",
return self._observables convergence_params=None,
):
"""Configure TN simulation given Quantum Matcha Tea interface.
@observables.setter Args:
def observables(self, observables: dict): ansatz (str): tensor network ansatz. It can be tree tensor network "TTN"
"""Set the observables to be measured after TN execution. or Matrix Product States "MPS" (default).
convergence_params (qmatchatea.utils.QCConvergenceParameters):
It accepts a dict of objects among the ones proposed in ``qtealeaves.observables``. convergence parameters class adapted to the quantum computing
execution. See https://baltig.infn.it/quantum_matcha_tea/py_api_quantum_matcha_tea/-/blob/master/qmatchatea/utils/utils.py?ref_type=heads#L540
for more instructions. If not passed, the default values proposed
by Quantum Matcha Tea's authors are set.
""" """
self._observables = qtealeaves.observables.TNObservables()
for obs in observables: # Set configurations or defaults
if isinstance(obs, qtealeaves.observables.tnobase._TNObsBase): self.convergence_params = (
self._observables += obs convergence_params or qmatchatea.QCConvergenceParameters()
else: )
raise TypeError("Expected an instance of TNObservables") self.ansatz = ansatz
def _setup_qmatchatea_backend(self):
"""Configure qmatchatea QCBackend object."""
qmatchatea_device = (
"cpu" if "CPU" in self.device else "gpu" if "GPU" in self.device else None
)
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 = qmatchatea.QCBackend(
backend="PY", # The only alternative is Fortran, but we use Python here
precision=qmatchatea_precision,
device=qmatchatea_device,
ansatz=self.ansatz,
)
def execute_circuit( def execute_circuit(
self, self,
@@ -184,49 +208,6 @@ class QMatchaTeaBackend(QibotnBackend):
return np.real(results.observables["custom_hamiltonian"]) return np.real(results.observables["custom_hamiltonian"])
def configure_tn_simulation(
self,
ansatz: str = "MPS",
convergence_params=None,
):
"""Configure TN simulation given Quantum Matcha Tea interface.
Args:
ansatz (str): tensor network ansatz. It can be tree tensor network "TTN"
or Matrix Product States "MPS" (default).
convergence_params (qmatchatea.utils.QCConvergenceParameters):
convergence parameters class adapted to the quantum computing
execution. See https://baltig.infn.it/quantum_matcha_tea/py_api_quantum_matcha_tea/-/blob/master/qmatchatea/utils/utils.py?ref_type=heads#L540
for more instructions. If not passed, the default values proposed
by Quantum Matcha Tea's authors are set.
"""
# Set configurations or defaults
self.convergence_params = (
convergence_params or qmatchatea.QCConvergenceParameters()
)
self.ansatz = ansatz
def _setup_qmatchatea_backend(self):
"""Configure qmatchatea QCBackend object."""
qmatchatea_device = (
"cpu" if "CPU" in self.device else "gpu" if "GPU" in self.device else None
)
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 = qmatchatea.QCBackend(
backend="PY", # The only alternative is Fortran, but we use Python here
precision=qmatchatea_precision,
device=qmatchatea_device,
ansatz=self.ansatz,
)
def _qibocirc_to_qiskitcirc(self, qibo_circuit) -> qiskit.QuantumCircuit: def _qibocirc_to_qiskitcirc(self, qibo_circuit) -> qiskit.QuantumCircuit:
"""Convert a Qibo Circuit into a Qiskit Circuit.""" """Convert a Qibo Circuit into a Qiskit Circuit."""
# Convert the circuit to QASM 2.0 to qiskit # Convert the circuit to QASM 2.0 to qiskit