Weird python inconsistency

Coreform Cubit 2022.9 & 2022.11 - Fedora

Truely mind bending error, I have a python script which takes in a bunch of planes, does some maths - largely irrelevant. However, I’ve spent an ungodly amount of time tracking this down, but bizzarely, when running the same script inside of Coreform Cubit and in my system python I get different results!

When I run this script;

#!/usr/env/python3

import numpy as np

def plane_intersect(a, b):
    a_vec, b_vec = np.array(a[:3]), np.array(b[:3])
    aXb_vec = np.cross(a_vec, b_vec)
    A = np.array([a_vec, b_vec, aXb_vec])
    d = np.array([-a[3], -b[3], 0.]).reshape(3,1)
    # could add np.linalg.det(A) == 0 test to prevent linalg.solve throwing error
    print(f'A={A}')
    print(f'd={d}')
    p_inter = np.linalg.solve(A, d).T

    return p_inter[0]

plane1 = [0,0,-1,0.946948223999989]
plane2 = [0,1,0,-0.124051900705194]
x = plane_intersect(plane1,plane2)
print(x)
print(np.__version__)

On my system I get; - which is the correct result

A=[[ 0  0 -1]
 [ 0  1  0]
 [ 1  0  0]]
d=[[-0.94694822]
 [ 0.1240519 ]
 [ 0.        ]]
[0.         0.1240519  0.94694822]
1.22.0

Inside of Cubit I get

A=[[ 0.  0. -1.]
 [ 0.  1.  0.]
 [ 1. -0.  0.]]
d=[[-0.94694822]
 [ 0.1240519 ]
 [ 0.        ]]
[[-0.94694822  0.1240519   0.        ]]
array([-0.94694822,  0.1240519 ,  0.        ])

Note how the inputs are identical, but the output vector is reversed!

I am at a loss to explain this, any ideas?

Even simpler one;

import numpy as np
a = np.array([[1.,2.],[3.,4.]])
b = np.array([2.,1.])
print(np.linalg.solve(a,b))

In system python,

[-3.   2.5]

In Cubit

[-0.94694822  0.1240519 ]

I’m at a loss

I’m assuming that you meant something a little different for that last example from Cubit? Same values but different order?

Nope, flat out different values. I re-ran it today to make sure I wasn’t crazy.

System python:

[-3.   2.5]

Coreform Cubit:

[-5.73021895e-300  6.90234151e-310]

So I’m now thinking its due a system library being pointed to rather than the shipped Coreform version.

I should point out I switched out to scipy.linalg and it runs fine.

I can’t seem to replicate this on my end:

I’m getting consistent results with your simpler problem as well. With Coreform Cubit 2022.11 I get

image

This result is with

%>sys.version
'3.10.5 | packaged by conda-forge | (main, Sep  1 2022, 12:25:28) [MSC v.1928 64 bit (AMD64)]'
%>np.__version__
'1.22.3'

and using the system python I get the same results.

This result is with

>>> sys.version
'3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]'
>>> np.__version__
'1.24.1'

Same result with different versions of python and different versions of numpy both executed on Windows.

What version of python and numpy are you using?

Thanks,
Karl