Beispiel #1
0
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        self._controller = aer_controller_execute()

        # Update available methods and devices for class
        if AerSimulator._AVAILABLE_METHODS is None:
            AerSimulator._AVAILABLE_METHODS = available_methods(
                self._controller, AerSimulator._SIMULATION_METHODS)
        if AerSimulator._AVAILABLE_DEVICES is None:
            AerSimulator._AVAILABLE_DEVICES = available_devices(
                self._controller, AerSimulator._SIMULATION_DEVICES)

        # Default configuration
        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                AerSimulator._DEFAULT_CONFIGURATION)

        super().__init__(configuration,
                         properties=properties,
                         available_methods=AerSimulator._AVAILABLE_METHODS,
                         provider=provider,
                         backend_options=backend_options)
Beispiel #2
0
 def __init__(self, configuration=None, provider=None, **fields):
     super().__init__(
         configuration=(configuration or QasmBackendConfiguration.from_dict(
             self.DEFAULT_CONFIGURATION)),
         provider=provider,
         **fields,
     )
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        warn(
            'The `StatevectorSimulator` backend will be deprecated in the'
            ' future. It has been superseded by the `AerSimulator`'
            ' backend. To obtain legacy functionality initalize with'
            ' `AerSimulator(method="statevector")` and append run circuits'
            ' with the `save_state` instruction.', PendingDeprecationWarning)

        self._controller = statevector_controller_execute()

        if StatevectorSimulator._AVAILABLE_METHODS is None:
            StatevectorSimulator._AVAILABLE_METHODS = available_methods(
                self._controller, [
                    'automatic', 'statevector', 'statevector_gpu',
                    'statevector_thrust'
                ])
        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                StatevectorSimulator._DEFAULT_CONFIGURATION)
        else:
            configuration.open_pulse = False

        super().__init__(
            configuration,
            properties=properties,
            available_methods=StatevectorSimulator._AVAILABLE_METHODS,
            provider=provider,
            backend_options=backend_options)
Beispiel #4
0
    def _discover_remote_backends(self):
        """Return the remote backends available.

        Returns:
            dict[str:IBMQBackend]: a dict of the remote backend instances,
                keyed by backend name.
        """
        ret = OrderedDict()
        configs_list = self._api.available_backends()
        for raw_config in configs_list:
            try:
                if raw_config.get('open_pulse', False):
                    config = PulseBackendConfiguration.from_dict(raw_config)
                else:
                    config = QasmBackendConfiguration.from_dict(raw_config)
                backend_cls = IBMQSimulator if config.simulator else IBMQBackend
                ret[config.backend_name] = backend_cls(
                    configuration=config,
                    provider=self._ibm_provider,
                    credentials=self.credentials,
                    api=self._api)
            except ModelValidationError as ex:
                logger.warning(
                    'Remote backend "%s" could not be instantiated due to an '
                    'invalid config: %s',
                    raw_config.get('backend_name',
                                   raw_config.get('name', 'unknown')),
                    ex)

        return ret
Beispiel #5
0
    def __init__(self, backend, backend_name, local=True):
        """FakeBackend initializer.

        Args:
            backend (IBMQBackend): IBMQBackend instance
            backend_name (str): The name to give the backend.
            local (bool): Determines if Aer of IBMQ simulator should be used.
        """
        if backend.configuration().open_pulse:
            config = PulseBackendConfiguration.from_dict(backend.configuration().to_dict())
        else:
            config = QasmBackendConfiguration.from_dict(backend.configuration().to_dict())
        super().__init__(config)
        self._credentials = _Credentials()
        self._properties = backend.properties()
        self._configuration.simulator = True
        self._configuration.local = local
        self._configuration.backend_name = backend_name
        if AER_VERSION >= 60000:
            self.noise_model = NoiseModel.from_backend(self, warnings=False)
        else:
            self.noise_model = NoiseModel.from_backend(self)
        if local:
            self.sim = Aer.get_backend('qasm_simulator')
        else:
            pro = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
            self.sim = pro.backends.ibmq_qasm_simulator
Beispiel #6
0
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        self._controller = aer_controller_execute()

        # Update available methods and devices for class
        if AerSimulator._AVAILABLE_METHODS is None:
            AerSimulator._AVAILABLE_METHODS = available_methods(
                self._controller, AerSimulator._SIMULATION_METHODS)
        if AerSimulator._AVAILABLE_DEVICES is None:
            AerSimulator._AVAILABLE_DEVICES = available_devices(
                self._controller, AerSimulator._SIMULATION_DEVICES)

        # Default configuration
        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                AerSimulator._DEFAULT_CONFIGURATION)

        # Cache basis gates since computing the intersection
        # of noise model, method, and config gates is expensive.
        self._cached_basis_gates = self._BASIS_GATES['automatic']

        super().__init__(configuration,
                         properties=properties,
                         provider=provider,
                         backend_options=backend_options)
Beispiel #7
0
    def __init__(self, configuration=None, provider=None):
        super().__init__(configuration=(configuration
                                        or QasmBackendConfiguration.from_dict(
                                            self.DEFAULT_CONFIGURATION)),
                         provider=provider)

        # Define attributes in __init__.
        self._local_random = np.random.RandomState()
        self._classical_memory = 0
        self._classical_register = 0
        self._statevector = 0
        self._number_of_cmembits = 0
        self._number_of_qubits = 0
        self._shots = 0
        self._memory = False
        self._initial_statevector = self.DEFAULT_OPTIONS["initial_statevector"]
        self._chop_threshold = self.DEFAULT_OPTIONS["chop_threshold"]
        self._qobj_config = None
        # TEMP
        self._sample_measure = False

        if self.SPLIT_STATES:
            # _substates field will contain 2 statevectors corresponding to
            # measurement results 0 and 1
            self._substates = []
            self._substate_probabilities = []
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        warn('The `UnitarySimulator` backend will be deprecated in the'
             ' future. It has been superseded by the `AerSimulator`'
             ' backend. To obtain legacy functionality initialize with'
             ' `AerSimulator(method="unitary")` and append run circuits'
             ' with the `save_state` instruction.', PendingDeprecationWarning)

        self._controller = aer_controller_execute()

        if UnitarySimulator._AVAILABLE_DEVICES is None:
            UnitarySimulator._AVAILABLE_DEVICES = available_devices(
                self._controller, UnitarySimulator._SIMULATION_DEVICES)

        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                UnitarySimulator._DEFAULT_CONFIGURATION)
        else:
            configuration.open_pulse = False

        super().__init__(configuration,
                         properties=properties,
                         provider=provider,
                         backend_options=backend_options)
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        warn(
            'The `QasmSimulator` backend will be deprecated in the'
            ' future. It has been superseded by the `AerSimulator`'
            ' backend.', PendingDeprecationWarning)

        self._controller = qasm_controller_execute()

        # Update available methods for class
        if QasmSimulator._AVAILABLE_METHODS is None:
            QasmSimulator._AVAILABLE_METHODS = available_methods(
                self._controller, QasmSimulator._SIMULATION_METHODS)

        # Default configuration
        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                QasmSimulator._DEFAULT_CONFIGURATION)
        else:
            configuration.open_pulse = False

        super().__init__(configuration,
                         properties=properties,
                         available_methods=QasmSimulator._AVAILABLE_METHODS,
                         provider=provider,
                         backend_options=backend_options)
def configuration_from_server_data(
    raw_config: Dict,
    instance: str = "",
) -> Optional[Union[QasmBackendConfiguration, PulseBackendConfiguration]]:
    """Create an IBMBackend instance from raw server data.

    Args:
        raw_config: Raw configuration.
        instance: Service instance.

    Returns:
        Backend configuration.
    """
    # Make sure the raw_config is of proper type
    if not isinstance(raw_config, dict):
        logger.warning(  # type: ignore[unreachable]
            "An error occurred when retrieving backend "
            "information. Some backends might not be available.")
        return None
    try:
        _decode_backend_configuration(raw_config)
        try:
            return PulseBackendConfiguration.from_dict(raw_config)
        except (KeyError, TypeError):
            return QasmBackendConfiguration.from_dict(raw_config)
    except Exception:  # pylint: disable=broad-except
        logger.warning(
            'Remote backend "%s" for service instance %s could not be instantiated due to an '
            "invalid config: %s",
            raw_config.get("backend_name", raw_config.get("name", "unknown")),
            repr(instance),
            traceback.format_exc(),
        )
    return None
Beispiel #11
0
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        warn(
            'The `QasmSimulator` backend will be deprecated in the'
            ' future. It has been superseded by the `AerSimulator`'
            ' backend.', PendingDeprecationWarning)

        self._controller = aer_controller_execute()

        # Update available methods for class
        if QasmSimulator._AVAILABLE_METHODS is None:
            QasmSimulator._AVAILABLE_METHODS = available_methods(
                self._controller, QasmSimulator._SIMULATION_METHODS)

        # Default configuration
        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                QasmSimulator._DEFAULT_CONFIGURATION)
        else:
            configuration.open_pulse = False

        # Cache basis gates since computing the intersection
        # of noise model, method, and config gates is expensive.
        self._cached_basis_gates = self._DEFAULT_BASIS_GATES

        super().__init__(configuration,
                         properties=properties,
                         provider=provider,
                         backend_options=backend_options)
Beispiel #12
0
 def __init__(self, configuration=None, provider=None):
     super().__init__(
         controller=bdd_controller,
         configuration=QasmBackendConfiguration.from_dict(
             self.DEFAULT_CONFIGURATION),
         provider=provider,
     )
Beispiel #13
0
 def __init__(self):
     dirname = os.path.dirname(__file__)
     filename = "conf_rochester.json"
     with open(os.path.join(dirname, filename), "r") as f_conf:
         conf = json.load(f_conf)
     configuration = QasmBackendConfiguration.from_dict(conf)
     configuration.backend_name = 'fake_rochester'
     super().__init__(configuration)
Beispiel #14
0
    def __init__(self, configuration=None, provider=None):
        super().__init__(configuration=(
            configuration or QasmBackendConfiguration.from_dict(self.DEFAULT_CONFIGURATION)),
                         provider=provider)

        # Define attributes inside __init__.
        self._unitary = None
        self._number_of_qubits = 0
        self._initial_unitary = None
        self._chop_threshold = 1e-15
Beispiel #15
0
 def __init__(self):
     dirname = os.path.dirname(__file__)
     filename = "conf_santiago.json"
     with open(os.path.join(dirname, filename)) as f_conf:
         conf = json.load(f_conf)
     configuration = QasmBackendConfiguration.from_dict(conf)
     configuration.backend_name = 'fake_santiago'
     self._defaults = None
     self._properties = None
     super().__init__(configuration)
Beispiel #16
0
    def _method_configuration(method=None):
        """Return QasmBackendConfiguration."""
        # Default configuration
        config = QasmBackendConfiguration.from_dict(
            QasmSimulator._DEFAULT_CONFIGURATION)

        # Statevector methods
        if method in ['statevector', 'statevector_gpu', 'statevector_thrust']:
            config.description = 'A C++ QasmQobj statevector simulator with noise'

        # Density Matrix methods
        elif method in [
                'density_matrix', 'density_matrix_gpu', 'density_matrix_thrust'
        ]:
            config.n_qubits = config.n_qubits // 2
            config.description = 'A C++ QasmQobj density matrix simulator with noise'
            config.basis_gates = [
                'u1', 'u2', 'u3', 'u', 'p', 'r', 'rx', 'ry', 'rz', 'id', 'x',
                'y', 'z', 'h', 's', 'sdg', 'sx', 't', 'tdg', 'swap', 'cx',
                'cy', 'cz', 'cp', 'cu1', 'rxx', 'ryy', 'rzz', 'rzx', 'ccx',
                'unitary', 'diagonal', 'kraus', 'superop'
                'roerror', 'delay', 'pauli'
            ]

        # Matrix product state method
        elif method == 'matrix_product_state':
            config.description = 'A C++ QasmQobj matrix product state simulator with noise'
            config.basis_gates = [
                'u1', 'u2', 'u3', 'u', 'p', 'cp', 'cx', 'cz', 'id', 'x', 'y',
                'z', 'h', 's', 'sdg', 'sx', 't', 'tdg', 'swap', 'ccx',
                'unitary', 'roerror', 'delay', 'r', 'rx', 'ry', 'rz', 'rxx',
                'ryy', 'rzz', 'rzx'
            ]

        # Stabilizer method
        elif method == 'stabilizer':
            config.n_qubits = 5000  # TODO: estimate from memory
            config.description = 'A C++ QasmQobj Clifford stabilizer simulator with noise'
            config.basis_gates = [
                'id', 'x', 'y', 'z', 'h', 's', 'sdg', 'sx', 'cx', 'cy', 'cz',
                'swap', 'roerror', 'delay'
            ]

        # Extended stabilizer method
        elif method == 'extended_stabilizer':
            config.n_qubits = 63  # TODO: estimate from memory
            config.description = 'A C++ QasmQobj ranked stabilizer simulator with noise'
            config.basis_gates = [
                'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg', 'sx', 'swap',
                'u0', 'u1', 'p', 'ccx', 'ccz', 'roerror', 'delay'
            ]

        return config
Beispiel #17
0
 def __init__(self):
     """
      0 ↔ 1 ↔ 3 ↔ 4
          ↕
          2
     """
     dirname = os.path.dirname(__file__)
     filename = "conf_ourense.json"
     with open(os.path.join(dirname, filename)) as f_conf:
         conf = json.load(f_conf)
     configuration = QasmBackendConfiguration.from_dict(conf)
     configuration.backend_name = 'fake_ourense'
     super().__init__(configuration)
Beispiel #18
0
    def __init__(self, configuration=None, provider=None, **fields):
        super().__init__(configuration=(configuration
                                        or QasmBackendConfiguration.from_dict(
                                            self.DEFAULT_CONFIGURATION)),
                         provider=provider,
                         **fields)

        # Define attributes inside __init__.
        self._unitary = None
        self._number_of_qubits = 0
        self._initial_unitary = None
        self._global_phase = 0
        self._chop_threshold = self.options.get('chop_threshold')
Beispiel #19
0
    def __init__(self):
        """
            1
          / |
        0 - 2 - 3
            | /
            4
        """
        dirname = os.path.dirname(__file__)
        filename = "conf_yorktown.json"
        with open(os.path.join(dirname, filename), "r") as f_conf:
            conf = json.load(f_conf)

        configuration = QasmBackendConfiguration.from_dict(conf)
        configuration.backend_name = 'fake_yorktown'
        super().__init__(configuration)
Beispiel #20
0
    def __init__(self):
        """
         0 ↔ 1 ↔ 2
             ↕
             3
             ↕
             4
        """
        dirname = os.path.dirname(__file__)
        filename = "conf_essex.json"
        with open(os.path.join(dirname, filename), "r") as f_conf:
            conf = json.load(f_conf)

        configuration = QasmBackendConfiguration.from_dict(conf)
        configuration.backend_name = 'fake_essex'
        self._defaults = None
        self._properties = None
        super().__init__(configuration)
Beispiel #21
0
    def _discover_remote_backends(self,
                                  timeout: Optional[float] = None
                                  ) -> Dict[str, IBMQBackend]:
        """Return the remote backends available for this provider.

        Args:
            timeout: Maximum number of seconds to wait for the discovery of
                remote backends.

        Returns:
            A dict of the remote backend instances, keyed by backend name.
        """
        ret = OrderedDict()  # type: ignore[var-annotated]
        configs_list = self._api_client.list_backends(timeout=timeout)
        for raw_config in configs_list:
            # Make sure the raw_config is of proper type
            if not isinstance(raw_config, dict):
                logger.warning(
                    "An error occurred when retrieving backend "
                    "information. Some backends might not be available.")
                continue

            try:
                decode_backend_configuration(raw_config)
                if raw_config.get('open_pulse', False):
                    config = PulseBackendConfiguration.from_dict(raw_config)
                else:
                    config = QasmBackendConfiguration.from_dict(raw_config)
                backend_cls = IBMQSimulator if config.simulator else IBMQBackend
                ret[config.backend_name] = backend_cls(
                    configuration=config,
                    provider=self,
                    credentials=self.credentials,
                    api_client=self._api_client)
            except Exception as ex:  # pylint: disable=broad-except
                logger.warning(
                    'Remote backend "%s" for provider %s could not be instantiated due to an '
                    'invalid config: %s: %s',
                    raw_config.get('backend_name',
                                   raw_config.get('name', 'unknown')),
                    repr(self),
                    type(ex).__name__, ex)

        return ret
Beispiel #22
0
 def __init__(self, configuration=None, provider=None, **fields):
     super().__init__(configuration=(configuration
                                     or QasmBackendConfiguration.from_dict(
                                         self._configuration)),
                      provider=provider,
                      **fields)
     # Define attributes in __init__.
     self._local_random = np.random.RandomState()
     self._classical_memory = 0
     self._classical_register = 0
     self._statevector = 0
     self._number_of_cmembits = 0
     self._number_of_qubits = 0
     self._shots = 0
     self._memory = False
     self._initial_statevector = self.options.get("initial_statevector")
     self._qobj_config = None
     # TEMP
     self._sample_measure = False
    def __init__(self, configuration=None, provider=None):
        super().__init__(configuration=(
            configuration or QasmBackendConfiguration.from_dict(self.DEFAULT_CONFIGURATION)),
                         provider=provider)

        # Define attributes in __init__.
        self._local_random = np.random.RandomState()
        self._classical_memory = 0
        self._classical_register = 0
        self._statevector = 0
        self._number_of_cmembits = 0
        self._number_of_qubits = 0
        self._shots = 0
        self._memory = False
        self._initial_statevector = self.DEFAULT_OPTIONS["initial_statevector"]
        self._chop_threshold = self.DEFAULT_OPTIONS["chop_threshold"]
        self._qobj_config = None
        # TEMP
        self._sample_measure = False
    def _discover_remote_backends(self,
                                  timeout: Optional[float] = None
                                  ) -> Dict[str, IBMQBackend]:
        """Return the remote backends available.

        Args:
            timeout (float or None): number of seconds to wait for the discovery.

        Returns:
            dict[str:IBMQBackend]: a dict of the remote backend instances,
                keyed by backend name.
        """
        ret = OrderedDict()
        configs_list = self._api.list_backends(timeout=timeout)
        for raw_config in configs_list:
            # Make sure the raw_config is of proper type
            if not isinstance(raw_config, dict):
                logger.warning(
                    "An error occurred when retrieving backend "
                    "information. Some backends might not be available.")
                continue

            try:
                if raw_config.get('open_pulse', False):
                    config = PulseBackendConfiguration.from_dict(raw_config)
                else:
                    config = QasmBackendConfiguration.from_dict(raw_config)
                backend_cls = IBMQSimulator if config.simulator else IBMQBackend
                ret[config.backend_name] = backend_cls(
                    configuration=config,
                    provider=self,
                    credentials=self.credentials,
                    api=self._api)
            except ModelValidationError as ex:
                logger.warning(
                    'Remote backend "%s" could not be instantiated due to an '
                    'invalid config: %s',
                    raw_config.get('backend_name',
                                   raw_config.get('name', 'unknown')), ex)

        return ret
Beispiel #25
0
    def __init__(self):
        """
                   00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
                   ↕                    ↕
                   05                  06
                   ↕                    ↕
         07 ↔ 08 ↔ 09 ↔ 10 ↔ 11 ↔ 12 ↔ 13 ↔ 14 ↔ 15
         ↕                   ↕                    ↕
         16                  17                  18
         ↕                   ↕                    ↕
         19 ↔ 20 ↔ 21 ↔ 22 ↔ 23 ↔ 24 ↔ 25 ↔ 26 ↔ 27
        """
        dirname = os.path.dirname(__file__)
        filename = "conf_cambridge.json"
        with open(os.path.join(dirname, filename), "r") as f_conf:
            conf = json.load(f_conf)

        configuration = QasmBackendConfiguration.from_dict(conf)
        configuration.backend_name = 'fake_cambridge'
        self._defaults = None
        self._properties = None
        super().__init__(configuration)
    def __init__(self,
                 configuration=None,
                 properties=None,
                 provider=None,
                 **backend_options):

        self._controller = unitary_controller_execute()

        if UnitarySimulator._AVAILABLE_METHODS is None:
            UnitarySimulator._AVAILABLE_METHODS = available_methods(
                self._controller,
                ['automatic', 'unitary', 'unitary_gpu', 'unitary_thrust'])

        if configuration is None:
            configuration = QasmBackendConfiguration.from_dict(
                UnitarySimulator._DEFAULT_CONFIGURATION)

        super().__init__(configuration,
                         properties=properties,
                         available_methods=UnitarySimulator._AVAILABLE_METHODS,
                         provider=provider,
                         backend_options=backend_options)
 def __init__(self, configuration=None, provider=None):
     super().__init__(statevector_controller_execute,
                      QasmBackendConfiguration.from_dict(
                          self.DEFAULT_CONFIGURATION),
                      provider=provider)
Beispiel #28
0
 def __init__(self, little_endian=False):
     super().__init__(
         QasmBackendConfiguration.from_dict(self.CONFIGURATION), None)
     self.little_endian = little_endian
Beispiel #29
0
 def _get_config_from_dict(self, conf):
     return QasmBackendConfiguration.from_dict(conf)