qiskit/providers/basicaer/unitary_simulator.py
def _set_options(self, qobj_config=None, backend_options=None):
        """Set the backend options for all experiments in a qobj"""
        # Reset default options
        self._initial_unitary = self.DEFAULT_OPTIONS["initial_unitary"]
        self._chop_threshold = self.DEFAULT_OPTIONS["chop_threshold"]
        if backend_options is None:
            backend_options = {}

        # Check for custom initial statevector in backend_options first,
        # then config second
        if 'initial_unitary' in backend_options:
            self._initial_unitary = np.array(backend_options['initial_unitary'],
                                             dtype=complex)
        elif hasattr(qobj_config, 'initial_unitary'):
            self._initial_unitary = np.array(qobj_config.initial_unitary,
                                             dtype=complex)
        if self._initial_unitary is not None:
            # Check the initial unitary is actually unitary
            shape = np.shape(self._initial_unitary)
            if len(shape) != 2 or shape[0] != shape[1]:
                raise BasicAerError("initial unitary is not a square matrix")
            iden = np.eye(len(self._initial_unitary))
            u_dagger_u = np.dot(self._initial_unitary.T.conj(),
                                self._initial_unitary)
            norm = np.linalg.norm(u_dagger_u - iden)
            if round(norm, 10) != 0:
                raise BasicAerError("initial unitary is not unitary")
            # Check the initial statevector is normalized

        # Check for custom chop threshold
        # Replace with custom options
        if 'chop_threshold' in backend_options:
            self._chop_threshold = backend_options['chop_threshold']
        elif hasattr(qobj_config, 'chop_threshold'):
            self._chop_threshold = qobj_config.chop_threshold
def _set_options(self, qobj_config=None, backend_options=None):
        """Set the backend options for all experiments in a qobj"""
        # Reset default options
        self._initial_unitary = self.DEFAULT_OPTIONS["initial_unitary"]
        self._chop_threshold = self.DEFAULT_OPTIONS["chop_threshold"]
        if backend_options is None:
            backend_options = {}

        # Check for custom initial statevector in backend_options first,
        # then config second
        if 'initial_unitary' in backend_options:
            self._initial_unitary = np.array(backend_options['initial_unitary'],
                                             dtype=complex)
        elif hasattr(qobj_config, 'initial_unitary'):
            self._initial_unitary = np.array(qobj_config.initial_unitary,
                                             dtype=complex)
        if self._initial_unitary is not None:
            # Check the initial unitary is actually unitary
            shape = np.shape(self._initial_unitary)
            if len(shape) != 2 or shape[0] != shape[1]:
                raise BasicAerError("initial unitary is not a square matrix")
            iden = np.eye(len(self._initial_unitary))
            u_dagger_u = np.dot(self._initial_unitary.T.conj(),
                                self._initial_unitary)
            norm = np.linalg.norm(u_dagger_u - iden)
            if round(norm, 10) != 0:
                raise BasicAerError("initial unitary is not unitary")
            # Check the initial statevector is normalized

        # Check for custom chop threshold
        # Replace with custom options
        if 'chop_threshold' in backend_options:
            self._chop_threshold = backend_options['chop_threshold']
        elif hasattr(qobj_config, 'chop_threshold'):
            self._chop_threshold = qobj_config.chop_threshold
def _set_options ( self , qobj_config = None , backend_options = None ) : # Reset default options self . _initial_unitary = self . DEFAULT_OPTIONS [ "initial_unitary" ] self . _chop_threshold = self . DEFAULT_OPTIONS [ "chop_threshold" ] if backend_options is None : backend_options = { } # Check for custom initial statevector in backend_options first, # then config second if 'initial_unitary' in backend_options : self . _initial_unitary = np . array ( backend_options [ 'initial_unitary' ] , dtype = complex ) elif hasattr ( qobj_config , 'initial_unitary' ) : self . _initial_unitary = np . array ( qobj_config . initial_unitary , dtype = complex ) if self . _initial_unitary is not None : # Check the initial unitary is actually unitary shape = np . shape ( self . _initial_unitary ) if len ( shape ) != 2 or shape [ 0 ] != shape [ 1 ] : raise BasicAerError ( "initial unitary is not a square matrix" ) iden = np . eye ( len ( self . _initial_unitary ) ) u_dagger_u = np . dot ( self . _initial_unitary . T . conj ( ) , self . _initial_unitary ) norm = np . linalg . norm ( u_dagger_u - iden ) if round ( norm , 10 ) != 0 : raise BasicAerError ( "initial unitary is not unitary" ) # Check the initial statevector is normalized # Check for custom chop threshold # Replace with custom options if 'chop_threshold' in backend_options : self . _chop_threshold = backend_options [ 'chop_threshold' ] elif hasattr ( qobj_config , 'chop_threshold' ) : self . _chop_threshold = qobj_config . chop_threshold
Set the backend options for all experiments in a qobj
Set the backend options for all experiments in a qobj