Example #1
0
    def run(self,
            qobj: Qobj,
            job_name: Optional[str] = None,
            job_share_level: Optional[str] = None,
            job_tags: Optional[List[str]] = None) -> IBMQJob:
        """Run a Qobj asynchronously.

        Args:
            qobj: description of job.
            job_name: custom name to be assigned to the job. This job
                name can subsequently be used as a filter in the
                ``jobs()`` function call. Job names do not need to be unique.
                Default: None.
            job_share_level: allows sharing a job at the hub/group/project and
                global level. The possible job share levels are: "global", "hub",
                "group", "project", and "none".

                    * global: the job is public to any user.
                    * hub: the job is shared between the users in the same hub.
                    * group: the job is shared between the users in the same group.
                    * project: the job is shared between the users in the same project.
                    * none: the job is not shared at any level.

                If the job share level is not specified, then the job is not shared at any level.
            job_tags: tags to be assigned to the job. The tags can
                subsequently be used as a filter in the ``jobs()`` function call.
                Default: None.

        Returns:
            an instance derived from BaseJob

        Raises:
            SchemaValidationError: If the job validation fails.
            IBMQBackendApiError: If an unexpected error occurred while submitting
                the job.
            IBMQBackendApiProtocolError: If an unexpected value received from
                 the server.
            IBMQBackendValueError: If an input parameter value is not valid.
        """
        # pylint: disable=arguments-differ
        if job_share_level:
            try:
                api_job_share_level = ApiJobShareLevel(job_share_level.lower())
            except ValueError:
                raise IBMQBackendValueError(
                    '"{}" is not a valid job share level. '
                    'Valid job share levels are: {}'.format(
                        job_share_level,
                        ', '.join(level.value for level in ApiJobShareLevel)))
        else:
            api_job_share_level = ApiJobShareLevel.NONE

        validate_job_tags(job_tags, IBMQBackendValueError)
        validate_qobj_against_schema(qobj)
        return self._submit_job(qobj, job_name, api_job_share_level, job_tags)
Example #2
0
    def run(
            self,
            experiments: Union[List[QuantumCircuit], List[Schedule]],
            backend: IBMQBackend,
            name: Optional[str] = None,
            max_experiments_per_job: Optional[int] = None,
            job_share_level: Optional[str] = None,
            job_tags: Optional[List[str]] = None,
            **run_config: Any
    ) -> ManagedJobSet:
        """Execute a set of circuits or pulse schedules on a backend.

        The circuits or schedules will be split into multiple jobs. Circuits
        or schedules in a job will be executed together in each shot.

        Args:
            experiments: Circuit(s) or pulse schedule(s) to execute.
            backend: Backend to execute the experiments on.
            name: Name for this set of jobs.
                Each job within the set will have
                a job name that consists of the set name followed by a suffix.
                If not specified, the current date and time is used.
            max_experiments_per_job: Maximum number of experiments to run in each job.
                If not specified, the default is to use the maximum allowed by
                the backend.
                If the specified value is greater the maximum allowed by the
                backend, the default is used.
            job_share_level: Allow sharing the jobs at the hub, group, project, or
                global level. The level can be one of: ``global``, ``hub``,
                ``group``, ``project``, and ``none``.
            job_tags: Tags to be assigned to the jobs. The tags can
                subsequently be used as a filter in the
                :meth:`IBMQBackend.jobs()<qiskit.providers.ibmq.ibmqbackend.IBMQBackend.jobs()>`
                function call.
            run_config: Configuration of the runtime environment. Some
                examples of these configuration parameters include:
                ``qobj_id``, ``qobj_header``, ``shots``, ``memory``,
                ``seed_simulator``, ``qubit_lo_freq``, ``meas_lo_freq``,
                ``qubit_lo_range``, ``meas_lo_range``, ``schedule_los``,
                ``meas_level``, ``meas_return``, ``meas_map``,
                ``memory_slot_size``, ``rep_time``, and ``parameter_binds``.

                Refer to the documentation on :func:`qiskit.compiler.assemble`
                for details on these arguments.

        Returns:
            A :class:`ManagedJobSet` instance representing the set of jobs for
            the experiments.

        Raises:
            IBMQJobManagerInvalidStateError: If an input parameter value is not valid.
        """
        if (any(isinstance(exp, Schedule) for exp in experiments) and
                not backend.configuration().open_pulse):
            raise IBMQJobManagerInvalidStateError(
                'Pulse schedules found, but the backend does not support pulse schedules.')

        # Validate job share level
        if job_share_level:
            try:
                api_job_share_level = ApiJobShareLevel(job_share_level.lower())
            except ValueError:
                valid_job_share_levels_str = ', '.join(level.value for level in ApiJobShareLevel)
                raise IBMQJobManagerInvalidStateError(
                    '"{}" is not a valid job share level. Valid job share levels are: {}'.format(
                        job_share_level, valid_job_share_levels_str)) from None
        else:
            api_job_share_level = ApiJobShareLevel.NONE

        validate_job_tags(job_tags, IBMQJobManagerInvalidStateError)

        if not isinstance(backend, IBMQBackend):
            raise IBMQJobManagerInvalidStateError(
                "IBMQJobManager only supports IBMQBackend. "
                "{} is not an IBMQBackend.".format(backend))

        experiment_list = self._split_experiments(
            experiments, backend=backend, max_experiments_per_job=max_experiments_per_job)

        job_set = ManagedJobSet(name=name)
        job_set.run(experiment_list, backend=backend, executor=self._executor,
                    job_share_level=api_job_share_level, job_tags=job_tags, **run_config)
        self._job_sets.append(job_set)

        return job_set