Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix endianness in result.mitigator #7689

Merged
merged 6 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/result/mitigation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def str2diag(string):
"1": np.array([0, 1], dtype=float),
}
ret = np.array([1], dtype=float)
for i in string:
for i in reversed(string):
if i not in chars:
raise QiskitError(f"Invalid diagonal string character {i}")
ret = np.kron(chars[i], ret)
Expand Down
30 changes: 21 additions & 9 deletions test/python/result/test_mitigators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@

import unittest
from collections import Counter

import numpy as np
from qiskit import QiskitError
from qiskit import QuantumCircuit
from qiskit.test import QiskitTestCase

from qiskit import QiskitError, QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.result import Counts
from qiskit.result import CorrelatedReadoutMitigator
from qiskit.result import LocalReadoutMitigator
from qiskit.result.utils import marginal_counts
from qiskit.quantum_info.operators.predicates import matrix_equal
from qiskit.result import (
CorrelatedReadoutMitigator,
Counts,
LocalReadoutMitigator,
)
from qiskit.result.mitigation.utils import (
counts_probability_vector,
str2diag,
expval_with_stddev,
stddev,
str2diag,
)
from qiskit.result.utils import marginal_counts
from qiskit.test import QiskitTestCase
from qiskit.test.mock import FakeYorktown
from qiskit.quantum_info.operators.predicates import matrix_equal


class TestReadoutMitigation(QiskitTestCase):
Expand Down Expand Up @@ -431,6 +434,15 @@ def test_error_handling(self):
"Assignment matrix columns must be valid probability distributions",
)

def test_expectation_value_endian(self):
"""Test that endian for expval is little."""
mitigators = self.mitigators(self.assignment_matrices())
counts = Counts({"10": 3, "11": 24, "00": 74, "01": 923})
for mitigator in mitigators:
expval, _ = mitigator.expectation_value(counts, diagonal="IZ", qubits=[0, 1])
print(expval)
jakelishman marked this conversation as resolved.
Show resolved Hide resolved
self.assertAlmostEqual(expval, -1.0, places=0)


class TestLocalReadoutMitigation(QiskitTestCase):
"""Tests specific to the local readout mitigator"""
Expand Down