简化代码;加入.venv下内容
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:
@@ -9,6 +9,7 @@ from qibotn.benchmark_cases import (
|
||||
build_circuit as build_benchmark_circuit,
|
||||
exact_pauli_sum,
|
||||
)
|
||||
from qibotn import cpu_expectation, mps_expectation, pauli_pattern, pauli_sum
|
||||
|
||||
|
||||
def build_circuit(nqubits=6):
|
||||
@@ -46,6 +47,37 @@ def test_cpu_generic_tn_expectation_matches_statevector():
|
||||
assert math.isclose(value, exact, abs_tol=1e-12)
|
||||
|
||||
|
||||
def test_public_cpu_expectation_api_matches_statevector():
|
||||
circuit = build_circuit()
|
||||
observable = pauli_sum((0.5, [("X", 0), ("Z", 1)]), (-0.25, [("Z", 5)]))
|
||||
exact = exact_pauli_sum(
|
||||
circuit,
|
||||
[(0.5, (("X", 0), ("Z", 1))), (-0.25, (("Z", 5),))],
|
||||
circuit.nqubits,
|
||||
)
|
||||
|
||||
value = cpu_expectation(circuit, observable, torch_threads=1)
|
||||
|
||||
assert math.isclose(value, exact, abs_tol=1e-12)
|
||||
|
||||
|
||||
def test_public_mps_expectation_api_accepts_pauli_pattern():
|
||||
circuit = build_circuit()
|
||||
exact_hamiltonian = hamiltonians.SymbolicHamiltonian(
|
||||
form=X(1) * Z(2) * X(4) * Z(5)
|
||||
)
|
||||
exact = exact_hamiltonian.expectation_from_state(circuit().state(numpy=True))
|
||||
|
||||
value = mps_expectation(
|
||||
circuit,
|
||||
pauli_pattern("IXZ"),
|
||||
bond=64,
|
||||
torch_threads=1,
|
||||
)
|
||||
|
||||
assert math.isclose(value, exact, abs_tol=1e-12)
|
||||
|
||||
|
||||
def test_cpu_mps_expectation_matches_statevector():
|
||||
circuit = build_circuit()
|
||||
observable = build_observable(circuit.nqubits)
|
||||
|
||||
Reference in New Issue
Block a user