Repository: Pyomo/pyomo

Issue:
model.clone() fails to properly clone indexed Expression
## Summary

When I attempt to invoke `model.clone()` on `ConcreteModel` object , Pyomo writes errors to the terminal indicating it is failing to clone one of the `Expression` objects, but the script terminates normally with an exit code of 0.

I experience this issue with `pyomo==6.4.1`. If I roll back to `pyomo==6.2`, I still experience the issue. But if I revert to `pyomo==6.1.2`, I do not observe the issue, and the clone works as expected.


### Steps to reproduce the issue

I experienced this issue with a model I built using EGRET. A zip archive containing the referenced data file is attached.
[case_ACTIVSg200.zip](https://github.com/Pyomo/pyomo/files/9066929/case_ACTIVSg200.zip)


```python
from egret.models.dcopf import create_ptdf_dcopf_model
from egret.parsers.matpower_parser import create_ModelData

md_dict = create_ModelData('case_ACTIVSg200.m')
md_dict.data['system']['load_mismatch_cost'] = 1
model, md_dict = create_ptdf_dcopf_model(md_dict, include_feasibility_slack=True, ptdf_options={'lazy': False})

model_clone = model.clone()
```

### Error Message

Pyomo prints messages like the following to the console but does not terminate.

```console
ERROR: Unable to clone Pyomo component attribute. Component 'pf['1']' contains
    an uncopyable field '_expr' (<class
    'pyomo.core.expr.numeric_expr.SumExpression'>)
...
...
...
ERROR: Unable to clone Pyomo component attribute. Component 'pf['245']'
    contains an uncopyable field '_expr' (<class
    'pyomo.core.expr.numeric_expr.SumExpression'>)
```

By hacking at `pyomo/core/base/component.py`, I was able to coerce Pyomo into printing the following traceback:

```console
Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 272, in _reconstruct
    y.__setstate__(state)
  File "pyomo\core\expr\numvalue.pyx", line 507, in pyomo.core.expr.numvalue.NumericValue.__setstate__
  File "pyomo\core\expr\numeric_expr.pyx", line 1355, in pyomo.core.expr.numeric_expr.LinearExpression._args_
IndexError: list index out of range

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 272, in _reconstruct
    y.__setstate__(state)
  File "pyomo\core\expr\numvalue.pyx", line 507, in pyomo.core.expr.numvalue.NumericValue.__setstate__
  File "pyomo\core\expr\numeric_expr.pyx", line 1355, in pyomo.core.expr.numeric_expr.LinearExpression._args_
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\block.py", line 1237, in clone
    new_block = copy.deepcopy(
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 193, in __deepcopy__
    sys.exit()
SystemExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 272, in _reconstruct
    y.__setstate__(state)
  File "pyomo\core\expr\numvalue.pyx", line 507, in pyomo.core.expr.numvalue.NumericValue.__setstate__
  File "pyomo\core\expr\numeric_expr.pyx", line 1355, in pyomo.core.expr.numeric_expr.LinearExpression._args_
IndexError: list index out of range

ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 272, in _reconstruct
    y.__setstate__(state)
  File "pyomo\core\expr\numvalue.pyx", line 507, in pyomo.core.expr.numvalue.NumericValue.__setstate__
  File "pyomo\core\expr\numeric_expr.pyx", line 1355, in pyomo.core.expr.numeric_expr.LinearExpression._args_
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\block.py", line 1237, in clone
    new_block = copy.deepcopy(
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 193, in __deepcopy__
    sys.exit()
SystemExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 272, in _reconstruct
    y.__setstate__(state)
  File "pyomo\core\expr\numvalue.pyx", line 507, in pyomo.core.expr.numvalue.NumericValue.__setstate__
  File "pyomo\core\expr\numeric_expr.pyx", line 1355, in pyomo.core.expr.numeric_expr.LinearExpression._args_
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-dfad7addae03>", line 1, in <module>
    model.clone()
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\block.py", line 1243, in clone
    new_block = copy.deepcopy(
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 187, in __deepcopy__
    new_state = deepcopy(state, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\copy.py", line 153, in deepcopy
    y = copier(memo)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py", line 193, in __deepcopy__
    sys.exit()
SystemExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py", line 1101, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py", line 248, in wrapped
    return f(*args, **kwargs)
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py", line 281, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\Users\bgaustg\Anaconda3\envs\mpi-sppy\lib\inspect.py", line 1541, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
AttributeError: 'tuple' object has no attribute 'tb_frame'
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    186                 saved_memo = dict(memo)
--> 187             new_state = deepcopy(state, memo)
    188         #except:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    171                 else:
--> 172                     y = _reconstruct(x, memo, *rv)
    173

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    269         if deep:
--> 270             state = deepcopy(state, memo)
    271         if hasattr(y, '__setstate__'):

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_list(x, memo, deepcopy)
    204     for a in x:
--> 205         append(deepcopy(a, memo))
    206     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    171                 else:
--> 172                     y = _reconstruct(x, memo, *rv)
    173

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    271         if hasattr(y, '__setstate__'):
--> 272             y.__setstate__(state)
    273         else:

pyomo\core\expr\numvalue.pyx in pyomo.core.expr.numvalue.NumericValue.__setstate__()

pyomo\core\expr\numeric_expr.pyx in pyomo.core.expr.numeric_expr.LinearExpression._args_()

IndexError: list index out of range

During handling of the above exception, another exception occurred:

SystemExit                                Traceback (most recent call last)
~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\block.py in clone(self)
   1236         try:
-> 1237             new_block = copy.deepcopy(
   1238                 self, {

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    152             if copier is not None:
--> 153                 y = copier(memo)
    154             else:

~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    186                 saved_memo = dict(memo)
--> 187             new_state = deepcopy(state, memo)
    188         #except:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_list(x, memo, deepcopy)
    204     for a in x:
--> 205         append(deepcopy(a, memo))
    206     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_tuple(x, memo, deepcopy)
    209 def _deepcopy_tuple(x, memo, deepcopy=deepcopy):
--> 210     y = [deepcopy(a, memo) for a in x]
    211     # We're not going to put the tuple in the memo, but it's still important we

~\Anaconda3\envs\mpi-sppy\lib\copy.py in <listcomp>(.0)
    209 def _deepcopy_tuple(x, memo, deepcopy=deepcopy):
--> 210     y = [deepcopy(a, memo) for a in x]
    211     # We're not going to put the tuple in the memo, but it's still important we

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    152             if copier is not None:
--> 153                 y = copier(memo)
    154             else:

~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    186                 saved_memo = dict(memo)
--> 187             new_state = deepcopy(state, memo)
    188         #except:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    152             if copier is not None:
--> 153                 y = copier(memo)
    154             else:

~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    192             print(traceback.format_exc())
--> 193             sys.exit()
    194             if paranoid:

SystemExit:

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    186                 saved_memo = dict(memo)
--> 187             new_state = deepcopy(state, memo)
    188         #except:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    171                 else:
--> 172                     y = _reconstruct(x, memo, *rv)
    173

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    269         if deep:
--> 270             state = deepcopy(state, memo)
    271         if hasattr(y, '__setstate__'):

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_list(x, memo, deepcopy)
    204     for a in x:
--> 205         append(deepcopy(a, memo))
    206     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    171                 else:
--> 172                     y = _reconstruct(x, memo, *rv)
    173

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    271         if hasattr(y, '__setstate__'):
--> 272             y.__setstate__(state)
    273         else:

pyomo\core\expr\numvalue.pyx in pyomo.core.expr.numvalue.NumericValue.__setstate__()

pyomo\core\expr\numeric_expr.pyx in pyomo.core.expr.numeric_expr.LinearExpression._args_()

IndexError: list index out of range

During handling of the above exception, another exception occurred:

SystemExit                                Traceback (most recent call last)
    [... skipping hidden 1 frame]

<ipython-input-2-dfad7addae03> in <module>
----> 1 model.clone()

~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\block.py in clone(self)
   1242         except:
-> 1243             new_block = copy.deepcopy(
   1244                 self, {

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    152             if copier is not None:
--> 153                 y = copier(memo)
    154             else:

~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    186                 saved_memo = dict(memo)
--> 187             new_state = deepcopy(state, memo)
    188         #except:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_list(x, memo, deepcopy)
    204     for a in x:
--> 205         append(deepcopy(a, memo))
    206     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_tuple(x, memo, deepcopy)
    209 def _deepcopy_tuple(x, memo, deepcopy=deepcopy):
--> 210     y = [deepcopy(a, memo) for a in x]
    211     # We're not going to put the tuple in the memo, but it's still important we

~\Anaconda3\envs\mpi-sppy\lib\copy.py in <listcomp>(.0)
    209 def _deepcopy_tuple(x, memo, deepcopy=deepcopy):
--> 210     y = [deepcopy(a, memo) for a in x]
    211     # We're not going to put the tuple in the memo, but it's still important we

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    152             if copier is not None:
--> 153                 y = copier(memo)
    154             else:

~\Anaconda3\envs\mpi-sppy\lib\site-packages\pyomo\core\base\component.py in __deepcopy__(self, memo)
    186                 saved_memo = dict(memo)
--> 187             new_state = deepcopy(state, memo)
    188         #except:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    145     if copier is not None:
--> 146         y = copier(x, memo)
    147     else:

~\Anaconda3\envs\mpi-sppy\lib\copy.py in _deepcopy_dict(x, memo, deepcopy)
    229     for key, value in x.items():
--> 230         y[deepcopy(key, memo)] = deepcopy(value, memo)
    231     return y

~\Anaconda3\envs\mpi-sppy\lib\copy.py in deepcopy(x, memo, _nil)
    152             if copier is not None:
--> 153                 y = copier(memo)
    154             else:

    192             print(traceback.format_exc())
--> 193             sys.exit()
    194             if paranoid:

SystemExit:

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
    [... skipping hidden 1 frame]

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\interactiveshell.py in showtraceback(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)
   2055                     stb = ['An exception has occurred, use %tb to see '
   2056                            'the full traceback.\n']
-> 2057                     stb.extend(self.InteractiveTB.get_exception_only(etype,
   2058                                                                      value))
   2059                 else:

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in get_exception_only(self, etype, value)
    752         value : exception value
    753         """
--> 754         return ListTB.structured_traceback(self, etype, value)
    755
    756     def show_exception_only(self, etype, evalue):

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, evalue, etb, tb_offset, context)
    628             out_list = (
--> 629                 self.structured_traceback(
    630                     etype, evalue, (etb, chained_exc_ids),
    631                     chained_exceptions_tb_offset, context)

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1365         else:
   1366             self.tb = tb
-> 1367         return FormattedTB.structured_traceback(
   1368             self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1369

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1265         if mode in self.verbose_modes:
   1266             # Verbose modes need a full traceback
-> 1267             return VerboseTB.structured_traceback(
   1268                 self, etype, value, tb, tb_offset, number_of_lines_of_context
   1269             )

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1122         """Return a nice text document describing the traceback."""
   1123
-> 1124         formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
   1125                                                                tb_offset)
   1126

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)
   1080
   1081
-> 1082         last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
   1083
   1084         frames = self.format_records(records, last_unique, recursion_repeat)

~\Anaconda3\envs\mpi-sppy\lib\site-packages\IPython\core\ultratb.py in find_recursion(etype, value, records)
    380     # first frame (from in to out) that looks different.
    381     if not is_recursion_error(etype, value, records):
--> 382         return len(records), 0
    383
    384     # Select filename, lineno, func_name to track frames with

TypeError: object of type 'NoneType' has no len()
```

### Information on your system

Pyomo version: 6.4.1
Python version: 3.9.5
Operating system: Windows 10.0.19044 Build 19044
How Pyomo was installed (PyPI, conda, source): conda
Solver (if applicable): N/A




Discussion:

Resolving patch:
diff --git a/pyomo/core/expr/numeric_expr.py b/pyomo/core/expr/numeric_expr.py
--- a/pyomo/core/expr/numeric_expr.py
+++ b/pyomo/core/expr/numeric_expr.py
@@ -1352,6 +1352,11 @@ def _args_(self):
     @_args_.setter
     def _args_(self, value):
         self._args_cache_ = list(value)
+        if not self._args_cache_:
+            self.constant = 0
+            self.linear_coefs = []
+            self.linear_vars = []
+            return
         if self._args_cache_[0].__class__ is not MonomialTermExpression:
             self.constant = value[0]
             first_var = 1


Test patch:
diff --git a/pyomo/core/tests/unit/test_numeric_expr.py b/pyomo/core/tests/unit/test_numeric_expr.py
--- a/pyomo/core/tests/unit/test_numeric_expr.py
+++ b/pyomo/core/tests/unit/test_numeric_expr.py
@@ -4053,6 +4053,35 @@ def test_Expr_if(self):
             total = counter.count - start
             self.assertEqual(total, 1)
 
+    def test_LinearExpression(self):
+        m = ConcreteModel()
+        m.x = Var()
+        m.y = Var([1,2])
+        e = LinearExpression()
+        f = e.clone()
+        self.assertIsNot(e, f)
+        self.assertIsNot(e.linear_coefs, f.linear_coefs)
+        self.assertIsNot(e.linear_vars, f.linear_vars)
+        self.assertEqual(e.constant, f.constant)
+        self.assertEqual(e.linear_coefs, f.linear_coefs)
+        self.assertEqual(e.linear_vars, f.linear_vars)
+        self.assertEqual(f.constant, 0)
+        self.assertEqual(f.linear_coefs, [])
+        self.assertEqual(f.linear_vars, [])
+
+        e = LinearExpression(
+            constant=5, linear_vars=[m.x, m.y[1]], linear_coefs=[10, 20])
+        f = e.clone()
+        self.assertIsNot(e, f)
+        self.assertIsNot(e.linear_coefs, f.linear_coefs)
+        self.assertIsNot(e.linear_vars, f.linear_vars)
+        self.assertEqual(e.constant, f.constant)
+        self.assertEqual(e.linear_coefs, f.linear_coefs)
+        self.assertEqual(e.linear_vars, f.linear_vars)
+        self.assertEqual(f.constant, 5)
+        self.assertEqual(f.linear_coefs, [10, 20])
+        self.assertEqual(f.linear_vars, [m.x, m.y[1]])
+
     def test_getitem(self):
         # Testing cloning of the abs() function
         with clone_counter() as counter: