prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  tn.set_default_backend should raise exception
  `tn.set_default_backend(backend_name)` should raise if `backend_name` is not a valid backend.
  
  </issue>
  <code>
  [start of tensornetwork/backend_contextmanager.py]
  1 from typing import Text, Union
  2 from tensornetwork.backends.base_backend import BaseBackend
  3 
  4 class DefaultBackend():
  5   """Context manager for setting up backend for nodes"""
  6 
  7   def __init__(self, backend: Union[Text, BaseBackend]) -> None:
  8     if not isinstance(backend, (Text, BaseBackend)):
  9       raise ValueError("Item passed to DefaultBackend "
  10                        "must be Text or BaseBackend")
  11     self.backend = backend
  12 
  13   def __enter__(self):
  14     _default_backend_stack.stack.append(self)
  15 
  16   def __exit__(self, exc_type, exc_val, exc_tb):
  17     _default_backend_stack.stack.pop()
  18 
  19 class _DefaultBackendStack():
  20   """A stack to keep track default backends context manager"""
  21 
  22   def __init__(self):
  23     self.stack = []
  24     self.default_backend = "numpy"
  25 
  26   def get_current_backend(self):
  27     return self.stack[-1].backend if self.stack else self.default_backend
  28 
  29 _default_backend_stack = _DefaultBackendStack()
  30 
  31 def get_default_backend():
  32   return _default_backend_stack.get_current_backend()
  33 
  34 def set_default_backend(backend: Union[Text, BaseBackend]) -> None:
  35   if _default_backend_stack.stack:
  36     raise AssertionError("The default backend should not be changed "
  37                          "inside the backend context manager")
  38   if not isinstance(backend, (Text, BaseBackend)):
  39     raise ValueError("Item passed to set_default_backend "
  40                      "must be Text or BaseBackend")
  41   _default_backend_stack.default_backend = backend
  42
  [end of tensornetwork/backend_contextmanager.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/tensornetwork/backend_contextmanager.py b/tensornetwork/backend_contextmanager.py
  --- a/tensornetwork/backend_contextmanager.py
  +++ b/tensornetwork/backend_contextmanager.py
  @@ -1,5 +1,6 @@
   from typing import Text, Union
   from tensornetwork.backends.base_backend import BaseBackend
  +from tensornetwork.backends import backend_factory
   
   class DefaultBackend():
     """Context manager for setting up backend for nodes"""
  @@ -38,4 +39,6 @@
     if not isinstance(backend, (Text, BaseBackend)):
       raise ValueError("Item passed to set_default_backend "
                        "must be Text or BaseBackend")
  +  if isinstance(backend, Text) and backend not in backend_factory._BACKENDS:
  +    raise ValueError(f"Backend '{backend}' was not found.")
     _default_backend_stack.default_backend = backend
  
verification_info: {"golden_diff": "diff --git a/tensornetwork/backend_contextmanager.py b/tensornetwork/backend_contextmanager.py\n--- a/tensornetwork/backend_contextmanager.py\n+++ b/tensornetwork/backend_contextmanager.py\n@@ -1,5 +1,6 @@\n from typing import Text, Union\n from tensornetwork.backends.base_backend import BaseBackend\n+from tensornetwork.backends import backend_factory\n \n class DefaultBackend():\n   \"\"\"Context manager for setting up backend for nodes\"\"\"\n@@ -38,4 +39,6 @@\n   if not isinstance(backend, (Text, BaseBackend)):\n     raise ValueError(\"Item passed to set_default_backend \"\n                      \"must be Text or BaseBackend\")\n+  if isinstance(backend, Text) and backend not in backend_factory._BACKENDS:\n+    raise ValueError(f\"Backend '{backend}' was not found.\")\n   _default_backend_stack.default_backend = backend\n", "issue": "tn.set_default_backend should raise exception\n`tn.set_default_backend(backend_name)` should raise if `backend_name` is not a valid backend.\n", "before_files": [{"content": "from typing import Text, Union\nfrom tensornetwork.backends.base_backend import BaseBackend\n\nclass DefaultBackend():\n  \"\"\"Context manager for setting up backend for nodes\"\"\"\n\n  def __init__(self, backend: Union[Text, BaseBackend]) -> None:\n    if not isinstance(backend, (Text, BaseBackend)):\n      raise ValueError(\"Item passed to DefaultBackend \"\n                       \"must be Text or BaseBackend\")\n    self.backend = backend\n\n  def __enter__(self):\n    _default_backend_stack.stack.append(self)\n\n  def __exit__(self, exc_type, exc_val, exc_tb):\n    _default_backend_stack.stack.pop()\n\nclass _DefaultBackendStack():\n  \"\"\"A stack to keep track default backends context manager\"\"\"\n\n  def __init__(self):\n    self.stack = []\n    self.default_backend = \"numpy\"\n\n  def get_current_backend(self):\n    return self.stack[-1].backend if self.stack else self.default_backend\n\n_default_backend_stack = _DefaultBackendStack()\n\ndef get_default_backend():\n  return _default_backend_stack.get_current_backend()\n\ndef set_default_backend(backend: Union[Text, BaseBackend]) -> None:\n  if _default_backend_stack.stack:\n    raise AssertionError(\"The default backend should not be changed \"\n                         \"inside the backend context manager\")\n  if not isinstance(backend, (Text, BaseBackend)):\n    raise ValueError(\"Item passed to set_default_backend \"\n                     \"must be Text or BaseBackend\")\n  _default_backend_stack.default_backend = backend\n", "path": "tensornetwork/backend_contextmanager.py"}]}