Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GID assignment to transmitters involved in multiple connectivity sets #15

Merged
merged 10 commits into from
Sep 16, 2024

Conversation

danilobenozzo
Copy link
Contributor

For each connectivity set, kept track of GIDs grouped by pre-synaptic cell type.
If a pre-synaptic cell already has a GID for [cell, branch], it is re-used in the case of multiple synapses.

@danilobenozzo danilobenozzo requested review from Helveg and filimarc July 8, 2024 15:34
Copy link
Contributor

@Helveg Helveg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm creates a (N ^ 2) / 2 "triangle" of work: iteration 2 checks everything of iteration 1, iteration 3 checks all the works of iteration 1 and 2, iteration 4 checks everything of iteration 1, 2 and 3, and so on...

If you sort and concatenate all the data based on conn_model.pre_type at the start this extra work is avoided and you do not need to do any checking of the previously existing transmitters or updating/inserting any new data.

This approach may be advantageous for the peak memory consumption.

I propose to remove all the new code and instead do this:

        pre_types = set(cs.pre_type for cm in simulation.get_connectivity_sets().values())
        for pre_type in pre_types:
            data = []
            for cm, cs in simulation.get_connectivity_sets().items():
                if cs.pre_type != pre_type:
                    continue
                pre, _ = cs.load_connections().as_globals().all()
                data.append(pre[:, :2])
            
            all_cm_transmitters = np.unique(data, axis=0)
            # ... continue the algorithm like before, now that we have joined ALL the relevant data together

PS: I've noticed np.concatenate is kind of slow, so this utility function can help:

def better_concat(items):
    if not items:
        raise RuntimeError('Can not concat 0 items')
    l = sum(len(x) for x in items)
    r = np.empty((l, items[0].shape[1]), dtype=items[0].dtype)
    ptr = 0
    for x in items:
        r[ptr:ptr+len(x)] = x
        ptr += len(x)
    return r

@Helveg
Copy link
Contributor

Helveg commented Jul 13, 2024

The tests also show that somehow you're now placing transmitters with duplicate GIDs. I think more tests are the only way out of this precarious mess.

If you have any deadlines that depend on this code, perhaps you can use a fork with your previous code (which seemed to work? At least it didn't break the existing tests) and then at a later point you can finish this PR with the optimal implementation.

@Helveg
Copy link
Contributor

Helveg commented Jul 17, 2024

@filimarc @danilobenozzo could you add at least add a couple of test cases that test correct GID assigment and transmitter placement for single/multiple conn models with overlapping cell types etc?

@Helveg Helveg self-requested a review August 3, 2024 15:39
Copy link
Contributor

@Helveg Helveg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for approving, I see there's still some tests missing

Sorry for rejecting* there's tests, but they're failing :D

@danilobenozzo
Copy link
Contributor Author

yeah.. new config files are not being found.
I added them dbbs-lab/bsb-test#7 (comment) isn't this enough?

@filimarc
Copy link
Contributor

filimarc commented Aug 5, 2024

Hi, i will publish the bsb-test package with your new config so github can dowload it with pip. Btw i tried to run test on my PC but it fails the 4chunck test. with mpirun -n 2 python -m unittest discover -v -s ./tests :

ok
ok
test_double_sim_minimal (test_neuron.TestNeuronMinimal) ... test_double_sim_minimal (test_neuron.TestNeuronMinimal) ... ok
test_minimal (test_neuron.TestNeuronMinimal) ... ok
test_minimal (test_neuron.TestNeuronMinimal) ... ok
ok
test_500ch_multibranch_manualconn (test_neuron.TestNeuronMultiBranch)
Tests runnability of the NEURON adapter with 500 chunks filled with 12x3 single ... test_500ch_multibranch_manualconn (test_neuron.TestNeuronMultiBranch)
Tests runnability of the NEURON adapter with 500 chunks filled with 12x3 single ... ? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33fbecc40>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc4d22f880>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33fbed030>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc4d22e770>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33fbed120>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc4d22f5b0>
ok
ok
test_500ch_manualloop (test_neuron.TestNeuronMultiBranchLoop)
Tests runnability of the NEURON adapter with 500 chunks filled with 12x3 single ... test_500ch_manualloop (test_neuron.TestNeuronMultiBranchLoop)
Tests runnability of the NEURON adapter with 500 chunks filled with 12x3 single ... ? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33fb42500>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc50475570>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33fb42c80>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc50475600>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33fb42d70>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc505e0760>
ok
ok
test_4ch_manual (test_neuron.TestNeuronMultichunk)
Tests runnability of the NEURON adapter with 4 chunks filled with 12x3 single ... test_4ch_manual (test_neuron.TestNeuronMultichunk)
Tests runnability of the NEURON adapter with 4 chunks filled with 12x3 single ... ? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33882d090>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc504c17e0>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33882c040>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc504c29e0>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x7ec33882d570>
? <bsb_hdf5.chunks.ChunkedCollection object at 0x78fc504c2020>
0 NEURON: gid=0 already exists on this process as an output port
0 near line 0
0 ^
0 ParallelContext[0].set_gid2node(0, 0)

@danilobenozzo
Copy link
Contributor Author

danilobenozzo commented Aug 5, 2024

@filimarc ok now it should work

@Helveg
Copy link
Contributor

Helveg commented Aug 5, 2024

@filimarc filimarc linked an issue Sep 9, 2024 that may be closed by this pull request
@filimarc filimarc requested a review from Helveg September 9, 2024 10:07
@filimarc filimarc merged commit 3997d8a into main Sep 16, 2024
7 checks passed
@filimarc filimarc deleted the feature/transmap branch September 16, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AdapterError: no pop found for pre / post cell type
3 participants