@@ -381,55 +381,6 @@ def resubmit(self) -> "Task":
381381
382382 return resubmit_task (self )
383383
384- @partial (arg_alias , alias_dict = {"format" : ["format_" ], "blocked" : ["wait" ]})
385- def m_results (
386- self ,
387- format : Optional [str ] = None ,
388- blocked : bool = True ,
389- mitigated : bool = False ,
390- calibriation_options : Optional [Dict [str , Any ]] = None ,
391- readout_mit : Optional [rem .ReadoutMit ] = None ,
392- mitigation_options : Optional [Dict [str , Any ]] = None ,
393- ) -> counts .ct :
394- """
395- get task results of the qjob
396-
397- :param format: unsupported now, defaults to None, which is "count_dict_bin"
398- :type format: Optional[str], optional
399- :param blocked: whether blocked to wait until the result is returned, defaults to False,
400- which raise error when the task is unfinished
401- :type blocked: bool, optional
402- :param mitigated: whether enable readout error mitigation, defaults to False
403- :type mitigated: bool, optional
404- :param calibriation_options: option dict for ``ReadoutMit.cals_from_system``,
405- defaults to None
406- :type calibriation_options: Optional[Dict[str, Any]], optional
407- :param readout_mit: if given, directly use the calibriation info on ``readout_mit``,
408- defaults to None
409- :type readout_mit: Optional[rem.ReadoutMit], optional
410- :param mitigation_options: option dict for ``ReadoutMit.apply_correction``, defaults to None
411- :type mitigation_options: Optional[Dict[str, Any]], optional
412- :return: count dict results
413- :rtype: Any
414- """
415- if not blocked :
416- s = self .state ()
417- if s != "completed" :
418- raise TaskUnfinished (self .id_ , s )
419- r = self .details ()["multi_result" ]
420- else :
421- s = self .state ()
422- tries = 0
423- while s != "completed" :
424- if s in ["failed" ]:
425- err = self .details ().get ("err" , "" )
426- raise TaskFailed (self .id_ , s , err )
427- time .sleep (0.5 + tries / 10 )
428- tries += 1
429- s = self .state ()
430- r = self .m_results (format = format , blocked = False , mitigated = False )
431-
432- return r # type: ignore
433384
434385 @partial (arg_alias , alias_dict = {"format" : ["format_" ], "blocked" : ["wait" ]})
435386 def results (
@@ -466,8 +417,16 @@ def results(
466417 s = self .state ()
467418 if s != "completed" :
468419 raise TaskUnfinished (self .id_ , s )
469- r = self .details ()["results" ]
470- r = counts .sort_count (r ) # type: ignore
420+ single_measz = "results" in self .details ()
421+ multi_measz = "multi_result" in self .details ()
422+ if not single_measz and not multi_measz :
423+ raise ValueError ("No results field in task details" )
424+ if single_measz :
425+ r = self .details ()["results" ]
426+ r = counts .sort_count (r ) # type: ignore
427+ if multi_measz :
428+ r = self .details ()["multi_result" ]
429+ r = [counts .sort_count (rr ) for rr in r ] # type: ignore
471430 else :
472431 s = self .state ()
473432 tries = 0
@@ -481,42 +440,47 @@ def results(
481440 r = self .results (format = format , blocked = False , mitigated = False )
482441 if mitigated is False :
483442 return r # type: ignore
484- nqubit = len (list (r .keys ())[0 ])
485-
486- # mitigated is True:
487- device = self .get_device ()
488- if device .provider .name != "tencent" :
489- raise ValueError ("Only tencent provider supports auto readout mitigation" )
490- if readout_mit is None and getattr (device , "readout_mit" , None ) is None :
491-
492- def run (cs : Any , shots : Any ) -> Any :
493- """
494- current workaround for batch
495- """
496- from .apis import submit_task
497-
498- ts = submit_task (circuit = cs , shots = shots , device = device .name + "?o=0" )
499- return [t .results (blocked = True ) for t in ts ] # type: ignore
500-
501- shots = self .details ()["shots" ]
502- readout_mit = rem .ReadoutMit (run )
503- if calibriation_options is None :
504- calibriation_options = {}
505- readout_mit .cals_from_system (
506- list (range (nqubit )), shots , ** calibriation_options
443+ def mitigated_assertion (rr : Any ) -> None :
444+ nqubit = len (list (r .keys ())[0 ])
445+
446+ # mitigated is True:
447+ device = self .get_device ()
448+ if device .provider .name != "tencent" :
449+ raise ValueError ("Only tencent provider supports auto readout mitigation" )
450+ if readout_mit is None and getattr (device , "readout_mit" , None ) is None :
451+
452+ def run (cs : Any , shots : Any ) -> Any :
453+ """
454+ current workaround for batch
455+ """
456+ from .apis import submit_task
457+
458+ ts = submit_task (circuit = cs , shots = shots , device = device .name + "?o=0" )
459+ return [t .results (blocked = True ) for t in ts ] # type: ignore
460+
461+ shots = self .details ()["shots" ]
462+ readout_mit = rem .ReadoutMit (run )
463+ if calibriation_options is None :
464+ calibriation_options = {}
465+ readout_mit .cals_from_system (
466+ list (range (nqubit )), shots , ** calibriation_options
467+ )
468+ device .readout_mit = readout_mit
469+ elif readout_mit is None :
470+ readout_mit = device .readout_mit
471+
472+ if mitigation_options is None :
473+ try :
474+ mitigation_options = {
475+ "logical_physical_mapping" : self .details ()["optimization" ]["pairs" ]
476+ }
477+ except KeyError :
478+ mitigation_options = {}
479+ return readout_mit .apply_correction (
480+ r , list (range (nqubit )), ** mitigation_options
507481 )
508- device .readout_mit = readout_mit
509- elif readout_mit is None :
510- readout_mit = device .readout_mit
511-
512- if mitigation_options is None :
513- try :
514- mitigation_options = {
515- "logical_physical_mapping" : self .details ()["optimization" ]["pairs" ]
516- }
517- except KeyError :
518- mitigation_options = {}
519- miti_count = readout_mit .apply_correction (
520- r , list (range (nqubit )), ** mitigation_options
521- )
522- return counts .sort_count (miti_count )
482+ if single_measz :
483+ miti_count = mitigated_assertion (r )
484+ return counts .sort_count (miti_count ) # type: ignore
485+ if multi_measz :
486+ return [counts .sort_count (mitigated_assertion (rr )) for rr in r ] # type: ignore
0 commit comments