We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
tn.set_default_backend should raise exception
`tn.set_default_backend(backend_name)` should raise if `backend_name` is not a valid backend.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tensornetwork/backend_contextmanager.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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

{"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"}], "after_files": [{"content": "from typing import Text, Union\nfrom tensornetwork.backends.base_backend import BaseBackend\nfrom tensornetwork.backends import backend_factory\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  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", "path": "tensornetwork/backend_contextmanager.py"}]}