prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Fixed Vars unpickle as stale
  ## Summary
  
  I'm not sure if this is a bug, but it seems unexpected? Anyway, if you pickle a model that has a fixed variable (not stale), when you unpickle it, it comes back as stale.
  
  ### Steps to reproduce the issue
  
  ```
  from pyomo.environ import *
  import pickle
  
  m = ConcreteModel()
  m.x = Var(domain=Binary)
  m.x.fix(1)
  
  unpickle = pickle.loads(pickle.dumps(m))
  
  m.x.pprint()
  unpickle.x.pprint()
  ```
  
  ```
  x : Size=1, Index=None
      Key  : Lower : Value : Upper : Fixed : Stale : Domain
      None :     0 :     1 :     1 :  True : False : Binary
  x : Size=1, Index=None
      Key  : Lower : Value : Upper : Fixed : Stale : Domain
      None :     0 :     1 :     1 :  True :  True : Binary
  ```
  
  ### Error Message
  
  It seems like these models should be identical, even up to stale-ness, right?
  
  ### Information on your system
  
  Pyomo version: main
  Python version: 3.8
  Operating system: linux
  How Pyomo was installed (PyPI, conda, source): source 
  Solver (if applicable):
  
  </issue>
  <code>
  [start of pyomo/core/staleflag.py]
  1 #  ___________________________________________________________________________
  2 #
  3 #  Pyomo: Python Optimization Modeling Objects
  4 #  Copyright (c) 2008-2022
  5 #  National Technology and Engineering Solutions of Sandia, LLC
  6 #  Under the terms of Contract DE-NA0003525 with National Technology and
  7 #  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
  8 #  rights in this software.
  9 #  This software is distributed under the 3-clause BSD License.
  10 #  ___________________________________________________________________________
  11 
  12 class _StaleFlagManager(object):
  13     def __init__(self):
  14         self._current = 0
  15         self.mark_all_as_stale()
  16 
  17     def stale_mapper(self, encode, value):
  18         if encode:
  19             return self.is_stale(value)
  20         else:
  21             if value:
  22                 return 0
  23             else:
  24                 self.get_flag(0)
  25 
  26     def _get_flag(self, current_flag):
  27         """Return the current global stale flag value"""
  28         return self._current
  29 
  30     def _get_flag_delayed(self, current_flag):
  31         """Implement the "delayed" advancement of the global stale flag value
  32 
  33         This will continue to return the current value of the state flag
  34         until the first non-stale variable is updated (that it, it is
  35         passed the current stale flag when called).  This allows for
  36         updating stale variable values without incrementing the global
  37         stale flag, but will mark everything as stale as soon as a
  38         non-stale variable value is changed.
  39 
  40         """
  41         if current_flag == self._current:
  42             self._current += 1
  43             setattr(self, 'get_flag', getattr(self, '_get_flag'))
  44         return self._current
  45 
  46     def is_stale(self, val):
  47         """Return ``True`` if the passed value indicated a stale variable"""
  48         return val != self._current
  49 
  50     def mark_all_as_stale(self, delayed=False):
  51         """Advance the global stale flag, marking all variables as stale
  52 
  53         This is generally called immediately before and after a batch
  54         variable update (i.e. loading values from a solver result or
  55         stored solution).  Before the batch update
  56         :meth:`mark_all_as_stale` is called with ``delayed=False``,
  57         which immediately marks all variables as stale.  After the batch
  58         update, :meth:`mark_all_as_stale` is typically called with
  59         ``delayed=True``.  This allows additional stale variables to be
  60         updated without advancing the global flag, but as soon as any
  61         non-stale variable has its value changed, then the flag is
  62         advanced and all other variables become stale.
  63 
  64         """
  65         if delayed:
  66             setattr(self, 'get_flag', getattr(self, '_get_flag_delayed'))
  67         else:
  68             setattr(self, 'get_flag', getattr(self, '_get_flag'))
  69             self._current += 1
  70 
  71 StaleFlagManager = _StaleFlagManager()
  72
  [end of pyomo/core/staleflag.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pyomo/core/staleflag.py b/pyomo/core/staleflag.py
  --- a/pyomo/core/staleflag.py
  +++ b/pyomo/core/staleflag.py
  @@ -21,7 +21,7 @@
               if value:
                   return 0
               else:
  -                self.get_flag(0)
  +                return self.get_flag(0)
   
       def _get_flag(self, current_flag):
           """Return the current global stale flag value"""
  
verification_info: {"golden_diff": "diff --git a/pyomo/core/staleflag.py b/pyomo/core/staleflag.py\n--- a/pyomo/core/staleflag.py\n+++ b/pyomo/core/staleflag.py\n@@ -21,7 +21,7 @@\n             if value:\n                 return 0\n             else:\n-                self.get_flag(0)\n+                return self.get_flag(0)\n \n     def _get_flag(self, current_flag):\n         \"\"\"Return the current global stale flag value\"\"\"\n", "issue": "Fixed Vars unpickle as stale\n## Summary\r\n\r\nI'm not sure if this is a bug, but it seems unexpected? Anyway, if you pickle a model that has a fixed variable (not stale), when you unpickle it, it comes back as stale.\r\n\r\n### Steps to reproduce the issue\r\n\r\n```\r\nfrom pyomo.environ import *\r\nimport pickle\r\n\r\nm = ConcreteModel()\r\nm.x = Var(domain=Binary)\r\nm.x.fix(1)\r\n\r\nunpickle = pickle.loads(pickle.dumps(m))\r\n\r\nm.x.pprint()\r\nunpickle.x.pprint()\r\n```\r\n\r\n```\r\nx : Size=1, Index=None\r\n    Key  : Lower : Value : Upper : Fixed : Stale : Domain\r\n    None :     0 :     1 :     1 :  True : False : Binary\r\nx : Size=1, Index=None\r\n    Key  : Lower : Value : Upper : Fixed : Stale : Domain\r\n    None :     0 :     1 :     1 :  True :  True : Binary\r\n```\r\n\r\n### Error Message\r\n\r\nIt seems like these models should be identical, even up to stale-ness, right?\r\n\r\n### Information on your system\r\n\r\nPyomo version: main\r\nPython version: 3.8\r\nOperating system: linux\r\nHow Pyomo was installed (PyPI, conda, source): source \r\nSolver (if applicable):\n", "before_files": [{"content": "#  ___________________________________________________________________________\n#\n#  Pyomo: Python Optimization Modeling Objects\n#  Copyright (c) 2008-2022\n#  National Technology and Engineering Solutions of Sandia, LLC\n#  Under the terms of Contract DE-NA0003525 with National Technology and\n#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain\n#  rights in this software.\n#  This software is distributed under the 3-clause BSD License.\n#  ___________________________________________________________________________\n\nclass _StaleFlagManager(object):\n    def __init__(self):\n        self._current = 0\n        self.mark_all_as_stale()\n\n    def stale_mapper(self, encode, value):\n        if encode:\n            return self.is_stale(value)\n        else:\n            if value:\n                return 0\n            else:\n                self.get_flag(0)\n\n    def _get_flag(self, current_flag):\n        \"\"\"Return the current global stale flag value\"\"\"\n        return self._current\n\n    def _get_flag_delayed(self, current_flag):\n        \"\"\"Implement the \"delayed\" advancement of the global stale flag value\n\n        This will continue to return the current value of the state flag\n        until the first non-stale variable is updated (that it, it is\n        passed the current stale flag when called).  This allows for\n        updating stale variable values without incrementing the global\n        stale flag, but will mark everything as stale as soon as a\n        non-stale variable value is changed.\n\n        \"\"\"\n        if current_flag == self._current:\n            self._current += 1\n            setattr(self, 'get_flag', getattr(self, '_get_flag'))\n        return self._current\n\n    def is_stale(self, val):\n        \"\"\"Return ``True`` if the passed value indicated a stale variable\"\"\"\n        return val != self._current\n\n    def mark_all_as_stale(self, delayed=False):\n        \"\"\"Advance the global stale flag, marking all variables as stale\n\n        This is generally called immediately before and after a batch\n        variable update (i.e. loading values from a solver result or\n        stored solution).  Before the batch update\n        :meth:`mark_all_as_stale` is called with ``delayed=False``,\n        which immediately marks all variables as stale.  After the batch\n        update, :meth:`mark_all_as_stale` is typically called with\n        ``delayed=True``.  This allows additional stale variables to be\n        updated without advancing the global flag, but as soon as any\n        non-stale variable has its value changed, then the flag is\n        advanced and all other variables become stale.\n\n        \"\"\"\n        if delayed:\n            setattr(self, 'get_flag', getattr(self, '_get_flag_delayed'))\n        else:\n            setattr(self, 'get_flag', getattr(self, '_get_flag'))\n            self._current += 1\n\nStaleFlagManager = _StaleFlagManager()\n", "path": "pyomo/core/staleflag.py"}]}