arbor-sim/arbor

Unclear error when `arbor.lif_cell` is mistaken for `arbor.cell_kind.lif`

Closed this issue · 5 comments

Helveg commented
def get_cell_kind(self, gid):
  return arbor.lif_cell

I ran into this error:

    self.domain = arbor.partition_load_balance(recipe, context)
RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)

If it had not been the only change I made since the last run I'd have no idea what caused this error.

So, you had this:

class recipe(A.recipe):
  def get_cell_kind(self, gid):
    return A.lif_cell
  def get_cell_description(self, gid):
    return A.cable_cell(...)

?

Helveg commented

I had

class recipe(A.recipe):
  def get_cell_kind(self, gid):
    return A.lif_cell
  def get_cell_description(self, gid):
    return A.lif_cell(...)

while I should have had

class recipe(A.recipe):
  def get_cell_kind(self, gid):
    return A.cell_kind.lif
  def get_cell_description(self, gid):
    return A.lif_cell(...)

So, the issue is that we rely on the kind to do an any_cast. The error should be better though, sure!

Hm, so here, trying something similar (swapping cable for lif in the brunel example I get

❯ python3 ..prunel.py
<arbor.context: num_threads 8, has_gpu False, has_mpi False, num_ranks 1>
<arbor.domain_decomposition: domain_id 0, num_domains 1, num_local_cells 500, num_global_cells 500, groups 500>
Traceback (most recent call last):
  File "brunel.py", line 261, in <module>
    sim = arbor.simulation(recipe, context, decomp)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: recipe::get_cell_kind(gid=493) -> cell_kind::cable does not match the cell type provided by recipe::get_cell_description(gid=493)

which is completely within my expectations.

Could you provide a small (!) example where this error occurs?

Oh dear, now I got your issue. You return a class object where an enum is required. I made a custom message
as this method is intertwined with the cell_description one and I expect some stumbling. See #2219