Lambda Layer, OperatorNotAllowedInGraphError
@daljee10,
Apologies for the delay.
I was facing a different error while executing the mentioned code. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/4a4950b18de4c966a3295afd9b18539d/untitled1189.ipynb) and provide the complete dependencies to reproduce the issue.

Also tf.tensor wants it's N to be a static python `int`. Try not passing it into the tf.function, and instead letting the function close over it. Also please have a look at this [issue](https://stackoverflow.com/questions/69498990/operatornotallowedingrapherror-using-a-tf-tensor-as-a-python-bool-is-not-al) with a similar error for the reference.

Thank you!


 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60604">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60604">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

tf.2

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

I created a ANN model using Keras Lambda layer to implement mathematical calculation for the output of ANN.
Function of the Lambda layer was defined by a long code of calculation. 
I mentioned @tf.fuction, but the Lambda layer didn't work well because of OperatorNotAllowdInGraphError.
The error says that 
"OperatorNotAllowedInGraphError: Exception encountered when calling layer "physics" (type Lambda).
Using a symbolic `tf.Tensor` as a Python `bool` is not allowed: AutoGraph is disabled in this function. Try decorating it directly with @tf.function."

I expect to do not only functions provided by tensorflow, such as tf.math. , but also other functions such  if-else function, indexing, and other works, which did not work well, in Lambda layer.
Maybe changing datatype of input_all0 from KerasTensor to Numpy could be helpful, but I did not find the way.



### Standalone code to reproduce the issue

```shell
@tf.function(experimental_compile=True, autograph=False, experimental_relax_shapes=True)
def physics(input_all):
    
    global ts
    global node_idx
    global ESB, glass_double, glass_triple
    global capacity, cap_outerwall, cap_air, cap_window_2, cap_window_3, cap_bipv, cap_innerwall
    global outerwall_idx, air_idx, window_2_idx, window_3_idx, bipv_idx, innerwall_idx
    global outerwall_layers, window_3_layers, bipv_layers, innerwall_layers
    
   
    tf.executing_eagerly()

    iOAT = input_all[None,0,0]
    iID = input_all[None,0,2]
    iIdsky = input_all[None,0,3]
    iIdgr = input_all[None,0,4]

    if input_all[None,0,6] < 90: igroup = 5
    if input_all[6,] < 80: igroup = 4
    if input_all[6,] < 70: igroup = 3
    if input_all[6,] < 60: igroup = 2
    if input_all[6,] < 50: igroup = 1
    if input_all[6,] < 40: igroup = 0
    
    X00 = tf.constant(input_all[None,0,8:-4])
    X0 = np.zeros(19)
    nn = 0
    
    for n in node_idx:
        X0[nn] = X00[0, n]
        nn += 1
    
    h_in = input_all[None,0,-4]
    h_outg = input_all[None,0,-3]
    h_outw = input_all[None,0,-2]
    h_ca = input_all[None,0,-1]
    
    hin_win = h_in
    hin_wall = h_in
    hin_pv = h_in
    hin_Innerwall = h_in
    hca_win1 = h_ca
    hca_win2 = h_ca
    
    hout_win = h_outg
    hout_pv = h_outg
    hout_wall = h_outw  
    # ....
    Ximp = np.linalg.solve( np.eye(len(capacity)) - amat*ts, X0 + bvector*ts)
    return Ximp

input1 = Input(shape=size1, name = 'input_parameter')
flatten_layer = Flatten()(input1)

hidden1 = Dense(size[0], activation = 'relu', name = 'hidden1_1')(flatten_layer)
output_parm = Dense(4, name = 'output_parameter')(hidden1)

hidden2 = Dense(size[1], name = 'hidden2_1')(flatten_layer)
output_VT = Dense(9, name = 'output_VirtualT')(hidden2)
input2 = Input(shape=size2, name = 'input_MT')
input_all0 = Concatenate(name = 'input_all')([input2, output_VT, output_parm])
   
output_T = Lambda(lambda x: physics(x), name="physics")(input_all0)
ann_ = Model(inputs=[input1, input2], outputs=output_T)
```


### Relevant log output

_No response_</details>