prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  from_mpc failed to load the case generated by to_mpc
  After checking the source code, I found the to_mpc function saves the fields in a loose format. According to the from_mpc function, all the fields should be under a variable called "mpc" (default), however the to_mpc function does not follow this, which leads to a situation that the from_mpc function cannot load the case generated by the to_mpc function.
  
  </issue>
  <code>
  [start of pandapower/converter/matpower/to_mpc.py]
  1 # -*- coding: utf-8 -*-
  2 
  3 # Copyright (c) 2016-2019 by University of Kassel and Fraunhofer Institute for Energy Economics
  4 # and Energy System Technology (IEE), Kassel. All rights reserved.
  5 
  6 
  7 import copy
  8 
  9 import numpy as np
  10 from scipy.io import savemat
  11 
  12 from pandapower.converter.pypower import to_ppc
  13 
  14 try:
  15     import pplog as logging
  16 except ImportError:
  17     import logging
  18 
  19 logger = logging.getLogger(__name__)
  20 
  21 
  22 def to_mpc(net, filename=None, **kwargs):
  23     """
  24     This function converts a pandapower net to a matpower case files (.mat) version 2.
  25     Note: python is 0-based while Matlab is 1-based.
  26 
  27     INPUT:
  28         **net** - The pandapower net.
  29 
  30     OPTIONAL:
  31         **filename** (str, None) - File path + name of the mat file which will be created. If None
  32             the mpc will only be returned
  33 
  34         ****kwargs** - please look at to_ppc() documentation
  35 
  36     EXAMPLE:
  37         import pandapower.converter as pc
  38         import pandapower.networks as pn
  39         net = pn.case9()
  40         pc.to_mpc(net, "case9.mat")
  41 
  42     """
  43     ppc = to_ppc(net, **kwargs)
  44 
  45     mpc = _ppc2mpc(ppc)
  46     if filename is not None:
  47         # savemat
  48         savemat(filename, mpc)
  49 
  50     return mpc
  51 
  52 
  53 def _ppc2mpc(ppc):
  54     """
  55     Convert network in Pypower/Matpower format
  56     Convert 0-based python to 1-based Matlab
  57 
  58     **INPUT**:
  59         * net - The pandapower format network
  60         * filename - File path + name of the mat file which is created
  61     """
  62 
  63     # convert to matpower
  64     # Matlab is one-based, so all entries (buses, lines, gens) have to start with 1 instead of 0
  65     mpc = copy.deepcopy(ppc)
  66     if len(np.where(mpc["bus"][:, 0] == 0)[0]):
  67         mpc["bus"][:, 0] = mpc["bus"][:, 0] + 1
  68         mpc["gen"][:, 0] = mpc["gen"][:, 0] + 1
  69         mpc["branch"][:, 0:2] = mpc["branch"][:, 0:2] + 1
  70     # adjust for the matpower converter -> taps should be 0 when there is no transformer, but are 1
  71     mpc["branch"][np.where(mpc["branch"][:, 8] == 1), 8] = 0
  72     # version is a string
  73     mpc["version"] = str(mpc["version"])
  74     # baseMVA has to be a float instead of int
  75     mpc["baseMVA"] = mpc["baseMVA"] * 1.0
  76     return mpc
  77 
  78 
  79 if "__main__" == __name__:
  80     pass
  81
  [end of pandapower/converter/matpower/to_mpc.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/pandapower/converter/matpower/to_mpc.py b/pandapower/converter/matpower/to_mpc.py
  --- a/pandapower/converter/matpower/to_mpc.py
  +++ b/pandapower/converter/matpower/to_mpc.py
  @@ -42,7 +42,8 @@
       """
       ppc = to_ppc(net, **kwargs)
   
  -    mpc = _ppc2mpc(ppc)
  +    mpc = dict()
  +    mpc["mpc"] = _ppc2mpc(ppc)
       if filename is not None:
           # savemat
           savemat(filename, mpc)
  
verification_info: {"golden_diff": "diff --git a/pandapower/converter/matpower/to_mpc.py b/pandapower/converter/matpower/to_mpc.py\n--- a/pandapower/converter/matpower/to_mpc.py\n+++ b/pandapower/converter/matpower/to_mpc.py\n@@ -42,7 +42,8 @@\n     \"\"\"\n     ppc = to_ppc(net, **kwargs)\n \n-    mpc = _ppc2mpc(ppc)\n+    mpc = dict()\n+    mpc[\"mpc\"] = _ppc2mpc(ppc)\n     if filename is not None:\n         # savemat\n         savemat(filename, mpc)\n", "issue": "from_mpc failed to load the case generated by to_mpc\nAfter checking the source code, I found the to_mpc function saves the fields in a loose format. According to the from_mpc function, all the fields should be under a variable called \"mpc\" (default), however the to_mpc function does not follow this, which leads to a situation that the from_mpc function cannot load the case generated by the to_mpc function.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright (c) 2016-2019 by University of Kassel and Fraunhofer Institute for Energy Economics\n# and Energy System Technology (IEE), Kassel. All rights reserved.\n\n\nimport copy\n\nimport numpy as np\nfrom scipy.io import savemat\n\nfrom pandapower.converter.pypower import to_ppc\n\ntry:\n    import pplog as logging\nexcept ImportError:\n    import logging\n\nlogger = logging.getLogger(__name__)\n\n\ndef to_mpc(net, filename=None, **kwargs):\n    \"\"\"\n    This function converts a pandapower net to a matpower case files (.mat) version 2.\n    Note: python is 0-based while Matlab is 1-based.\n\n    INPUT:\n        **net** - The pandapower net.\n\n    OPTIONAL:\n        **filename** (str, None) - File path + name of the mat file which will be created. If None\n            the mpc will only be returned\n\n        ****kwargs** - please look at to_ppc() documentation\n\n    EXAMPLE:\n        import pandapower.converter as pc\n        import pandapower.networks as pn\n        net = pn.case9()\n        pc.to_mpc(net, \"case9.mat\")\n\n    \"\"\"\n    ppc = to_ppc(net, **kwargs)\n\n    mpc = _ppc2mpc(ppc)\n    if filename is not None:\n        # savemat\n        savemat(filename, mpc)\n\n    return mpc\n\n\ndef _ppc2mpc(ppc):\n    \"\"\"\n    Convert network in Pypower/Matpower format\n    Convert 0-based python to 1-based Matlab\n\n    **INPUT**:\n        * net - The pandapower format network\n        * filename - File path + name of the mat file which is created\n    \"\"\"\n\n    # convert to matpower\n    # Matlab is one-based, so all entries (buses, lines, gens) have to start with 1 instead of 0\n    mpc = copy.deepcopy(ppc)\n    if len(np.where(mpc[\"bus\"][:, 0] == 0)[0]):\n        mpc[\"bus\"][:, 0] = mpc[\"bus\"][:, 0] + 1\n        mpc[\"gen\"][:, 0] = mpc[\"gen\"][:, 0] + 1\n        mpc[\"branch\"][:, 0:2] = mpc[\"branch\"][:, 0:2] + 1\n    # adjust for the matpower converter -> taps should be 0 when there is no transformer, but are 1\n    mpc[\"branch\"][np.where(mpc[\"branch\"][:, 8] == 1), 8] = 0\n    # version is a string\n    mpc[\"version\"] = str(mpc[\"version\"])\n    # baseMVA has to be a float instead of int\n    mpc[\"baseMVA\"] = mpc[\"baseMVA\"] * 1.0\n    return mpc\n\n\nif \"__main__\" == __name__:\n    pass\n", "path": "pandapower/converter/matpower/to_mpc.py"}]}