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

IndexError: list index out of range at plotext/_build.py", line 261 #185

Open
Jipok opened this issue Oct 16, 2023 · 3 comments
Open

IndexError: list index out of range at plotext/_build.py", line 261 #185

Jipok opened this issue Oct 16, 2023 · 3 comments

Comments

@Jipok
Copy link

Jipok commented Oct 16, 2023

code
#!/usr/bin/env python3
import plotext as plt
#from subprocess import check_output
#import psutil
import time

CMD = "sensors amdgpu-pci-0500 | grep PPT | grep -oP '(?<=cap = )(.?\d+)'"
TARGET_TEMP = 83
CAP_MIN = 20
CAP_MAX = 180
CHART_HISTORY_COUNT = 55
plt.theme("pro")

# Prefill arrays for good chart after start
a_temp = []
a_powercap = []
#temp = psutil.sensors_temperatures()["amdgpu"][0].current
#powercap = int(check_output(CMD, shell = True).decode('utf-8'))
temp = 1
powercap = 1
for i in range(1, CHART_HISTORY_COUNT):
        a_temp.append(temp)
        a_powercap.append(powercap)

while True:
        # Trim chart
        if len(a_temp) > CHART_HISTORY_COUNT:
                a_temp = a_temp[1:]
                a_powercap = a_powercap[1:]
        # Get data
        #temp = psutil.sensors_temperatures()["amdgpu"][0].current
        a_temp.append(temp)
        #powercap = int(check_output(CMD, shell = True).decode('utf-8'))
        a_powercap.append(powercap)
        # Plot temp
        plt.clear_terminal()
        plt.clear_data()
        label = "Temp %s°C" % temp
        plt.plot(a_temp, label = label, color = "red")
        plt.ylabel(label)
        plt.ylim(20, 100)
        plt.hline(TARGET_TEMP, "green")
        # Plot power cap
        label = "Powercap %sW" % powercap
        plt.plot(a_powercap, label = label, yside = "right", color = "blue")
        plt.ylabel(label, yside = "right")
        plt.ylim(CAP_MIN - 10, CAP_MAX + 10, yside = "right")
        plt.show()
        # Limit power
        newcap = powercap
        if temp < TARGET_TEMP:
                cap_step = TARGET_TEMP - temp
                newcap = int(min(powercap + cap_step, CAP_MAX))
        if temp > TARGET_TEMP:
                cap_step = pow(temp - TARGET_TEMP, 2)
                newcap = int(max(powercap - cap_step, CAP_MIN))
        if newcap != powercap:
                check_output("/opt/rocm/bin/rocm-smi --setpoweroverdrive " + str(newcap), shell = True)

        time.sleep(1)
log
Traceback (most recent call last):
  File "/root/./main_dup.py", line 50, in <module>
    plt.show()
  File "/usr/lib/python3.11/site-packages/plotext/_core.py", line 293, in show
    _figure.show()
  File "/usr/lib/python3.11/site-packages/plotext/_figure.py", line 319, in show
    self.build()
    ^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/plotext/_figure.py", line 326, in build
    self._build_matrix()
  File "/usr/lib/python3.11/site-packages/plotext/_figure.py", line 332, in _build_matrix
    self.monitor.build_plot() if not self.monitor.fast_plot else None
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/plotext/_build.py", line 261, in build_plot
    [[self.matrix.insert_element(col_start + S + i, row_end - 1 - s, marker[s][i], color[s][i], style[s][i]) for i in range(3)] for s in range(l)] if legend_test else None
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/plotext/_build.py", line 261, in <listcomp>
    [[self.matrix.insert_element(col_start + S + i, row_end - 1 - s, marker[s][i], color[s][i], style[s][i]) for i in range(3)] for s in range(l)] if legend_test else None
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/plotext/_build.py", line 261, in <listcomp>
    [[self.matrix.insert_element(col_start + S + i, row_end - 1 - s, marker[s][i], color[s][i], style[s][i]) for i in range(3)] for s in range(l)] if legend_test else None
                                                                                   ~~~~~~~~^^^
IndexError: list index out of range
This is a real script that I use, I replaced receiving real data and now it should run and give the same result on any hardware. For some reason, this problem only occurs the first time the script is launched after the server is rebooted. If the script runs successfully, then after that it will always run successfully.
@jc-audet
Copy link

jc-audet commented Jan 10, 2024

This issue arrises because the lines your trying to plot does not appear in the y axis limits of [20,100], which causes empty arrays in the build. It is fixed with the piece of code in #197.

@cap-txt
Copy link

cap-txt commented Mar 28, 2024

I have the same issue, which only shows up if I pass a label to the plot and not otherwise.

@piccolomo
Copy link
Owner

Just to update and apologise: I have been quite busy rewriting the package from ground up and will update.

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

No branches or pull requests

4 participants