Skip to content

Instantly share code, notes, and snippets.

@YukiSakamoto
Last active November 9, 2017 09:08
Show Gist options
  • Save YukiSakamoto/8f4c9ed445a9f233ed5f601bf50cbd67 to your computer and use it in GitHub Desktop.
Save YukiSakamoto/8f4c9ed445a9f233ed5f601bf50cbd67 to your computer and use it in GitHub Desktop.
test

2017.11.10

現状

ReactionRuleから、Descriptorがよびだせる。

呼び出し方・引数は、添付のコード参照。

次の対応

Gillespieのコード

  // 82行目付近
    if (next_reaction_.k() <= 0.0)
    {
        this->dt_ += dt; // skip a reaction
        return false;
    }

BDのコード

    // 84行目付近
   for (std::vector<ReactionRule>::const_iterator i(reaction_rules.begin());
         i != reaction_rules.end(); ++i)
    {
        const ReactionRule& rr(*i);
        prob += rr.k() * dt();
		// ...       

    }

このあたりを修正?

その他

  • ReactionRuleをコピーしたら、ReactionRuleDescriptorも(参照を渡すのではなく、)オブジェクトを複製する。このとき、Python Functionは、カウントをインクレメントする。

  • Pythonでflux()を呼ぶ=> C++ layer => Python Function という流れだと、どうしても化学種の量を含む配列(ベクタ)を2回も複製する必要が出てくる。これだとオーバーヘッドがあまりに大きいので、ReactionRule::flux()の呼び出しは、C++を経由せずにするのはいかがなものか。

from ecell4.core import *
def f(reactants, products, t):
return -1000.
rrd = ReactionRuleDescriptor(f)
L, k1 = 1.0, 1.0
sp1, sp2, sp3 = Species("A"), Species("B"), Species("C")
rr1 = ReactionRule([sp1, sp2], [sp3], k1)
rr1.set_descriptor(rrd)
n_sp1, n_sp2, n_sp3 = 0., 0., 0.
t = 0.
print("flux: ", rr1.flux([n_sp1, n_sp2], [n_sp3], t) )
@YukiSakamoto
Copy link
Author

YukiSakamoto commented Nov 9, 2017

s/flux/propensity/

@YukiSakamoto
Copy link
Author

@YukiSakamoto
Copy link
Author

@YukiSakamoto
Copy link
Author

YukiSakamoto commented Nov 9, 2017

if rr.has_descriptor() then rr.propencity()
else rr.k()
end
のような感じで。

@YukiSakamoto
Copy link
Author

YukiSakamoto commented Nov 9, 2017

次にやること
ODERatelawにできて、ReactionRuleDesctorにできないことを、後者に押し込む。
ODESimulatorで使えるようにしていく。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment