def __init__(self, t1, initial_prob1=None, readout0to1=None, readout1to0=None, dt_factor=None): """ Initialize the T1 backend """ dt_factor_in_ns = dt_factor * 1e9 if dt_factor is not None else None configuration = QasmBackendConfiguration( backend_name="t1_simulator", backend_version="0", n_qubits=int(1e6), basis_gates=["barrier", "x", "delay", "measure"], gates=[], local=True, simulator=True, conditional=False, open_pulse=False, memory=False, max_shots=int(1e6), coupling_map=None, dt=dt_factor_in_ns, ) self._t1 = t1 self._initial_prob1 = initial_prob1 self._readout0to1 = readout0to1 self._readout1to0 = readout1to0 self._dt_factor = dt_factor super().__init__(configuration)
def __init__(self): """ 0 ← 1 → 2 → 3 ← 4 ← 5 → 6 ↑ ↑ ↑ ↓ ↓ ↓ 13 → 12 ← 11 → 10 ← 9 → 8 ← 7 """ cmap = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]] configuration = QasmBackendConfiguration( backend_name='fake_melbourne', backend_version='0.0.0', n_qubits=14, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, max_experiments=900, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
def __init__(self, t1, initial_prob1=None, readout0to1=None, readout1to0=None): """ Initialize the T1 backend """ configuration = QasmBackendConfiguration( backend_name="t1_simulator", backend_version="0", n_qubits=int(1e6), basis_gates=["barrier", "x", "delay", "measure"], gates=[], local=True, simulator=True, conditional=False, open_pulse=False, memory=False, max_shots=int(1e6), coupling_map=None, ) self._t1 = t1 self._initial_prob1 = initial_prob1 self._readout0to1 = readout0to1 self._readout1to0 = readout1to0 self._rng = np.random.default_rng(0) super().__init__(configuration)
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): """ 0 ↔ 1 ↔ 3 ↔ 4 ↕ 2 """ cmap = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] configuration = QasmBackendConfiguration( backend_name='fake_ourense', backend_version='0.0.0', n_qubits=5, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, max_experiments=900, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
def __init__(self): """ 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 | | | | | | | | 0 - 15 - 14 - 13 - 12 - 11 - 10 - 9 """ cmap = [[1, 0], [1, 2], [2, 3], [3, 4], [3, 14], [5, 4], [6, 5], [6, 7], [6, 11], [7, 10], [8, 7], [9, 8], [9, 10], [11, 10], [12, 5], [12, 11], [12, 13], [13, 4], [13, 14], [15, 0], [15, 2], [15, 14]] configuration = QasmBackendConfiguration( backend_name='fake_rueschlikon', backend_version='0.0.0', n_qubits=16, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
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)
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)
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
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, p0=None, initial_prob_plus=None, readout0to1=None, readout1to0=None, ): """ Initialize the T2Ramsey backend """ configuration = QasmBackendConfiguration( backend_name="T2Ramsey_simulator", backend_version="0", n_qubits=int(1e6), basis_gates=["barrier", "h", "p", "delay", "measure"], gates=[], local=True, simulator=True, conditional=False, open_pulse=False, memory=False, max_shots=int(1e6), coupling_map=None, ) self._t2ramsey = p0["T2star"] self._a_param = p0["A"] self._freq = p0["f"] self._phi = p0["phi"] self._b_param = p0["B"] self._initial_prob_plus = initial_prob_plus self._readout0to1 = readout0to1 self._readout1to0 = readout1to0 self._rng = np.random.default_rng(0) super().__init__(configuration)
def __init__(self): """ 1 → 2 → 3 → 4 ← 5 ← 6 → 7 ← 8 ↓ ↑ ↓ ↓ ↑ ↓ ↓ ↑ 0 ← 15 → 14 ← 13 ← 12 → 11 → 10 ← 9 """ cmap = [[1, 0], [1, 2], [2, 3], [3, 4], [3, 14], [5, 4], [6, 5], [6, 7], [6, 11], [7, 10], [8, 7], [9, 8], [9, 10], [11, 10], [12, 5], [12, 11], [12, 13], [13, 4], [13, 14], [15, 0], [15, 2], [15, 14]] configuration = QasmBackendConfiguration( backend_name='fake_rueschlikon', backend_version='0.0.0', n_qubits=16, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, max_experiments=900, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
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): """ 1 / | 0 - 2 - 3 | / 4 """ cmap = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]] configuration = QasmBackendConfiguration( backend_name='fake_tenerife', backend_version='0.0.0', n_qubits=5, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
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 __init__(self): """ 0 - 1 - 2 - 3 - 4 - 5 - 6 | | | | | | 13 - 12 - 11 - 10 - 9 - 8 - 7 """ cmap = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]] configuration = QasmBackendConfiguration( backend_name='fake_melbourne', backend_version='0.0.0', n_qubits=14, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
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)
def __init__(self): cmap = [[0, 1], [0, 5], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3], [4, 9], [5, 0], [5, 6], [5, 10], [6, 5], [6, 7], [7, 6], [7, 8], [7, 12], [8, 7], [8, 9], [9, 4], [9, 8], [9, 14], [10, 5], [10, 11], [10, 15], [11, 10], [11, 12], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14], [14, 9], [14, 13], [14, 19], [15, 10], [15, 16], [16, 15], [16, 17], [17, 16], [17, 18], [18, 17], [18, 19], [19, 14], [19, 18]] configuration = QasmBackendConfiguration( backend_name='fake_poughkeepsie', backend_version='0.0.0', n_qubits=20, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=True, max_shots=8192, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
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
def __init__(self, configuration=None, provider=None): super().__init__( controller=bdd_controller, configuration=QasmBackendConfiguration.from_dict( self.DEFAULT_CONFIGURATION), provider=provider, )
def __init__(self): """ .. code-block:: text 1 ↙ ↑ 0 ← 2 ← 3 ↑ ↙ 4 """ cmap = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]] configuration = QasmBackendConfiguration( backend_name="fake_tenerife", backend_version="0.0.0", n_qubits=5, basis_gates=["u1", "u2", "u3", "cx", "id"], simulator=False, local=True, conditional=False, open_pulse=False, memory=False, max_shots=65536, max_experiments=900, gates=[GateConfig(name="TODO", parameters=[], qasm_def="TODO")], coupling_map=cmap, ) super().__init__(configuration)
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
def __init__( self, t2hahn=None, frequency=None, initialization_error=None, readout0to1=None, readout1to0=None, ): """ Initialize the T2Hahn backend """ configuration = QasmBackendConfiguration( backend_name="T2Hahn_simulator", backend_version="0", n_qubits=int(1e6), basis_gates=["barrier", "rx", "delay", "measure"], gates=[], local=True, simulator=True, conditional=False, open_pulse=False, memory=False, max_shots=int(1e6), coupling_map=None, ) self._t2hahn = t2hahn self._frequency = frequency self._initialization_error = initialization_error self._readout0to1 = readout0to1 self._readout1to0 = readout1to0 self._rng = np.random.default_rng(seed=SEED) super().__init__(configuration)
def __init__(self): """ 00 ↔ 01 ↔ 02 ↔ 03 ↔ 04 ↕ ↕ 05 ↔ 06 ↔ 07 ↔ 08 ↔ 09 ↕ ↕ ↕ 10 ↔ 11 ↔ 12 ↔ 13 ↔ 14 ↕ ↕ 15 ↔ 16 ↔ 17 ↔ 18 ↔ 19 """ cmap = [[0, 1], [1, 0], [1, 2], [1, 6], [2, 1], [2, 3], [3, 2], [3, 4], [3, 8], [4, 3], [5, 6], [5, 10], [6, 1], [6, 5], [6, 7], [7, 6], [7, 8], [7, 12], [8, 3], [8, 7], [8, 9], [9, 8], [9, 14], [10, 5], [10, 11], [11, 10], [11, 12], [11, 16], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14], [13, 18], [14, 9], [14, 13], [15, 16], [16, 11], [16, 15], [16, 17], [17, 16], [17, 18], [18, 13], [18, 17], [18, 19], [19, 18]] configuration = QasmBackendConfiguration( backend_name='fake_boeblingen', backend_version='0.0.0', n_qubits=20, basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], simulator=False, local=True, conditional=False, open_pulse=False, memory=True, max_shots=8192, gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], coupling_map=cmap, ) super().__init__(configuration)
def test_deprecate_id_instruction(self): """Test replacement of 'id' Instructions with 'Delay' instructions.""" circuit_with_id = QuantumCircuit(2) circuit_with_id.id(0) circuit_with_id.id(0) circuit_with_id.id(1) config = QasmBackendConfiguration( basis_gates=["id"], supported_instructions=["delay"], dt=0.25, backend_name="test", backend_version="0.0", n_qubits=1, gates=[], local=False, simulator=False, conditional=False, open_pulse=False, memory=False, max_shots=1, coupling_map=[], ) with patch.object(self.backend, "configuration", return_value=config): with self.assertWarnsRegex(DeprecationWarning, r"'id' instruction"): mutated_circuit = self.backend._deprecate_id_instruction( circuit_with_id) self.assertEqual(mutated_circuit[0].count_ops(), {"delay": 3}) self.assertEqual(circuit_with_id.count_ops(), {"id": 3})
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)
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)
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
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)
def test_backend_default_configuration(self): simulator = QuantumInspireBackend(Mock(), Mock()) configuration = simulator.configuration() expected_configuration = QasmBackendConfiguration( backend_name='qi_simulator', backend_version=quantum_inspire_version, n_qubits=26, basis_gates=['x', 'y', 'z', 'h', 'rx', 'ry', 'rz', 's', 'sdg', 't', 'tdg', 'cx', 'ccx', 'u1', 'u2', 'u3', 'id', 'swap', 'cz', 'snapshot'], gates=[GateConfig(name='NotUsed', parameters=['NaN'], qasm_def='NaN')], conditional=True, simulator=True, local=False, memory=True, open_pulse=False, max_shots=1024, max_experiments=1, coupling_map=None ) self.assertDictEqual(configuration.to_dict(), expected_configuration.to_dict())