Skip to content

Commit

Permalink
fix: fixed observable for GST with transpiler
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Jun 17, 2024
1 parent df68f78 commit 687c260
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/qibo/tomography/gate_set_tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _measurement_basis(j, nqubits):
return [gates.M(q, basis=measurements[q]) for q in range(len(measurements))]


# this is not needed anymore
def _expectation_value(nqubits, circuit, j, nshots=int(1e4), backend=None):
"""Executes a circuit used in gate set tomography and processes the
measurement outcomes for the Pauli Transfer Matrix notation. The circuit
Expand Down Expand Up @@ -221,17 +222,27 @@ def _gate_tomography(
circ.add(gate)

for j in range(4**nqubits):
new_circ = circ.copy()
measurements = _measurement_basis(j, nqubits)
new_circ.add(measurements)
if noise_model is not None and backend.name != "qibolab":
new_circ = noise_model.apply(new_circ)
if transpiler is not None:
new_circ, _ = transpiler(new_circ)
expectation_val = _expectation_value(
nqubits, new_circ, j, nshots, backend=backend
)
matrix_jk[j, k] = expectation_val
if j == 0:
exp_val = 1.0
else:
new_circ = circ.copy()
measurements = _measurement_basis(j, nqubits)
new_circ.add(measurements)
observable = _get_observable(j, nqubits)
if noise_model is not None and backend.name != "qibolab":
new_circ = noise_model.apply(new_circ)
if transpiler is not None:
new_circ, qubit_map = transpiler(new_circ)
qubit_map = {v: k for k, v in qubit_map.items()}
for term in observable.terms:
term.target_qubits = tuple(
qubit_map.get(q, q) for q in term.target_qubits
)

exp_val = backend.execute_circuit(
new_circ, nshots=nshots
).expectation_from_samples(observable)
matrix_jk[j, k] = exp_val
return matrix_jk


Expand Down
2 changes: 2 additions & 0 deletions tests/test_tomography_gate_set_tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def test_GST_with_transpiler(backend):
include_empty=True,
Pauli_Liouville=False,
backend=backend,
transpiler=None,
)
# define transpiler
connectivity = nx.Graph()
Expand All @@ -284,6 +285,7 @@ def test_GST_with_transpiler(backend):
Sabre(connectivity),
Unroller(NativeGates.default()),
],
int_qubit_names=True,
)
# transpiled GST
T_empty_1q, T_empty_2q, *T_approx_gates = GST(
Expand Down

0 comments on commit 687c260

Please sign in to comment.