esi-neuroscience / syncopy

Systems Neuroscience Computing in Python: user-friendly analysis of large-scale electrophysiology data
BSD 3-Clause "New" or "Revised" License
48 stars 14 forks source link

Parallel computation precision #304

Open tensionhead opened 2 years ago

tensionhead commented 2 years ago

At least for the coherence, sequential and parallel computing do not give the same results:

import numpy as np                                                                                         
import syncopy as spy                                                                                      
import syncopy.tests.synth_data as synth_data                                                              
import dask.distributed as dd                                                                              

adata = synth_data.white_noise(nTrials=10,                                                                 
                                nSamples=100,                                                               
                                nChannels=2,                                                                
                                samplerate=200)                                                             

def test_seq():                                                                                            

    res = spy.connectivityanalysis(adata)                                                                  
    res2 = spy.connectivityanalysis(adata)                                                                 
    print()                                                                                                
    print("all equal:", np.all(res.data[:] == res2.data[:]))                                               
    print()                                                                                                

def test_parallel():                                                                                       

    client = dd.Client()                                                                                   
    test_seq()                                                                                             
    client.close()

This will give True for test_seq but False for test_parallel! No idea where to start to look even, coherences can have tricky denominators (if power at that freq. is almost 0), but no clue if that's the problem here.

tensionhead commented 2 years ago

So as for these connectivity measures the values are all between [-1, 1], and we have errors of about 1e-8 we can probably ignore this. However I'll keep it open, as we did not find the cause for this behavior.

tensionhead commented 1 year ago

Turns out, for Granger causality that can have effects of up to 1e-2, especially around the 0-frequency. Still not really problematic, but definitely noticable!