mirror of https://github.com/Qiskit/qiskit.git
Edit Result to always contain date, status, header (#8216)
* date attribute Date attribute is needed for some specific applications such as mitigation in mthree. It is not created by default when running a job in the basicAer backend. * Update test_result.py * Adding default attributes header and status I have no clue why in the test_results the attribute status is repeated. * fix Result repr * add release note * Qualify method name in release note * Remove final conditional attribute lookup on Result Co-authored-by: Alejandro Montanez <alejomonbar@gmail.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
71495591d7
commit
992c2619d6
|
@ -62,12 +62,9 @@ class Result:
|
||||||
self.job_id = job_id
|
self.job_id = job_id
|
||||||
self.success = success
|
self.success = success
|
||||||
self.results = results
|
self.results = results
|
||||||
if date is not None:
|
self.date = date
|
||||||
self.date = date
|
self.status = status
|
||||||
if status is not None:
|
self.header = header
|
||||||
self.status = status
|
|
||||||
if header is not None:
|
|
||||||
self.header = header
|
|
||||||
self._metadata.update(kwargs)
|
self._metadata.update(kwargs)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -83,12 +80,7 @@ class Result:
|
||||||
self.results,
|
self.results,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if hasattr(self, "date"):
|
out += f", date={self.date}, status={self.status}, header={self.header}"
|
||||||
out += ", date=%s" % self.date
|
|
||||||
if hasattr(self, "status"):
|
|
||||||
out += ", status=%s" % self.status
|
|
||||||
if hasattr(self, "header"):
|
|
||||||
out += ", status=%s" % self.header
|
|
||||||
for key in self._metadata:
|
for key in self._metadata:
|
||||||
if isinstance(self._metadata[key], str):
|
if isinstance(self._metadata[key], str):
|
||||||
value_str = "'%s'" % self._metadata[key]
|
value_str = "'%s'" % self._metadata[key]
|
||||||
|
@ -107,17 +99,14 @@ class Result:
|
||||||
out_dict = {
|
out_dict = {
|
||||||
"backend_name": self.backend_name,
|
"backend_name": self.backend_name,
|
||||||
"backend_version": self.backend_version,
|
"backend_version": self.backend_version,
|
||||||
|
"date": self.date,
|
||||||
|
"header": None if self.header is None else self.header.to_dict(),
|
||||||
"qobj_id": self.qobj_id,
|
"qobj_id": self.qobj_id,
|
||||||
"job_id": self.job_id,
|
"job_id": self.job_id,
|
||||||
|
"status": self.status,
|
||||||
"success": self.success,
|
"success": self.success,
|
||||||
"results": [x.to_dict() for x in self.results],
|
"results": [x.to_dict() for x in self.results],
|
||||||
}
|
}
|
||||||
if hasattr(self, "date"):
|
|
||||||
out_dict["date"] = self.date
|
|
||||||
if hasattr(self, "status"):
|
|
||||||
out_dict["status"] = self.status
|
|
||||||
if hasattr(self, "header"):
|
|
||||||
out_dict["header"] = self.header.to_dict()
|
|
||||||
out_dict.update(self._metadata)
|
out_dict.update(self._metadata)
|
||||||
return out_dict
|
return out_dict
|
||||||
|
|
||||||
|
@ -142,7 +131,7 @@ class Result:
|
||||||
|
|
||||||
in_data = copy.copy(data)
|
in_data = copy.copy(data)
|
||||||
in_data["results"] = [ExperimentResult.from_dict(x) for x in in_data.pop("results")]
|
in_data["results"] = [ExperimentResult.from_dict(x) for x in in_data.pop("results")]
|
||||||
if "header" in in_data:
|
if in_data.get("header") is not None:
|
||||||
in_data["header"] = QobjHeader.from_dict(in_data.pop("header"))
|
in_data["header"] = QobjHeader.from_dict(in_data.pop("header"))
|
||||||
return cls(**in_data)
|
return cls(**in_data)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
:class:`.Result` was modified so that it always contains ``date``, ``status``,
|
||||||
|
and ``header`` attributes (set to ``None`` if not specified).
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixed a bug in :meth:`.Result.__repr__` that caused the attributes to be
|
||||||
|
specified incorrectly.
|
|
@ -121,7 +121,8 @@ class TestResultOperations(QiskitTestCase):
|
||||||
"results=[ExperimentResult(shots=14, success=True, "
|
"results=[ExperimentResult(shots=14, success=True, "
|
||||||
"meas_level=2, data=ExperimentResultData(counts={'0x0': 4,"
|
"meas_level=2, data=ExperimentResultData(counts={'0x0': 4,"
|
||||||
" '0x2': 10}), header=QobjExperimentHeader(creg_sizes="
|
" '0x2': 10}), header=QobjExperimentHeader(creg_sizes="
|
||||||
"[['c0', 2], ['c0', 1], ['c1', 1]], memory_slots=4))])"
|
"[['c0', 2], ['c0', 1], ['c1', 1]], memory_slots=4))], date=None, "
|
||||||
|
"status=None, header=None)"
|
||||||
)
|
)
|
||||||
self.assertEqual(expected, repr(result))
|
self.assertEqual(expected, repr(result))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue