I have a *.geo file that I have written with a python script. The main use of this *.geo file is to construct and save a triangular mesh. In gmsh you can label interest entities with the command Physical. For example Physical Point, Physical Line, etc.
Here comes the *.geo file:
// This is a test for *.geo
h = 1.00E+01 ;
Point( 1 ) = { 1.00E+00 , 1.00E+00 , 0.00E+00 ,h};
Point( 2 ) = { 7.00E+01 , 1.00E+00 , 0.00E+00 ,h};
Point( 3 ) = { 7.00E+01 , 7.00E+01 , 0.00E+00 ,h};
Point( 4 ) = { 1.00E+00 , 7.00E+01 , 0.00E+00 ,h};
Point( 5 ) = { 3.80E+01 , 2.70E+01 , 0.00E+00 ,h*0.5};
Point( 6 ) = { 3.80E+01 , 2.80E+01 , 0.00E+00 ,h*0.5};
Point( 7 ) = { 3.80E+01 , 2.90E+01 , 0.00E+00 ,h*0.5};
Point( 8 ) = { 3.80E+01 , 3.00E+01 , 0.00E+00 ,h*0.5};
Point( 9 ) = { 3.80E+01 , 3.10E+01 , 0.00E+00 ,h*0.5};
Point( 10 ) = { 3.80E+01 , 3.20E+01 , 0.00E+00 ,h*0.5};
Point( 11 ) = { 3.80E+01 , 3.30E+01 , 0.00E+00 ,h*0.5};
Point( 12 ) = { 3.90E+01 , 3.30E+01 , 0.00E+00 ,h*0.5};
Point( 13 ) = { 3.90E+01 , 3.40E+01 , 0.00E+00 ,h*0.5};
Point( 14 ) = { 3.90E+01 , 3.50E+01 , 0.00E+00 ,h*0.5};
Point( 15 ) = { 3.90E+01 , 3.60E+01 , 0.00E+00 ,h*0.5};
Point( 16 ) = { 4.00E+01 , 3.60E+01 , 0.00E+00 ,h*0.5};
Point( 17 ) = { 4.00E+01 , 3.70E+01 , 0.00E+00 ,h*0.5};
Point( 18 ) = { 4.10E+01 , 3.70E+01 , 0.00E+00 ,h*0.5};
Point( 19 ) = { 4.10E+01 , 3.80E+01 , 0.00E+00 ,h*0.5};
Point( 20 ) = { 4.10E+01 , 3.90E+01 , 0.00E+00 ,h*0.5};
Point( 21 ) = { 4.20E+01 , 3.90E+01 , 0.00E+00 ,h*0.5};
Point( 22 ) = { 4.20E+01 , 4.00E+01 , 0.00E+00 ,h*0.5};
Point( 23 ) = { 4.30E+01 , 4.00E+01 , 0.00E+00 ,h*0.5};
Point( 24 ) = { 4.40E+01 , 4.00E+01 , 0.00E+00 ,h*0.5};
Point( 25 ) = { 4.40E+01 , 4.10E+01 , 0.00E+00 ,h*0.5};
Point( 26 ) = { 4.50E+01 , 4.10E+01 , 0.00E+00 ,h*0.5};
Point( 27 ) = { 4.50E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 28 ) = { 4.60E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 29 ) = { 4.70E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 30 ) = { 4.80E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 31 ) = { 4.80E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 32 ) = { 4.90E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 33 ) = { 5.00E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 34 ) = { 5.10E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 35 ) = { 5.20E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 36 ) = { 5.30E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 37 ) = { 5.40E+01 , 4.30E+01 , 0.00E+00 ,h*0.5};
Point( 38 ) = { 5.40E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 39 ) = { 5.50E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 40 ) = { 5.60E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 41 ) = { 5.70E+01 , 4.20E+01 , 0.00E+00 ,h*0.5};
Point( 42 ) = { 5.70E+01 , 4.10E+01 , 0.00E+00 ,h*0.5};
Point( 43 ) = { 5.80E+01 , 4.10E+01 , 0.00E+00 ,h*0.5};
Point( 44 ) = { 5.80E+01 , 4.00E+01 , 0.00E+00 ,h*0.5};
Point( 45 ) = { 5.90E+01 , 4.00E+01 , 0.00E+00 ,h*0.5};
Point( 46 ) = { 6.00E+01 , 4.00E+01 , 0.00E+00 ,h*0.5};
Point( 47 ) = { 6.00E+01 , 3.90E+01 , 0.00E+00 ,h*0.5};
Point( 48 ) = { 6.10E+01 , 3.90E+01 , 0.00E+00 ,h*0.5};
Point( 49 ) = { 6.10E+01 , 3.80E+01 , 0.00E+00 ,h*0.5};
Point( 50 ) = { 6.10E+01 , 3.70E+01 , 0.00E+00 ,h*0.5};
Point( 51 ) = { 6.20E+01 , 3.70E+01 , 0.00E+00 ,h*0.5};
Point( 52 ) = { 6.20E+01 , 3.60E+01 , 0.00E+00 ,h*0.5};
Point( 53 ) = { 6.30E+01 , 3.60E+01 , 0.00E+00 ,h*0.5};
Point( 54 ) = { 6.30E+01 , 3.50E+01 , 0.00E+00 ,h*0.5};
Point( 55 ) = { 6.30E+01 , 3.40E+01 , 0.00E+00 ,h*0.5};
Point( 56 ) = { 6.30E+01 , 3.30E+01 , 0.00E+00 ,h*0.5};
Point( 57 ) = { 6.40E+01 , 3.30E+01 , 0.00E+00 ,h*0.5};
Point( 58 ) = { 6.40E+01 , 3.20E+01 , 0.00E+00 ,h*0.5};
Point( 59 ) = { 6.40E+01 , 3.10E+01 , 0.00E+00 ,h*0.5};
Point( 60 ) = { 6.40E+01 , 3.00E+01 , 0.00E+00 ,h*0.5};
Point( 61 ) = { 6.40E+01 , 2.90E+01 , 0.00E+00 ,h*0.5};
Point( 62 ) = { 6.40E+01 , 2.80E+01 , 0.00E+00 ,h*0.5};
Point( 63 ) = { 6.40E+01 , 2.70E+01 , 0.00E+00 ,h*0.5};
Point( 64 ) = { 6.30E+01 , 2.70E+01 , 0.00E+00 ,h*0.5};
Point( 65 ) = { 6.30E+01 , 2.60E+01 , 0.00E+00 ,h*0.5};
Point( 66 ) = { 6.30E+01 , 2.50E+01 , 0.00E+00 ,h*0.5};
Point( 67 ) = { 6.30E+01 , 2.40E+01 , 0.00E+00 ,h*0.5};
Point( 68 ) = { 6.20E+01 , 2.40E+01 , 0.00E+00 ,h*0.5};
Point( 69 ) = { 6.20E+01 , 2.30E+01 , 0.00E+00 ,h*0.5};
Point( 70 ) = { 6.10E+01 , 2.30E+01 , 0.00E+00 ,h*0.5};
Point( 71 ) = { 6.10E+01 , 2.20E+01 , 0.00E+00 ,h*0.5};
Point( 72 ) = { 6.10E+01 , 2.10E+01 , 0.00E+00 ,h*0.5};
Point( 73 ) = { 6.00E+01 , 2.10E+01 , 0.00E+00 ,h*0.5};
Point( 74 ) = { 6.00E+01 , 2.00E+01 , 0.00E+00 ,h*0.5};
Point( 75 ) = { 5.90E+01 , 2.00E+01 , 0.00E+00 ,h*0.5};
Point( 76 ) = { 5.80E+01 , 2.00E+01 , 0.00E+00 ,h*0.5};
Point( 77 ) = { 5.80E+01 , 1.90E+01 , 0.00E+00 ,h*0.5};
Point( 78 ) = { 5.70E+01 , 1.90E+01 , 0.00E+00 ,h*0.5};
Point( 79 ) = { 5.70E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 80 ) = { 5.60E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 81 ) = { 5.50E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 82 ) = { 5.40E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 83 ) = { 5.40E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 84 ) = { 5.30E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 85 ) = { 5.20E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 86 ) = { 5.10E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 87 ) = { 5.00E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 88 ) = { 4.90E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 89 ) = { 4.80E+01 , 1.70E+01 , 0.00E+00 ,h*0.5};
Point( 90 ) = { 4.80E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 91 ) = { 4.70E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 92 ) = { 4.60E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 93 ) = { 4.50E+01 , 1.80E+01 , 0.00E+00 ,h*0.5};
Point( 94 ) = { 4.50E+01 , 1.90E+01 , 0.00E+00 ,h*0.5};
Point( 95 ) = { 4.40E+01 , 1.90E+01 , 0.00E+00 ,h*0.5};
Point( 96 ) = { 4.40E+01 , 2.00E+01 , 0.00E+00 ,h*0.5};
Point( 97 ) = { 4.30E+01 , 2.00E+01 , 0.00E+00 ,h*0.5};
Point( 98 ) = { 4.20E+01 , 2.00E+01 , 0.00E+00 ,h*0.5};
Point( 99 ) = { 4.20E+01 , 2.10E+01 , 0.00E+00 ,h*0.5};
Point( 100 ) = { 4.10E+01 , 2.10E+01 , 0.00E+00 ,h*0.5};
Point( 101 ) = { 4.10E+01 , 2.20E+01 , 0.00E+00 ,h*0.5};
Point( 102 ) = { 4.10E+01 , 2.30E+01 , 0.00E+00 ,h*0.5};
Point( 103 ) = { 4.00E+01 , 2.30E+01 , 0.00E+00 ,h*0.5};
Point( 104 ) = { 4.00E+01 , 2.40E+01 , 0.00E+00 ,h*0.5};
Point( 105 ) = { 3.90E+01 , 2.40E+01 , 0.00E+00 ,h*0.5};
Point( 106 ) = { 3.90E+01 , 2.50E+01 , 0.00E+00 ,h*0.5};
Point( 107 ) = { 3.90E+01 , 2.60E+01 , 0.00E+00 ,h*0.5};
Point( 108 ) = { 3.90E+01 , 2.70E+01 , 0.00E+00 ,h*0.5};
Point( 109 ) = { 3.80E+01 , 2.70E+01 , 0.00E+00 ,h*0.5};
// Writing stuff for domain: 4
Line( 110 ) = { 1 , 2 , 3 , 4 , 1 };
Line Loop( 111 ) = { 110 };
Physical Line( "Border_0" ) = { 111 };
// Writing stuff for domain: 105
BSpline( 112 ) = { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 5};
Line Loop( 113 ) = { 112 };
Physical Line( "Border_1" ) = { 113 };
Plane Surface( 114 ) = { 113 };
Physical Surface( "Inclusion_1" ) = { 114 };
Plane Surface( 115 ) = {111,113};
Physical Surface( "Matrix_domain" ) = { 115 };
The created *.msh file, contains the mesh, has identified the Physical labels, but I can not find the corresponding element sets.
There is definitely something wrong in how you write the file.
In GMSH, you would usually have Line(100) = {1,2}; connecting only two points and then Line Loop that would create the loops out of the lines. Here, this is violated both for the straight segments (forming a square) and for the BSplines (forming a circular-like) inclusion.
I've manually edited the file to achieve the (supposedly, expected) result:
Line( 210 ) = { 1 , 2 };
Line( 211) = {2,3};
Line( 212) = {3,4};
Line(213) = {4,1};
Line Loop( 111 ) = { 210,211,212,213 };
Physical Line( "Border_0" ) = { 210, 211,212,213};
// Writing stuff for domain: 105
BSpline (310) = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34};
BSpline (311) = {34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60};
BSpline (312) = {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86};
BSpline (313) = {86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 5,6,7,8};
Line Loop( 113 ) = { 310,311,312,313 };
Physical Line( "Border_1" ) = { 310, 311,312,313};
Plane Surface( 114 ) = { 113 };
Physical Surface( "Inclusion_1" ) = { 114 };
Plane Surface( 115 ) = {111,113};
Physical Surface( "Matrix_domain" ) = { 115 };
Now, I split the "circle" into 4 segments as it recommended to have arc angles <180 degrees in GMSH. And though BSpline is not necessarily a Circle (command for an arc in GMSH), I tend to use this convention here as well.
Similarly, the actual Lines (not Line Loops) have to be added to the Physical Line.
Now, I guess, you can find your elements (if I correctly understood your question).
Related
I need each column to generate random integers with specified range for col 1 (random.randint(1, 50) for col 2 random.randint(51, 100)...etc
import numpy
import random
import pandas
from random import randint
wsn = numpy.arange(1, 6)
taskn = 3
t1 = numpy.random.randint((random.randint(2, 50),random.randint(51, 100),
random.randint(101, 150),random.randint(151, 200),random.randint(201, 250)),size=(5,5))
t2 = numpy.random.randint((random.randint(2, 50),random.randint(51, 100),
random.randint(101, 150),random.randint(151, 200),random.randint(201, 250)),size=(5,5))
t3= numpy.random.randint((random.randint(2, 50),random.randint(51, 100),
random.randint(101, 150),random.randint(151, 200),random.randint(201, 250)),size=(5,5))
print('\nGenerated Data:\t\n\nNumber \t\t\t Task 1 \t\t\t Task 2 \t\t\t Task 3\n')
ni = len(t1)
for i in range(ni):
print('\t {0} \t {1} \t {2} \t {3}\n'.format(wsn[i], t1[i],t2[i],t3[i]))
print('\n\n')
It prints the following
Generated Data:
Number Task 1 Task 2 Task 3
1 [ 1 13 16 121 18] [ 5 22 34 65 194] [ 10 68 60 134 130]
2 [ 0 2 117 176 46] [ 1 15 111 116 180] [22 41 70 24 85]
3 [ 0 12 121 19 193] [ 0 5 37 109 205] [ 5 53 5 106 15]
4 [ 0 5 97 99 235] [ 0 22 142 11 150] [ 6 79 129 64 87]
5 [ 2 46 71 101 186] [ 3 57 141 37 71] [ 15 32 9 117 77]
soemtimes It even generates 0 when I didn't even specifiy 0 in the ranges
np.random.randint(low, high, size=None) allows for low and high being arrays of length num_intervals.
In that case, when size is not specified, it will generate as many integers as there are intervals defined by the low and high bounds.
If you want to generate multiple integers per interval, you just need to specify the corresponding size argument, which must ends by num_intervals.
Here it is size=(num_tasks, num_samples, num_intervals).
import numpy as np
bounds = np.array([1, 50, 100, 150, 200, 250])
num_tasks = 3
num_samples = 7
bounds_low = bounds[:-1]
bounds_high = bounds[1:]
num_intervals = len(bounds_low)
arr = np.random.randint(
bounds_low, bounds_high, size=(num_tasks, num_samples, num_intervals)
)
Checking the properties:
assert arr.shape == (num_tasks, num_samples, num_intervals)
for itvl_idx in range(num_intervals):
assert np.all(arr[:, :, itvl_idx] >= bounds_low[itvl_idx])
assert np.all(arr[:, :, itvl_idx] < bounds_high[itvl_idx])
An example of output:
array([[[ 45, 61, 100, 185, 216],
[ 36, 78, 117, 152, 222],
[ 18, 77, 112, 153, 221],
[ 9, 70, 123, 178, 223],
[ 16, 84, 118, 157, 233],
[ 42, 78, 108, 179, 240],
[ 40, 52, 116, 152, 225]],
[[ 3, 92, 102, 151, 236],
[ 45, 89, 138, 179, 218],
[ 45, 73, 120, 183, 231],
[ 35, 80, 130, 167, 212],
[ 14, 86, 118, 195, 212],
[ 20, 66, 117, 151, 248],
[ 49, 94, 138, 175, 212]],
[[ 13, 75, 116, 169, 206],
[ 13, 75, 127, 179, 213],
[ 29, 64, 136, 151, 213],
[ 1, 81, 140, 197, 200],
[ 17, 77, 112, 171, 215],
[ 18, 75, 103, 180, 209],
[ 47, 57, 132, 194, 234]]])
I have two models that proven to be identical as following:
if len(m_s.layers) != len(m_m.layers):
print("number of layers are different")
for i in range(len(m_s.layers)):
weight_s = m_s.layers[i].get_weights()
weight_m = m_m.layers[i].get_weights()
if len(weight_s) > 0:
for j in range(len(weight_s)):
if (weight_s[j] == weight_m[j]).all:
print("layer %d identical" % i)
else:
print("!!!!! layer %d not the same" % i)
else:
if len(weight_m) == 0:
print("layer %d identical" % i)
else:
print("!!!!! layer %d not the same" % i)
and the output shows they are identical. They are slices from the imagenet model.
layer 0 identical
layer 1 identical
layer 2 identical
layer 2 identical
layer 2 identical
layer 2 identical
layer 3 identical
layer 4 identical
layer 5 identical
layer 5 identical
layer 5 identical
layer 5 identical
layer 6 identical
layer 7 identical
layer 8 identical
layer 8 identical
layer 8 identical
layer 8 identical
layer 9 identical
layer 10 identical
layer 10 identical
layer 10 identical
layer 10 identical
layer 11 identical
layer 12 identical
layer 13 identical
layer 13 identical
layer 13 identical
layer 13 identical
layer 14 identical
layer 15 identical
layer 16 identical
layer 16 identical
layer 16 identical
layer 16 identical
layer 17 identical
layer 18 identical
layer 18 identical
layer 18 identical
layer 18 identical
layer 19 identical
layer 20 identical
layer 21 identical
layer 21 identical
layer 21 identical
layer 21 identical
layer 22 identical
layer 23 identical
layer 24 identical
layer 24 identical
layer 24 identical
layer 24 identical
layer 25 identical
layer 26 identical
layer 27 identical
layer 27 identical
layer 27 identical
layer 27 identical
layer 28 identical
layer 29 identical
layer 30 identical
layer 30 identical
layer 30 identical
layer 30 identical
layer 31 identical
layer 32 identical
layer 33 identical
layer 33 identical
layer 33 identical
layer 33 identical
layer 34 identical
layer 35 identical
layer 35 identical
layer 35 identical
layer 35 identical
layer 36 identical
layer 37 identical
layer 38 identical
layer 38 identical
layer 38 identical
layer 38 identical
layer 39 identical
layer 40 identical
layer 41 identical
layer 41 identical
layer 41 identical
layer 41 identical
layer 42 identical
layer 43 identical
layer 44 identical
layer 44 identical
layer 44 identical
layer 44 identical
layer 45 identical
layer 46 identical
layer 47 identical
layer 47 identical
layer 47 identical
layer 47 identical
layer 48 identical
layer 49 identical
layer 50 identical
layer 50 identical
layer 50 identical
layer 50 identical
layer 51 identical
However, when I used these two model in the same machine and same env to predict the same input data, the outputs were completely different.
m_s.predict(data)
output
array([[[[-2.2014694e+00, -7.4636793e+00, -3.7543521e+00, ...,
4.2393379e+00, 7.2923303e+00, -7.9203067e+00],
[-6.8980045e+00, -6.7517347e+00, 5.9752476e-01, ...,
2.2391853e+00, -2.0161586e+00, -7.5054851e+00],
[-4.4470978e+00, -4.2420959e+00, -3.9374633e+00, ...,
5.9843721e+00, 5.4481273e+00, -2.7136576e+00],
...,
[-8.2077494e+00, -5.5874801e+00, 2.2708473e+00, ...,
-2.5585687e-01, 4.0198727e+00, -4.5880938e+00],
[-7.5793233e+00, -6.3811040e+00, 3.7389126e+00, ...,
1.7169635e+00, -3.4249902e-01, -7.1873198e+00],
[-8.2512989e+00, -4.2883468e+00, -2.7908459e+00, ...,
3.9796615e+00, 4.7512245e-01, -4.5338011e+00]],
[[-5.2522459e+00, -5.2272692e+00, -3.7313356e+00, ...,
1.0820831e+00, -1.9317195e+00, -8.3177958e+00],
[-5.8229809e+00, -6.8049965e+00, -1.4538713e+00, ...,
4.0576010e+00, -1.9025326e-02, -8.2517090e+00],
[-6.1541910e+00, -2.6757658e-01, -5.4412403e+00, ...,
1.7984511e+00, 2.9016986e+00, 7.6427579e-01],
...,
[-1.1129386e+00, 7.9319181e+00, 7.7404571e-01, ...,
-1.7145084e+01, 1.5210888e+01, 1.3812095e+01],
[ 3.5752565e-01, 1.4212518e+00, -6.1826277e-01, ...,
-3.4348285e+00, 5.1942883e+00, 2.1960042e+00],
[-6.3907943e+00, -5.3237562e+00, -3.1632636e+00, ...,
2.1118989e+00, -3.8516359e+00, -6.2463970e+00]],
[[-7.2064867e+00, -3.6420932e+00, -1.6844990e+00, ...,
6.4910537e-01, -4.4807429e+00, -7.8619242e+00],
[-6.4934230e+00, -4.5477719e+00, 9.2149705e-01, ...,
4.2846882e-01, -7.4903011e-01, -9.8737726e+00],
[-7.2704558e+00, 9.5214283e-01, -2.0818310e+00, ...,
-1.6958854e-01, 1.6371614e+00, -2.7756066e+00],
...,
[-7.1980424e+00, -7.2074276e-01, 2.3514495e+00, ...,
-9.7255888e+00, 2.1547556e-01, 4.3379207e+00],
[-6.7656651e+00, 6.3100419e+00, -7.8286257e+00, ...,
-5.1035576e+00, -1.3960669e+00, 2.3991609e+00],
[-7.0669832e+00, -1.2582588e-01, -5.3176193e+00, ...,
3.4836166e+00, -2.4024684e+00, -6.0632706e+00]],
...,
[[-7.3400059e+00, -3.1168675e+00, -1.9545169e+00, ...,
1.0936095e+00, -1.5736668e+00, -9.5641651e+00],
[-2.9115820e+00, -4.7334772e-01, 2.6805878e-01, ...,
8.3148491e-01, -1.2751791e+00, -5.5142212e+00],
[ 1.2365078e+00, 1.0945862e+01, -4.9259267e+00, ...,
1.9169430e+00, 5.1151342e+00, 4.9710069e+00],
...,
[-2.2321188e+00, 8.8735223e-02, -7.6890874e+00, ...,
-3.1269640e-01, 7.3404179e+00, -7.2507386e+00],
[-2.2741010e+00, -6.5992510e-01, 4.0761769e-01, ...,
1.8645943e+00, 4.0359187e+00, -7.7996893e+00],
[ 5.5672646e-02, -1.4715804e+00, -1.9753509e+00, ...,
2.5039923e+00, -1.0506821e-01, -6.5183282e+00]],
[[-8.3111782e+00, -4.6992331e+00, -3.1351955e+00, ...,
1.8569698e+00, -1.1717710e+00, -8.5070782e+00],
[-4.7671299e+00, -2.5072317e+00, 2.9760203e+00, ...,
2.9142296e+00, 3.2271760e+00, -4.7557964e+00],
[ 5.5070686e-01, 5.3218126e-02, -2.1629403e+00, ...,
8.8359457e-01, 3.1481497e+00, -2.1769693e+00],
...,
[-3.7305963e+00, -1.2512873e+00, 2.0231385e+00, ...,
4.4094267e+00, 3.0268743e+00, -9.6763916e+00],
[-5.4271636e+00, -4.6796727e+00, 5.7922940e+00, ...,
3.6725988e+00, 5.2563481e+00, -8.1707211e+00],
[-1.2138665e-02, -3.6983132e+00, -6.4367266e+00, ...,
6.8217549e+00, 5.7782011e+00, -5.4132147e+00]],
[[-5.0323372e+00, -3.3903065e+00, -2.7963824e+00, ...,
3.9016938e+00, 1.4906535e+00, -2.1907964e+00],
[-7.7795396e+00, -5.7441168e+00, 3.4615259e+00, ...,
1.4764800e+00, -2.9045539e+00, -4.4136987e+00],
[-7.2599754e+00, -3.4636111e+00, 4.3936129e+00, ...,
1.9856967e+00, -1.0856767e+00, -5.7980385e+00],
...,
[-6.1726952e+00, -3.9608026e+00, 5.5742388e+00, ...,
4.9396091e+00, -2.8744078e+00, -8.3122082e+00],
[-1.3442982e+00, -5.5807371e+00, 4.7524319e+00, ...,
5.0170369e+00, 2.9530718e+00, -7.1846304e+00],
[-1.7616816e+00, -6.7234058e+00, -8.3512306e+00, ...,
4.1365266e+00, -2.8818092e+00, -2.9208889e+00]]]],
dtype=float32)
while
m_m.predict(data)
output
array([[[[ -7.836284 , -2.3029385 , -3.6463926 , ..., -1.104739 ,
12.992413 , -6.7326055 ],
[-11.714638 , -2.161682 , -2.0715065 , ..., -0.0467519 ,
6.557784 , -2.7576606 ],
[ -8.029486 , -4.068902 , -4.6803293 , ..., 7.022674 ,
7.741771 , -1.874607 ],
...,
[-11.229774 , -5.3050747 , 2.807798 , ..., 1.1340691 ,
4.3236184 , -5.2162905 ],
[-11.458603 , -6.2387724 , 0.25091058, ..., 1.0305461 ,
5.9631624 , -6.284294 ],
[ -8.663513 , -1.8256164 , -3.0079443 , ..., 5.9437366 ,
7.0928698 , -1.0781381 ]],
[[ -4.362539 , -2.8450599 , -3.1030283 , ..., -1.5129573 ,
2.2504683 , -8.414198 ],
[ -6.308961 , -4.99597 , -3.8596241 , ..., 4.2793174 ,
2.7787375 , -5.9963284 ],
[ -4.8252788 , -1.5710263 , -6.083002 , ..., 4.856139 ,
2.9387665 , 0.29977918],
...,
[ -0.8481703 , 5.348722 , 2.3885899 , ..., -19.35567 ,
13.1428795 , 12.364189 ],
[ -1.8864173 , -3.7014763 , -2.5292692 , ..., -3.6618025 ,
4.3906307 , 0.03934002],
[ -6.0526505 , -5.504422 , -3.8778243 , ..., 4.3741727 ,
1.0135782 , -5.1025114 ]],
[[ -6.7328253 , -1.5671132 , 0.16782492, ..., -2.5069456 ,
1.4343324 , -8.59162 ],
[ -7.5468965 , -5.6893063 , 0.13871288, ..., 0.22174302,
1.1608338 , -8.77916 ],
[ -5.940791 , 1.1769392 , -4.5080614 , ..., 3.5371704 ,
2.4181929 , -2.7893126 ],
...,
[ -9.490874 , -2.3575358 , 2.5908213 , ..., -18.813345 ,
-3.4546187 , 4.8375816 ],
[ -5.1123285 , 3.3766522 , -10.71935 , ..., -5.8476105 ,
-3.5569503 , 0.6331433 ],
[ -6.2075157 , 0.4942119 , -7.044799 , ..., 5.191918 ,
2.7723277 , -4.5243273 ]],
...,
[[ -7.06453 , -1.3950944 , -0.37429178, ..., -0.11883163,
0.22527158, -9.231563 ],
[ -4.0204725 , -3.6592636 , 0.15709507, ..., 1.7647433 ,
4.6479545 , -3.8798246 ],
[ 0.75817275, 9.890637 , -7.069035 , ..., 2.995041 ,
6.8453026 , 6.028713 ],
...,
[ -1.5892754 , 2.119719 , -10.078391 , ..., -2.546938 ,
6.5255003 , -6.749384 ],
[ -3.2769198 , -0.46709523, -2.1529863 , ..., 1.8028917 ,
7.2509494 , -7.5441256 ],
[ -1.2531447 , 0.96327865, -1.0863694 , ..., 2.423694 ,
-1.1047542 , -6.4944725 ]],
[[-10.218704 , -2.5448627 , -0.6002845 , ..., 0.80485874,
2.7691112 , -7.374723 ],
[ -8.354421 , -5.461962 , 5.2284613 , ..., 0.5315646 ,
5.701563 , -4.0477304 ],
[ -2.7866952 , -5.8492465 , -1.5627437 , ..., 1.9490132 ,
4.0491743 , -2.7550128 ],
...,
[ -4.5389686 , -3.2624135 , 0.7429285 , ..., 2.5953412 ,
3.8780956 , -8.652936 ],
[ -5.704813 , -3.730238 , 4.87866 , ..., 2.6826556 ,
4.8833456 , -6.8225956 ],
[ -0.16680491, -0.4325713 , -4.7689047 , ..., 8.588567 ,
6.786765 , -4.7118473 ]],
[[ -1.4958351 , 2.151188 , -4.1733856 , ..., -1.891511 ,
12.969635 , -2.5913832 ],
[ -7.6865544 , 0.5423928 , 6.2699823 , ..., -2.4558625 ,
6.1929445 , -2.7875526 ],
[ -6.995783 , 2.609788 , 5.6196365 , ..., -0.6639404 ,
5.7171726 , -3.7962272 ],
...,
[ -3.6628227 , -1.3322173 , 4.7582774 , ..., 2.122392 ,
3.1294663 , -8.338194 ],
[ -3.0116327 , -1.322252 , 4.802135 , ..., 1.9731755 ,
8.750839 , -6.989321 ],
[ 2.3386476 , -2.4584374 , -5.9336634 , ..., 0.48920852,
3.540884 , -2.9136944 ]]]], dtype=float32)
It obviously not because of floating rounding, since the outputs are quite different. I don't understand why. Please help
I found out the reason by extracting layer by layer. There are BatchNormalizing layers in the model and weight changed although I set them as not trainable.
I want to bucket volumes and build up a summary report over the aggregate data via those buckets. Currently I use apply to do this, but apply can be very slow for large data sets. Is there a generic form of the syntax given in create_lt_ten_buckets? I'm guessing this is more of a numpy thing, with which I am less familiar.
def create_buckets(df_internal, comparison_operator, column_to_bucket, min_value, max_value, ranges_pivots):
low = [min_value] + ranges_pivots
high = ranges_pivots + [max_value]
ranges = list(zip(low, high))
max_str_len = len(str(max(high + low)))
def get_value(row):
count = 0
for l,h in ranges:
if comparison_operator(l, row[column_to_bucket]) and comparison_operator(row[column_to_bucket], h):
return "{}|{}_to_{}".format(str(count).zfill(max_str_len),l,h)
count+=1
return "OUTOFBAND"
df_internal["{}_BUCKETED".format(column_to_bucket)] = df_internal.apply(get_value, axis=1)
def create_lt_ten_bucket(df_internal, column_to_bucket):
df_internal["{}_is_lt_ten".format(column_to_bucket)] = df_internal[column_to_bucket] < 10
dftest = pd.DataFrame([1,2,3,4,5, 44, 250, 22], columns=["value_alpha"])
create_buckets(dftest, lambda v1,v2: v1 <= v2, "value_alpha", 0, 999, [1, 2, 5, 10, 25, 50, 100, 200])
display(dftest)
create_lt_ten_bucket(dftest, "value_alpha")
display(dftest)
dftest.groupby('value_alpha_BUCKETED').sum().sort_values('value_alpha_BUCKETED')
OUTPUT
value_alpha value_alpha_BUCKETED
0 1 000|0_to_1
1 2 001|1_to_2
2 3 002|2_to_5
3 4 002|2_to_5
4 5 002|2_to_5
5 44 005|25_to_50
6 250 008|200_to_999
7 22 004|10_to_25
dftest = pd.DataFrame([1,2,3,4,5, 44, 250, 22], columns=["value_alpha"])
create_buckets(dftest, lambda v1,v2: v1 <= v2, "value_alpha", 0, 999999999, [1, 2, 5, 10, 25, 50, 100, 200])
display(dftest)
create_lt_ten_bucket(dftest, "value_alpha")
display(dftest)
OUTPUT
value_alpha value_alpha_BUCKETED value_alpha_is_lt_ten
0 1 000|0_to_1 True
1 2 001|1_to_2 True
2 3 002|2_to_5 True
3 4 002|2_to_5 True
4 5 002|2_to_5 True
5 44 005|25_to_50 False
6 250 008|200_to_999 False
7 22 004|10_to_25 False
In the end I'm trying to get a summary of the data similar to this:
dftest.groupby('value_alpha_BUCKETED').sum().sort_values('value_alpha_BUCKETED')
value_alpha value_alpha_is_lt_ten
value_alpha_BUCKETED
000|0_to_1 1 1.0
001|1_to_2 2 1.0
002|2_to_5 12 3.0
004|10_to_25 22 0.0
005|25_to_50 44 0.0
008|200_to_999 250 0.0
I'm not entirely clear on what you're asking, but what you have is roughly pd.cut and pd.DataFrame.groupby:
dftest['new_bucket'] = pd.cut(dftest['value_alpha'], [0, 1, 2, 5, 10, 25, 50, 100, 200, 999])
dftest['value_alpha_is_lt_ten'] = dftest['value_alpha'] < 10
print(dftest.groupby("new_bucket").sum())
value_alpha value_alpha_is_lt_ten
new_bucket
(0, 1] 1 1.0
(1, 2] 2 1.0
(2, 5] 12 3.0
(5, 10] 0 0.0
(10, 25] 22 0.0
(25, 50] 44 0.0
(50, 100] 0 0.0
(100, 200] 0 0.0
(200, 999] 250 0.0
If you don't want the empty buckets, you could .query on values where value_alpha > 0
According to this question I implemented the horizontal addition this time 5 by 5 and 7 by 7. It does the job correctly but it is not fast enough.
Can it be faster than what it is? I tried to use hadd and other instruction but the improvement is restricted. For examlple, when I use _mm256_bsrli_epi128 it is slightly better but it needs some extra permutation that ruins the benefit because of the lanes. So the question is how it should be implemented to gain more performance. The same story is for 9 elements, etc.
This adds 5 elements horizontally and puts the results in places 0, 5, and 10:
//it put the results in places 0, 5, and 10
inline __m256i _mm256_hadd5x5_epi16(__m256i a )
{
__m256i a1, a2, a3, a4;
a1 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 1 * 2);
a2 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 2 * 2);
a3 = _mm256_bsrli_epi128(a2, 2);
a4 = _mm256_bsrli_epi128(a3, 2);
return _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(a1, a2), _mm256_add_epi16(a3, a4)) , a );
}
And this adds 7 elements horizontally and puts the results in places 0 and 7:
inline __m256i _mm256_hadd7x7_epi16(__m256i a )
{
__m256i a1, a2, a3, a4, a5, a6;
a1 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 1 * 2);
a2 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 2 * 2);
a3 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 3 * 2);
a4 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 4 * 2);
a5 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 5 * 2);
a6 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 6 * 2);
return _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(a1, a2), _mm256_add_epi16(a3, a4)) , _mm256_add_epi16(_mm256_add_epi16(a5, a6), a ));
}
Indeed it is possible calculate these sums with less instructions. The idea is to accumulate
the partial sums not only in columns 10, 5 and 0, but also in other columns. This reduces the number of
vpaddw instructions and the number of 'shuffles' compared to your solution.
#include <stdio.h>
#include <x86intrin.h>
/* gcc -O3 -Wall -m64 -march=haswell hor_sum5x5.c */
int print_vec_short(__m256i x);
int print_10_5_0_short(__m256i x);
__m256i _mm256_hadd5x5_epi16(__m256i a );
__m256i _mm256_hadd7x7_epi16(__m256i a );
int main() {
short x[16];
for(int i=0; i<16; i++) x[i] = i+1; /* arbitrary initial values */
__m256i t0 = _mm256_loadu_si256((__m256i*)x);
__m256i t2 = _mm256_permutevar8x32_epi32(t0,_mm256_set_epi32(0,7,6,5,4,3,2,1));
__m256i t02 = _mm256_add_epi16(t0,t2);
__m256i t3 = _mm256_bsrli_epi128(t2,4); /* byte shift right */
__m256i t023 = _mm256_add_epi16(t02,t3);
__m256i t13 = _mm256_srli_epi64(t02,16); /* bit shift right */
__m256i sum = _mm256_add_epi16(t023,t13);
printf("t0 = ");print_vec_short(t0 );
printf("t2 = ");print_vec_short(t2 );
printf("t02 = ");print_vec_short(t02 );
printf("t3 = ");print_vec_short(t3 );
printf("t023= ");print_vec_short(t023);
printf("t13 = ");print_vec_short(t13 );
printf("sum = ");print_vec_short(sum );
printf("\nVector elements of interest: columns 10, 5, 0:\n");
printf("t0 [10, 5, 0] = ");print_10_5_0_short(t0 );
printf("t2 [10, 5, 0] = ");print_10_5_0_short(t2 );
printf("t02 [10, 5, 0] = ");print_10_5_0_short(t02 );
printf("t3 [10, 5, 0] = ");print_10_5_0_short(t3 );
printf("t023[10, 5, 0] = ");print_10_5_0_short(t023);
printf("t13 [10, 5, 0] = ");print_10_5_0_short(t13 );
printf("sum [10, 5, 0] = ");print_10_5_0_short(sum );
printf("\nSum with _mm256_hadd5x5_epi16(t0)\n");
sum = _mm256_hadd5x5_epi16(t0);
printf("sum [10, 5, 0] = ");print_10_5_0_short(sum );
/* now the sum of 7 elements: */
printf("\n\nSum of short ints 13...7 and short ints 6...0:\n");
__m256i t = _mm256_loadu_si256((__m256i*)x);
t0 = _mm256_permutevar8x32_epi32(t0,_mm256_set_epi32(3,6,5,4,3,2,1,0));
t0 = _mm256_and_si256(t0,_mm256_set_epi16(0xFFFF,0,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, 0,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF));
__m256i t1 = _mm256_alignr_epi8(t0,t0,2);
__m256i t01 = _mm256_add_epi16(t0,t1);
__m256i t23 = _mm256_alignr_epi8(t01,t01,4);
__m256i t0123 = _mm256_add_epi16(t01,t23);
__m256i t4567 = _mm256_alignr_epi8(t0123,t0123,8);
__m256i sum08 = _mm256_add_epi16(t0123,t4567); /* all elements are summed, but another permutation is needed to get the answer at position 7 */
sum = _mm256_permutevar8x32_epi32(sum08,_mm256_set_epi32(4,4,4,4,4,0,0,0));
printf("t = ");print_vec_short(t );
printf("t0 = ");print_vec_short(t0 );
printf("t1 = ");print_vec_short(t1 );
printf("t01 = ");print_vec_short(t01 );
printf("t23 = ");print_vec_short(t23 );
printf("t0123 = ");print_vec_short(t0123 );
printf("t4567 = ");print_vec_short(t4567 );
printf("sum08 = ");print_vec_short(sum08 );
printf("sum = ");print_vec_short(sum );
printf("\nSum with _mm256_hadd7x7_epi16(t) (the answer is in column 0 and in column 7)\n");
sum = _mm256_hadd7x7_epi16(t);
printf("sum = ");print_vec_short(sum );
return 0;
}
inline __m256i _mm256_hadd5x5_epi16(__m256i a )
{
__m256i a1, a2, a3, a4;
a1 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 1 * 2);
a2 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 2 * 2);
a3 = _mm256_bsrli_epi128(a2, 2);
a4 = _mm256_bsrli_epi128(a3, 2);
return _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(a1, a2), _mm256_add_epi16(a3, a4)) , a );
}
inline __m256i _mm256_hadd7x7_epi16(__m256i a )
{
__m256i a1, a2, a3, a4, a5, a6;
a1 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 1 * 2);
a2 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 2 * 2);
a3 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 3 * 2);
a4 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 4 * 2);
a5 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 5 * 2);
a6 = _mm256_alignr_epi8(_mm256_permute2x128_si256(a, _mm256_setzero_si256(), 0x31), a, 6 * 2);
return _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(a1, a2), _mm256_add_epi16(a3, a4)) , _mm256_add_epi16(_mm256_add_epi16(a5, a6), a ));
}
int print_vec_short(__m256i x){
short int v[16];
_mm256_storeu_si256((__m256i *)v,x);
printf("%4hi %4hi %4hi %4hi | %4hi %4hi %4hi %4hi | %4hi %4hi %4hi %4hi | %4hi %4hi %4hi %4hi \n",
v[15],v[14],v[13],v[12],v[11],v[10],v[9],v[8],v[7],v[6],v[5],v[4],v[3],v[2],v[1],v[0]);
return 0;
}
int print_10_5_0_short(__m256i x){
short int v[16];
_mm256_storeu_si256((__m256i *)v,x);
printf("%4hi %4hi %4hi \n",v[10],v[5],v[0]);
return 0;
}
The output is:
$ ./a.out
t0 = 16 15 14 13 | 12 11 10 9 | 8 7 6 5 | 4 3 2 1
t2 = 2 1 16 15 | 14 13 12 11 | 10 9 8 7 | 6 5 4 3
t02 = 18 16 30 28 | 26 24 22 20 | 18 16 14 12 | 10 8 6 4
t3 = 0 0 2 1 | 16 15 14 13 | 0 0 10 9 | 8 7 6 5
t023= 18 16 32 29 | 42 39 36 33 | 18 16 24 21 | 18 15 12 9
t13 = 0 18 16 30 | 0 26 24 22 | 0 18 16 14 | 0 10 8 6
sum = 18 34 48 59 | 42 65 60 55 | 18 34 40 35 | 18 25 20 15
Vector elements of interest: columns 10, 5, 0:
t0 [10, 5, 0] = 11 6 1
t2 [10, 5, 0] = 13 8 3
t02 [10, 5, 0] = 24 14 4
t3 [10, 5, 0] = 15 10 5
t023[10, 5, 0] = 39 24 9
t13 [10, 5, 0] = 26 16 6
sum [10, 5, 0] = 65 40 15
Sum with _mm256_hadd5x5_epi16(t0)
sum [10, 5, 0] = 65 40 15
Sum of short ints 13...7 and short ints 6...0:
t = 16 15 14 13 | 12 11 10 9 | 8 7 6 5 | 4 3 2 1
t0 = 8 0 14 13 | 12 11 10 9 | 0 7 6 5 | 4 3 2 1
t1 = 9 8 0 14 | 13 12 11 10 | 1 0 7 6 | 5 4 3 2
t01 = 17 8 14 27 | 25 23 21 19 | 1 7 13 11 | 9 7 5 3
t23 = 21 19 17 8 | 14 27 25 23 | 5 3 1 7 | 13 11 9 7
t0123 = 38 27 31 35 | 39 50 46 42 | 6 10 14 18 | 22 18 14 10
t4567 = 39 50 46 42 | 38 27 31 35 | 22 18 14 10 | 6 10 14 18
sum08 = 77 77 77 77 | 77 77 77 77 | 28 28 28 28 | 28 28 28 28
sum = 77 77 77 77 | 77 77 77 77 | 77 77 28 28 | 28 28 28 28
Sum with _mm256_hadd7x7_epi16(t) (the answer is in column 0 and in column 7)
sum = 16 31 45 58 | 70 81 91 84 | 77 70 63 56 | 49 42 35 28
WHERE (
((SERVICECOMPONENT_ID IN (123, 150, 198, 199, 290, 287, 291, 289, 288, 286, 282, 281)))
OR ((SERVICEREQUEST_ID IN (
SELECT distinct(SR.SERVICEREQUEST_ID)
FROM SERVICE_REQUEST SR,ASSIGNED_SR_PROJECTS ASP,PROJECT_RESOURCES PRS
WHERE SR.SERVICEREQUEST_ID = ASP.SERVICEREQUEST_ID
AND PRS.PROJECT_ID = ASP.PROJECT_ID
AND PRS.RESPONSIBILITY IN ('MANAGER','LEAD')
AND PRS.RESOURCE_ID =180 )) )
)
In general,
SELECT a FROM b WHERE c IN (SELECT d FROM e)
is equivalent to
SELECT a FROM b WHERE EXISTS (SELECT 1 FROM e WHERE c = d)
The SERVICEREQUEST_ID IN (subquery) part of your code example translates to:
OR EXISTS (
SELECT 1
FROM
SERVICE_REQUEST SR,
ASSIGNED_SR_PROJECTS ASP,
PROJECT_RESOURCES PRS
WHERE
SR.SERVICEREQUEST_ID = ASP.SERVICEREQUEST_ID
AND PRS.PROJECT_ID = ASP.PROJECT_ID
AND PRS.RESPONSIBILITY IN ('MANAGER', 'LEAD')
AND PRS.RESOURCE_ID = 180
AND mytable.SERVICEREQUEST_ID = SR.SERVICEREQUEST_ID
)
if you have static list of elements It's better to use "IN".... If you have a subquery and it is returning more than one value then Use Exist...
There is no Difference in Both clauses..
WHERE (
( (SERVICECOMPONENT_ID IN ( 123 , 150 , 198 , 199 , 290 , 287 , 291 , 289 , 288 , 286 , 282 , 281 )) )
OR ( (SERVICEREQUEST_ID IN ( 1952 , 2387 , 3618 , 3633 , 4178 , 4432 , 5090 , 5271 , 6068 , 6320 , 6396 , 6526 , 7162 , 7442 , 7558 , 7639 , 7688 , 8176 , 8189 , 8338 , 8460 , 8461 , 8598 , 8612 , 8628 , 8675 , 8775 , 8869 , 8886 , 8898 )) )
OR ( (REQUESTED_BY LIKE 'XXXXXXX#example.com' ) )
OR ( ( EXISTS ( SELECT count(distinct(SR.SERVICEREQUEST_ID)) FROM SERVICE_REQUEST SR,ASSIGNED_SR_PROJECTS ASP,PROJECT_RESOURCES PRS WHERE SR.SERVICEREQUEST_ID = ASP.SERVICEREQUEST_ID AND PRS.PROJECT_ID = ASP.PROJECT_ID AND PRS.RESPONSIBILITY IN ('MANAGER','LEAD') AND PRS.RESOURCE_ID =180 )) )
OR ( (STATUS_CODE LIKE 'OPEN' ) AND ( EXISTS (SELECT count(COMPONENT.CATEGORY_ID) FROM PROJECTMASTER PROJECTS, BUDGET BUDGET, CONTRACT CONTRACT,COMPONENTS COMPONENT, PROJECT_RESOURCES PROJ_RESOURCES, CATEGORY_OWNER_ASSIGNMENT CATEGORYOWNER, SERVICECATEGORYASSIGNMENT CATEGORYASSIGNMENT WHERE PROJECTS.PROJECT_ID = PROJ_RESOURCES.PROJECT_ID AND PROJECTS.BUDGET_ID = BUDGET.BUDGET_ID AND BUDGET.CONTRACT = CONTRACT.CONTRACT_ID AND CATEGORYASSIGNMENT.CONTRACT_ID = CONTRACT.CONTRACT_ID AND COMPONENT.COMPONENT_ID = CATEGORYASSIGNMENT.COMPONENT_ID AND CATEGORYOWNER.CATEGORY_ID = COMPONENT.CATEGORY_ID AND CATEGORYOWNER.USER_ID = PROJ_RESOURCES.RESOURCE_ID AND (CATEGORYOWNER.OWNER_FLAG = 'Y' OR CATEGORYOWNER.MEMBER_FLAG = 'Y') AND PROJ_RESOURCES.RESOURCE_ID = 180 AND PROJ_RESOURCES.ACTIVE_FLAG = 'Y' AND CATEGORYASSIGNMENT.ACTIVE_FLAG = 'Y' AND PROJ_RESOURCES.RESPONSIBILITY IN ('MANAGER', 'LEAD') )) )
)
read this for further clarification..
Difference between EXISTS and IN in SQL?