def test_supported_fingerprinting(cls, monkeypatch): # patch so we can instantiate various solvers without the proper libraries monkeypatch.setitem(sys.modules, "scipy", Mock()) monkeypatch.setitem(sys.modules, "scipy.optimize", Mock()) monkeypatch.setitem(sys.modules, "sklearn", Mock()) monkeypatch.setitem(sys.modules, "sklearn.linear_model", Mock()) monkeypatch.setitem(sys.modules, "sklearn.utils", Mock()) monkeypatch.setitem(sys.modules, "sklearn.utils.extmath", Mock()) obj = cls() assert Fingerprint.supports(obj) # check fingerprint is created without error and is a valid sha1 hash fp = str(Fingerprint(obj)) assert len(fp) == 40 and set(fp).issubset("0123456789abcdef")
def test_supported_fingerprinting(cls, monkeypatch): # patch so we can instantiate various solvers without the proper libraries monkeypatch.setitem(sys.modules, "scipy", Mock()) monkeypatch.setitem(sys.modules, "scipy.optimize", Mock()) monkeypatch.setitem(sys.modules, "sklearn", Mock()) monkeypatch.setitem(sys.modules, "sklearn.linear_model", Mock()) monkeypatch.setitem(sys.modules, "sklearn.utils", Mock()) monkeypatch.setitem(sys.modules, "sklearn.utils.extmath", Mock()) args = [] if issubclass(cls, nengo.neurons.RatesToSpikesNeuronType): # spiking types require a `base_type` argument, so provide one args.append(nengo.neurons.RectifiedLinear()) obj = cls(*args) assert Fingerprint.supports(obj) # check fingerprint is created without error and is a valid sha1 hash fp = str(Fingerprint(obj)) assert len(fp) == 40 and set(fp).issubset("0123456789abcdef")
def tune(self, dt, model, ens): from nengo_bio.internal.multi_compartment_lif_sim import GaussianSource from nengo_bio.internal.model_weights import tune_two_comp_model_weights # Fetch the maximum rates for which we need to determine the neuron # parameters max_rates = model.params[ens].max_rates if isinstance(ens.max_rates, Uniform): min_max_rate = ens.max_rates.low max_max_rate = ens.max_rates.high else: min_max_rate = np.min(max_rates) max_max_rate = np.max(max_rates) # Get the parameter hash params_hash = str(Fingerprint([self, dt])) # Function running a single neuron simulation sim_class = self._compile(dt) def run_single_sim(idx, out, in_exc, in_inh): xs = np.asarray((in_exc, in_inh), order='C', dtype=np.float64) # TODO: Get these parameters from the connection sim_class().run_single_with_gaussian_sources( out, [ GaussianSource( seed=4902 + idx, mu=in_exc * 0.95, sigma=in_exc * 0.5, tau=5e-3, offs=0.0), GaussianSource( seed=5821 + 7 * idx, mu=in_inh * 0.95, sigma=in_inh * 0.5, tau=5e-3, offs=0.0), ]) return tune_two_comp_model_weights( dt=dt, max_rates=max_rates, min_max_rate=min_max_rate, max_max_rate=max_max_rate, run_single_sim=run_single_sim, estimate_input_range=self._estimate_input_range, filter_input=self._filter_input, lif_rate_inv=self._lif_rate_inv, params_hash=params_hash)
def test_fails_for_lambda_expression(): with pytest.raises(FingerprintError): Fingerprint(lambda x: x)
def test_unsupported_fingerprinting(obj): with pytest.raises(FingerprintError): Fingerprint(obj)
def test_fingerprinting(reference, equal, different): assert str(Fingerprint(reference)) == str(Fingerprint(equal)) assert str(Fingerprint(reference)) != str(Fingerprint(different))
1., 1., )) # Normalise ws[1] = 1 ws = ws / ws[1] return ws def _params_den(self): return multi_compartment_lif_parameters.DendriticParameters.\ make_two_comp_lif( C_som=self.C_som, C_den=self.C_den, g_leak_som=self.g_leak_som, g_leak_den=self.g_leak_den, g_couple=self.g_couple, E_rev_leak=self.E_rev_leak, E_rev_exc=self.E_rev_exc, E_rev_inh=self.E_rev_inh ) # Alias for TwoCompLIF emphasizing the use of conductance based synapses TwoCompLIFCond = TwoCompLIF # Whitelist the neuron types Fingerprint.whitelist(LIF) Fingerprint.whitelist(LIFCond) Fingerprint.whitelist(TwoCompLIF)
def test_fails_for_lambda_expression(): with pytest.raises(FingerprintError, match="cannot be fingerprinted"): Fingerprint(lambda x: x)
def test_unsupported_fingerprinting(obj): with pytest.raises(FingerprintError, match="cannot be fingerprinted"): Fingerprint(obj)
def test_fails_for_lambda_expression(): with pytest.raises((ValueError, AttributeError)): Fingerprint(lambda x: x)