1

I'm performing a simulation of protein-protein interactions. I'm using Python to code logic gates as functions to model protein interactions. My model is basically a series of groups (g0 to g4) containing logic gates (see image). Initially, I set up a list containing my groups, and then for each group a dict that contains proteins (nodes) with their starting values (their so-called seedValues, which are the starting parameters for the network at t=0).

My question is this: is there some way of iterating through my groups (and their logic gate functions), that begins at group 0 (g0 in the image) at t, and that at t=t+1 executes groups g0 and g1, then executes the three groups g0, g1 and g2 at t=t+2, and so on until t=m, where m is the number of iterations wanted?

Clarification: Perhaps I am unclear. My problem is this: say that I write a function that steps through my groups, one at a time. It starts at g0 at time t=0, and executes, stores and outputs all the gates in that group, plus all the gates "ahead" of itself (g1 to g4). When this is done, the function ticks time one step forward (t=t+1) and goes to g1 and exeuctes again, including outputting groups g2 to g4. Now is where an error creeps in: for an accurate model, I need to execute g0 at time t=t+1 too, before the program steps to g2. How can I make my program output such sequential "waves" of execution? I imagine I might need to use recursion, but I don't know how.

See example image of what I mean with "groups" here. Image notes: A and B are switches (the program is supposed to change them, as a way of studying perturbations), C is a constant (never changed). J is the output (mostly for show). D and F are built that way to oscillate, whenever A = 0.

I have searched for this on Stack Exchange and Stack Overflow; while I see many questions that tangent my area of interest (1, 2), I don't see any that I determine specifically solve my problems. Thank you for your time.

Community
  • 1
  • 1
  • Probably I'm missing something here. The only good reason to create a multithread/multiprocess program Is performance. If you haven't written the program yet, how do you know it's not fast enough? Just because the circuit components function in parallel doesn't mean the internal structure of your program must do the calculations in parallel. What matters is that the program produces an accurate model of what the circuit (protein) does. Why complicate your task by writing a multithreaded program? – Paul Cornelius Apr 08 '16 at 08:01
  • I have updated my question to better reflect what I am looking to do. Please see my clarification in the original question. – Sebastian Hansen Apr 08 '16 at 08:49

2 Answers2

0

It seems to me your problem reduces to a couple of nested loops. If you put all the groups into a list named gx, and you increment time t in steps from 0 to some value tmax, it looks like this in Python...

for t in range(tmax):
    for i in range(t):
        nodeExecute(gx[i])

Each time you increment t, one more group gets executed in addition to all the previous ones. Apologies if I still haven't understood.

Paul Cornelius
  • 9,245
  • 1
  • 15
  • 24
0

For event-driven digital simulation or discrete event simulation, a "time wheel" or "timing wheel" is often used as basic data structure. The wheel is basically an array where every element points to a list or dynamic vector of simulated events which share the same value for "time mod wheelsize".

Timewheel as depicted here: enter image description here

A timewheel is more efficient than a priority queue, which could also be used to process the simulation events in ascending order of their timestamps.

Pseudo-code of event-driven logic simulation:

t = tStart
While (t < tEnd) {
    process all events scheduled for t and schedule follow-up events
    schedule events from signal sources
    t = t + 1
}

To handle the grouping of gates, you could treat each group as a super-gate with multiple outputs. It might be necessary to model different latency delays within a given group of gates.

Rather than writing your own simulator, you could describe your circuit in a Hardware Description Language like Verilog and use a ready-made simulator.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54
  • This seems like a great approach to my question. Just like your excellent answer suggests, I've chosen to model my gates in a series of groups, where one group is executed per time step. I describe it graphically ![like this](http://i.imgur.com/4dCtTqm.jpg), which corresponds pretty well with the event-driven data structures you suggested. Thank you for your input! – Sebastian Hansen Apr 11 '16 at 08:14