def test_Model_predict_percept_correctly_parallelizes(): # setup and time spatial model with 1 thread one_thread_spatial = Model(spatial=ValidSpatialModel(n_threads=1)).build() start_time_one_thread_spatial = time.perf_counter() one_thread_spatial.predict_percept(ArgusI()) one_thread_spatial_predict_time = time.perf_counter( ) - start_time_one_thread_spatial # setup and time spatial model with 2 threads two_thread_spatial = Model(spatial=ValidSpatialModel(n_threads=2)).build() start_time_two_thread_spatial = time.perf_counter() two_thread_spatial.predict_percept(ArgusI()) two_threaded_spatial_predict_time = time.perf_counter( ) - start_time_two_thread_spatial # we expect roughly a linear decrease in time as thread count increases npt.assert_almost_equal(actual=two_threaded_spatial_predict_time, desired=one_thread_spatial_predict_time / 2, decimal=1e-5) # setup and time temporal model with 1 thread one_thread_temporal = Model(temporal=ValidTemporalModel( n_threads=1)).build() start_time_one_thread_temporal = time.perf_counter() one_thread_temporal.predict_percept(ArgusI()) one_thread_temporal_predict_time = time.perf_counter( ) - start_time_one_thread_temporal # setup and time temporal model with 2 threads two_thread_temporal = Model(temporal=ValidTemporalModel( n_threads=2)).build() start_time_two_thread_temporal = time.perf_counter() two_thread_temporal.predict_percept(ArgusI()) two_thread_temporal_predict_time = time.perf_counter( ) - start_time_two_thread_temporal # we expect roughly a linear decrease in time as thread count increases npt.assert_almost_equal(actual=two_thread_temporal_predict_time, desired=one_thread_temporal_predict_time / 2, decimal=1e-5)
def test_Model_predict_percept(): # A None Model has nothing to build, nothing to perceive: model = Model() npt.assert_equal(model.predict_percept(ArgusI()), None) npt.assert_equal(model.predict_percept(ArgusI(stim={'A1': 1})), None) npt.assert_equal( model.predict_percept(ArgusI(stim={'A1': 1}), t_percept=[0, 1]), None) # Just the spatial model: model = Model(spatial=ValidSpatialModel()).build() npt.assert_equal(model.predict_percept(ArgusI()), None) # Just the temporal model: model = Model(temporal=ValidTemporalModel()).build() npt.assert_equal(model.predict_percept(ArgusI()), None) # Invalid calls: model = Model(spatial=ValidSpatialModel(), temporal=ValidTemporalModel()) with pytest.raises(NotBuiltError): # Must call build first: model.predict_percept(ArgusI()) model.build() with pytest.raises(ValueError): # Cannot request t_percepts that are not multiples of dt: model.predict_percept(ArgusI(stim=np.ones(16)), t_percept=[0.1, 0.11]) with pytest.raises(ValueError): # stim.time==None but requesting t_percept != None model.predict_percept(ArgusI(stim=np.ones(16)), t_percept=[0, 1, 2]) with pytest.raises(TypeError): # Must pass an implant: model.predict_percept(Stimulus(3))