#๐Ÿ”’ Why is numba not working? I don't even know anymore I've tried everything.

15 messages ยท Page 1 of 1 (latest)

pseudo urchin
#

This is the function I'm trying to call


@njit
def reactor_metrics(array, fuel, reactor_block_properties, reactor_fuel_type):
    x_max, y_max, z_max = array.shape
    total_fuel_cells = 0
    total_neighbor = 0.0
    total_heat_multiplier = 0.0
    power = 0.0
    heat = 0.0
    total_cooling = 0.0
    
    for x in range(x_max):
        for y in range(y_max):
            for z in range(z_max):
                element = int(array[x, y, z])
                if element in reactor_block_properties:
                    total_cooling += reactor_block_properties[element]['cooling_value']
                    if element == 1:
                        total_fuel_cells += 1
                        adjacent_cells = count_neighbors(array, x, y, z, 1)
                        mod = count_neighbors(array, x, y, z, 2)
                        base_energy_gen = reactor_fuel_type[fuel]['energy_gen']
                        base_heat_gen = reactor_fuel_type[fuel]['heat_gen']
                        # ... irrelevant code 

    efficiency = 100 * total_neighbor / total_fuel_cells if total_fuel_cells != 0 else 0
    heat_multiplier = 100 * total_heat_multiplier / total_fuel_cells if total_fuel_cells != 0 else 0

    metrics = {
        "heat_gen": heat,
        "cooling": total_cooling,
        "fuel_cells": total_fuel_cells,
        "energy_gen": power,
        "efficiency": int(efficiency),
        "heat_multiplier": heat_multiplier,
        "total_energy": power * total_fuel_cells,
        "heat_diff": int(heat - total_cooling)
    }
    return metrics
``` And this is the error `File "metrics.py", line 49:
def count_neighbors_opposite(array, x, y, z, element):
    <source elided>

@jit
^ 

This error may have been caused by the following argument(s):
- argument 2: Cannot determine Numba type of <class 'dict'>
- argument 3: Cannot determine Numba type of <class 'dict'>`
tired fableBOT
#

@pseudo urchin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

pseudo urchin
#

Do I need to rewrite everything just because of numba?

#

!paste

tired fableBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

pseudo urchin
#

This is the pure python code. It works, but it's insanely slow. I got it working with cuda using cupy, but for some reason it's actually slower?

#

Numba/Cython/Cupy/JIT/Pypy speedup

#

How can cupy cuda be slower than numpy?

#

And numba isn't even working because this stupid library is allergic to dictionaries

#

cython is allergic to arrays

#

bunp

tired fableBOT
#

@pseudo urchin

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.