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

Fix/aplot index error #1691

Merged
merged 4 commits into from
Dec 14, 2022
Merged

Fix/aplot index error #1691

merged 4 commits into from
Dec 14, 2022

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented Dec 13, 2022

I have seen this error randomly in few places in the CICD:

WARNING: /home/runner/work/pymapdl/pymapdl/examples/00-mapdl-examples/lathe_cutter.py failed to execute correctly: Traceback (most recent call last):
  File "/home/runner/work/pymapdl/pymapdl/examples/00-mapdl-examples/lathe_cutter.py", line 164, in <module>
    mapdl.vplot(
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/ansys/mapdl/core/mapdl.py", line 1433, in vplot
    out = self.aplot(
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/ansys/mapdl/core/mapdl.py", line 15[72](https://github.com/pyansys/pymapdl/actions/runs/3689261536/jobs/6245029261#step:16:73), in aplot
    area_color = rand[anum]
IndexError: index 1 is out of bounds for axis 0 with size 1

Link: https://github.com/pyansys/pymapdl/actions/runs/3689261536/jobs/6245029261#step:16:77

This comes from:

  if color_areas:
      anum = surf["entity_num"]
      rand = np.random.random(anum[-1]+1)
      area_color = rand[anum]
      meshes.append({"mesh": surf, "scalars": area_color})

The only reason for rand[anum] to show an index error is because the anum[-1]+1 is 1, meaning that in anum, the last element is zero. Because anum comes from surf["entity_num"] there should not be zero (one index based).

Several approaches here to increase robustness:

  • Fix anum[-1] to be at least 1. I.e. np.random.random(max([anum[-1]+1,1])).
  • Use max on anum, assuming that only the last element is zero. This might help us to "define" a bit more this random error. So I'm going for this.

@github-actions github-actions bot added the BUG Issue, problem or error in PyMAPDL label Dec 13, 2022
@github-actions
Copy link
Contributor

Please add one of the following labels to add this contribution to the Release Notes 👇

@codecov
Copy link

codecov bot commented Dec 14, 2022

Codecov Report

Merging #1691 (6535fff) into main (70c6b3b) will increase coverage by 0.05%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1691      +/-   ##
==========================================
+ Coverage   85.18%   85.23%   +0.05%     
==========================================
  Files          45       45              
  Lines        7511     7506       -5     
==========================================
  Hits         6398     6398              
+ Misses       1113     1108       -5     

@germa89 germa89 merged commit bc997e7 into main Dec 14, 2022
@germa89 germa89 deleted the fix/aplot-index-error branch December 14, 2022 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Issue, problem or error in PyMAPDL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant