更新脚本
Some checks failed
Build wheels / build (ubuntu-latest, 3.11) (push) Has been cancelled
Build wheels / build (ubuntu-latest, 3.12) (push) Has been cancelled
Build wheels / build (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / check (push) Has been cancelled
Tests / build (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / build (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / build (ubuntu-latest, 3.13) (push) Has been cancelled
Some checks failed
Build wheels / build (ubuntu-latest, 3.11) (push) Has been cancelled
Build wheels / build (ubuntu-latest, 3.12) (push) Has been cancelled
Build wheels / build (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / check (push) Has been cancelled
Tests / build (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / build (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / build (ubuntu-latest, 3.13) (push) Has been cancelled
This commit is contained in:
@@ -70,6 +70,8 @@ def main():
|
|||||||
parser.add_argument("--exact", action="store_true")
|
parser.add_argument("--exact", action="store_true")
|
||||||
parser.add_argument("--exact-max-qubits", type=int, default=24)
|
parser.add_argument("--exact-max-qubits", type=int, default=24)
|
||||||
parser.add_argument("--preprocess", action="store_true")
|
parser.add_argument("--preprocess", action="store_true")
|
||||||
|
parser.add_argument("--compile-circuit", action="store_true")
|
||||||
|
parser.add_argument("--track-memory", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
logging.getLogger("qibo.config").setLevel(logging.ERROR)
|
logging.getLogger("qibo.config").setLevel(logging.ERROR)
|
||||||
logging.getLogger("qtealeaves").setLevel(logging.ERROR)
|
logging.getLogger("qtealeaves").setLevel(logging.ERROR)
|
||||||
@@ -105,10 +107,17 @@ def main():
|
|||||||
cut_ratio=args.cut_ratio,
|
cut_ratio=args.cut_ratio,
|
||||||
svd_control=args.svd_control,
|
svd_control=args.svd_control,
|
||||||
tensor_module=args.tensor_module,
|
tensor_module=args.tensor_module,
|
||||||
|
compile_circuit=args.compile_circuit,
|
||||||
|
track_memory=args.track_memory,
|
||||||
)
|
)
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
value = float(
|
value = float(
|
||||||
backend.expectation(circuit, observable, preprocess=args.preprocess).real
|
backend.expectation(
|
||||||
|
circuit,
|
||||||
|
observable,
|
||||||
|
preprocess=args.preprocess,
|
||||||
|
compile_circuit=args.compile_circuit,
|
||||||
|
).real
|
||||||
)
|
)
|
||||||
elapsed = time.perf_counter() - start
|
elapsed = time.perf_counter() - start
|
||||||
abs_error = float("nan") if exact is None else abs(value - exact)
|
abs_error = float("nan") if exact is None else abs(value - exact)
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class QMatchaTeaBackend(QibotnBackend, NumpyBackend):
|
|||||||
svd_control: str = "A",
|
svd_control: str = "A",
|
||||||
ini_bond_dimension: int = 1,
|
ini_bond_dimension: int = 1,
|
||||||
tensor_module: str = "numpy",
|
tensor_module: str = "numpy",
|
||||||
|
compile_circuit: bool = False,
|
||||||
|
cache_gate_tensors: bool = True,
|
||||||
|
track_memory: bool = False,
|
||||||
):
|
):
|
||||||
"""Configure TN simulation given Quantum Matcha Tea interface.
|
"""Configure TN simulation given Quantum Matcha Tea interface.
|
||||||
|
|
||||||
@@ -78,6 +81,9 @@ class QMatchaTeaBackend(QibotnBackend, NumpyBackend):
|
|||||||
)
|
)
|
||||||
self.ansatz = ansatz
|
self.ansatz = ansatz
|
||||||
self.tensor_module = tensor_module
|
self.tensor_module = tensor_module
|
||||||
|
self.compile_circuit = compile_circuit
|
||||||
|
self.cache_gate_tensors = cache_gate_tensors
|
||||||
|
self.track_memory = track_memory
|
||||||
if hasattr(self, "qmatchatea_backend"):
|
if hasattr(self, "qmatchatea_backend"):
|
||||||
self._setup_backend_specifics()
|
self._setup_backend_specifics()
|
||||||
|
|
||||||
@@ -100,6 +106,8 @@ class QMatchaTeaBackend(QibotnBackend, NumpyBackend):
|
|||||||
ansatz=self.ansatz,
|
ansatz=self.ansatz,
|
||||||
tensor_module=self.tensor_module,
|
tensor_module=self.tensor_module,
|
||||||
)
|
)
|
||||||
|
self.qmatchatea_backend.cache_gate_tensors = self.cache_gate_tensors
|
||||||
|
self.qmatchatea_backend.track_memory = self.track_memory
|
||||||
|
|
||||||
def execute_circuit(
|
def execute_circuit(
|
||||||
self,
|
self,
|
||||||
@@ -199,7 +207,7 @@ class QMatchaTeaBackend(QibotnBackend, NumpyBackend):
|
|||||||
statevector=statevector,
|
statevector=statevector,
|
||||||
)
|
)
|
||||||
|
|
||||||
def expectation(self, circuit, observable, preprocess=True):
|
def expectation(self, circuit, observable, preprocess=True, compile_circuit=None):
|
||||||
"""Compute the expectation value of a Qibo-friendly ``observable`` on
|
"""Compute the expectation value of a Qibo-friendly ``observable`` on
|
||||||
the Tensor Network constructed from a Qibo ``circuit``.
|
the Tensor Network constructed from a Qibo ``circuit``.
|
||||||
|
|
||||||
@@ -225,7 +233,11 @@ class QMatchaTeaBackend(QibotnBackend, NumpyBackend):
|
|||||||
observable = check_observable(observable, circuit.nqubits)
|
observable = check_observable(observable, circuit.nqubits)
|
||||||
|
|
||||||
# From Qibo to Qiskit
|
# From Qibo to Qiskit
|
||||||
circuit = self._qibocirc_to_qiskitcirc(circuit, preprocess=preprocess)
|
circuit = self._qibocirc_to_qiskitcirc(
|
||||||
|
circuit,
|
||||||
|
preprocess=preprocess,
|
||||||
|
compile_circuit=compile_circuit,
|
||||||
|
)
|
||||||
run_qk_params = qmatchatea.preprocessing.qk_transpilation_params(False)
|
run_qk_params = qmatchatea.preprocessing.qk_transpilation_params(False)
|
||||||
|
|
||||||
operators = qmatchatea.QCOperators()
|
operators = qmatchatea.QCOperators()
|
||||||
@@ -245,21 +257,28 @@ class QMatchaTeaBackend(QibotnBackend, NumpyBackend):
|
|||||||
return np.real(results.observables["custom_hamiltonian"])
|
return np.real(results.observables["custom_hamiltonian"])
|
||||||
|
|
||||||
def _qibocirc_to_qiskitcirc(
|
def _qibocirc_to_qiskitcirc(
|
||||||
self, qibo_circuit, preprocess=True
|
self, qibo_circuit, preprocess=True, compile_circuit=None
|
||||||
) -> qiskit.QuantumCircuit:
|
) -> 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
|
||||||
qasm_circuit = qibo_circuit.to_qasm()
|
qasm_circuit = qibo_circuit.to_qasm()
|
||||||
qiskit_circuit = qiskit.QuantumCircuit.from_qasm_str(qasm_circuit)
|
qiskit_circuit = qiskit.QuantumCircuit.from_qasm_str(qasm_circuit)
|
||||||
|
|
||||||
|
if compile_circuit is None:
|
||||||
|
compile_circuit = self.compile_circuit
|
||||||
|
|
||||||
if not preprocess:
|
if not preprocess:
|
||||||
|
if compile_circuit:
|
||||||
|
qiskit_circuit = qmatchatea.tensor_compiler(qiskit_circuit)
|
||||||
return qiskit_circuit
|
return qiskit_circuit
|
||||||
|
|
||||||
# Transpile the circuit to adapt it to the linear structure of the MPS,
|
# Transpile the circuit to adapt it to the linear structure of the MPS,
|
||||||
# with the constraint of having only the gates basis_gates
|
# with the constraint of having only the gates basis_gates
|
||||||
qiskit_circuit = qmatchatea.preprocessing.preprocess(
|
qiskit_circuit = qmatchatea.preprocessing.preprocess(
|
||||||
qiskit_circuit,
|
qiskit_circuit,
|
||||||
qk_params=qmatchatea.preprocessing.qk_transpilation_params(),
|
qk_params=qmatchatea.preprocessing.qk_transpilation_params(
|
||||||
|
tensor_compiler=compile_circuit
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return qiskit_circuit
|
return qiskit_circuit
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user