def _run_job(self, qobj):
     """Run a Qobj on the backend."""
     self._validate(qobj)
     final_state_key = 32767  # Internal key for final state snapshot
     # Add final snapshots to circuits
     for experiment in qobj.experiments:
         experiment.instructions.append(
             QobjInstruction.from_dict({
                 'name': '#snapshot',
                 'params': [final_state_key]
             }))
     result = super()._run_job(qobj)
     # Extract final state snapshot and move to 'statevector' data field
     for res in result._result['result']:
         snapshots = res['data']['snapshots']
         if str(final_state_key) in snapshots:
             final_state_key = str(final_state_key)
         # Pop off final snapshot added above
         final_state = snapshots.pop(final_state_key, None)
         final_state = final_state['statevector'][0]
         # Add final state to results data
         res['data']['statevector'] = final_state
         # Remove snapshot dict if empty
         if snapshots == {}:
             res['data'].pop('snapshots', None)
     return result
示例#2
0
 def _run_job(self, qobj):
     """Run a Qobj on the backend."""
     self._validate(qobj)
     final_state_key = 32767  # Internal key for final state snapshot
     # Add final snapshots to circuits
     for circuit in qobj.circuits:
         circuit.compiled_circuit.operations.append(
             QobjInstruction.from_dict({
                 'name': 'snapshot',
                 'params': [final_state_key]
             }))
     result = super()._run_job(qobj)._result
     # Replace backend name with current backend
     result['backend'] = self._configuration['name']
     # Extract final state snapshot and move to 'statevector' data field
     for res in result['result']:
         snapshots = res['data']['snapshots']
         if str(final_state_key) in snapshots:
             final_state_key = str(final_state_key)
         # Pop off final snapshot added above
         final_state = snapshots.pop(final_state_key, None)
         final_state = final_state['statevector'][0]
         # Add final state to results data
         res['data']['statevector'] = final_state
         # Remove snapshot dict if empty
         if snapshots == {}:
             res['data'].pop('snapshots', None)
     return Result(result)
    def _run_job(self, job_id, qobj):
        """Run circuits in qobj and return the result

            Args:
                qobj (Qobj): Qobj structure
                job_id (str): A job id

            Returns:
                qiskit.Result: Result is a class including the information to be returned to users.
                    Specifically, result_list in the return contains the essential information,
                    which looks like this::

                        [{'data':
                        {
                          'statevector': array([sqrt(2)/2, 0, 0, sqrt(2)/2], dtype=object),
                        },
                        'status': 'DONE'
                        }]
        """

        self._validate(qobj)
        final_state_key = '32767'  # Internal key for final state snapshot
        # Add final snapshots to circuits
        for circuit in qobj.experiments:
            circuit.instructions.append(
                QobjInstruction.from_dict({
                    'name': 'snapshot',
                    'params': [final_state_key]
                }))
        qobj.config.shots = 1
        result_dict = super()._run_job(job_id, qobj).to_dict()
        # Extract final state snapshot and move to 'statevector' data field
        for res in result_dict['results']:
            snapshots = res['data']['snapshots']
            # Pop off final snapshot added above
            final_state = snapshots.pop(final_state_key, None)
            final_state = final_state['statevector'][0]
            # Add final state to results data
            res['data']['statevector'] = final_state
            # Remove snapshot dict if empty
            if snapshots == {}:
                res['data'].pop('snapshots', None)

        return Result.from_dict(result_dict)