@@ -604,7 +604,7 @@ def submit_remote_ibm(job: Job) -> tuple[str, "RuntimeJobV2"]:
604
604
605
605
606
606
@typechecked
607
- def run_remote_ibm (job : Job ) -> Result :
607
+ def run_remote_ibm (job : Job ) -> BatchResult | Result :
608
608
"""Submits the job on the right IBM remote device, precised in the job in
609
609
parameter, and waits until the job is completed.
610
610
@@ -632,7 +632,7 @@ def extract_result(
632
632
result : "QiskitResult | EstimatorResult | PrimitiveResult[PubResult | SamplerPubResult]" ,
633
633
job : Optional [Job ],
634
634
device : "IBMDevice | IBMSimulatedDevice | AZUREDevice" ,
635
- ) -> Result : # TODO: [multi-obs] return BatchResult for multi observable
635
+ ) -> BatchResult | Result : # TODO: [multi-obs] return BatchResult for multi observable
636
636
"""Parses a result from ``IBM`` execution (remote or local) in a ``MPQP``
637
637
:class:`~mpqp.execution.result.Result`.
638
638
@@ -654,20 +654,44 @@ def extract_result(
654
654
res_data = result [0 ].data
655
655
# res_data is a DataBin, which means all typechecking is out of the
656
656
# windows for this specific object
657
-
658
- # If we are in observable mode
659
- if hasattr (res_data , "evs" ):
660
- if job is None :
661
- job = Job (JobType .OBSERVABLE , QCircuit (0 ), device )
662
-
663
- mean = float (res_data .evs ) # pyright: ignore[reportAttributeAccessIssue]
664
- error = float (res_data .stds ) # pyright: ignore[reportAttributeAccessIssue]
665
- shots = (
666
- job .measure .shots
667
- if job .device .is_simulator () and job .measure is not None
668
- else result [0 ].metadata ["shots" ]
669
- )
670
- return Result (job , mean , error , shots )
657
+ all_results = []
658
+ res_data = result
659
+
660
+ results = res_data .evs if isinstance (res_data .evs , list ) else [res_data .evs ]
661
+ for single_result in results :
662
+ if hasattr (res_data , "evs" ): #
663
+ if job is None :
664
+ job = Job (JobType .OBSERVABLE , QCircuit (0 ), device )
665
+
666
+ mean = float (
667
+ single_result
668
+ ) # pyright: ignore[reportAttributeAccessIssue]
669
+ error = float (
670
+ res_data .stds
671
+ ) # pyright: ignore[reportAttributeAccessIssue]
672
+ shots = (
673
+ job .measure .shots
674
+ if job .device .is_simulator () and job .measure is not None
675
+ else result [0 ].metadata ["shots" ]
676
+ )
677
+ all_results .append (Result (job , mean , error , shots ))
678
+
679
+ if len (all_results ) > 1 :
680
+ return BatchResult (all_results )
681
+
682
+ return all_results [0 ]
683
+ # if hasattr(res_data, "evs"):
684
+ # if job is None:
685
+ # job = Job(JobType.OBSERVABLE, QCircuit(0), device)
686
+
687
+ # mean = float(res_data.evs) # pyright: ignore[reportAttributeAccessIssue]
688
+ # error = float(res_data.stds) # pyright: ignore[reportAttributeAccessIssue]
689
+ # shots = (
690
+ # job.measure.shots
691
+ # if job.device.is_simulator() and job.measure is not None
692
+ # else result[0].metadata["shots"]
693
+ # )
694
+ # return Result(job, mean, error, shots)
671
695
# If we are in sample mode
672
696
else :
673
697
if job is None :
0 commit comments