We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove nest_asyncio from bittensor to allow uvloop support
### Is your feature request related to a problem? Please describe.

Uvloop, which provides supperior speed, does not allow loop nesting.

It is also the case that uvloop is pulled in by popular packages, which [forces some subnets develop hacks to combat this](https://github.com/synapsec-ai/llm-defender-subnet/blob/6c37925c4f34a298607c97dfceebcc01fb74d562/scripts/run_neuron.sh#L140-L146).

And perhaps more importantly, https://github.com/erdewit/nest_asyncio seems to have been abandodend 

### Describe the solution you'd like

Remove nest_asyncio, and let bittensor users decide which asyncio loop they want to run. Perhaps even suggest (not mandate) running uvloop, since it consistently shows better results in benchmarks than CPython asyncio stdlib loop.

Seems like there was some attempt of this in the past https://github.com/opentensor/bittensor/pull/1501 for some reason (?) 

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bittensor/__init__.py`
Content:
```
1 # The MIT License (MIT)
2 # Copyright © 2021 Yuma Rao
3 # Copyright © 2022-2023 Opentensor Foundation
4 # Copyright © 2023 Opentensor Technologies Inc
5 
6 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7 # documentation files (the “Software”), to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 # and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10 
11 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of
12 # the Software.
13 
14 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15 # THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 # DEALINGS IN THE SOFTWARE.
19 
20 from rich.console import Console
21 from rich.traceback import install
22 
23 # Install and apply nest asyncio to allow the async functions
24 # to run in a .ipynb
25 import nest_asyncio
26 
27 nest_asyncio.apply()
28 
29 # Bittensor code and protocol version.
30 __version__ = "7.0.0"
31 
32 version_split = __version__.split(".")
33 __version_as_int__: int = (
34     (100 * int(version_split[0]))
35     + (10 * int(version_split[1]))
36     + (1 * int(version_split[2]))
37 )
38 __new_signature_version__ = 360
39 
40 # Rich console.
41 __console__ = Console()
42 __use_console__ = True
43 
44 # Remove overdue locals in debug training.
45 install(show_locals=False)
46 
47 
48 def turn_console_off():
49     global __use_console__
50     global __console__
51     from io import StringIO
52 
53     __use_console__ = False
54     __console__ = Console(file=StringIO(), stderr=False)
55 
56 
57 def turn_console_on():
58     global __use_console__
59     global __console__
60     __use_console__ = True
61     __console__ = Console()
62 
63 
64 turn_console_off()
65 
66 
67 # Logging helpers.
68 def trace(on: bool = True):
69     logging.set_trace(on)
70 
71 
72 def debug(on: bool = True):
73     logging.set_debug(on)
74 
75 
76 # Substrate chain block time (seconds).
77 __blocktime__ = 12
78 
79 # Pip address for versioning
80 __pipaddress__ = "https://pypi.org/pypi/bittensor/json"
81 
82 # Raw GitHub url for delegates registry file
83 __delegates_details_url__: str = "https://raw.githubusercontent.com/opentensor/bittensor-delegates/main/public/delegates.json"
84 
85 # Substrate ss58_format
86 __ss58_format__ = 42
87 
88 # Wallet ss58 address length
89 __ss58_address_length__ = 48
90 
91 __networks__ = ["local", "finney", "test", "archive"]
92 
93 __finney_entrypoint__ = "wss://entrypoint-finney.opentensor.ai:443"
94 
95 __finney_test_entrypoint__ = "wss://test.finney.opentensor.ai:443/"
96 
97 __archive_entrypoint__ = "wss://archive.chain.opentensor.ai:443/"
98 
99 # Needs to use wss://
100 __bellagene_entrypoint__ = "wss://parachain.opentensor.ai:443"
101 
102 __local_entrypoint__ = "ws://127.0.0.1:9944"
103 
104 __tao_symbol__: str = chr(0x03C4)
105 
106 __rao_symbol__: str = chr(0x03C1)
107 
108 # Block Explorers map network to explorer url
109 # Must all be polkadotjs explorer urls
110 __network_explorer_map__ = {
111     "opentensor": {
112         "local": "https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer",
113         "endpoint": "https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer",
114         "finney": "https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer",
115     },
116     "taostats": {
117         "local": "https://x.taostats.io",
118         "endpoint": "https://x.taostats.io",
119         "finney": "https://x.taostats.io",
120     },
121 }
122 
123 # --- Type Registry ---
124 __type_registry__ = {
125     "types": {
126         "Balance": "u64",  # Need to override default u128
127     },
128     "runtime_api": {
129         "NeuronInfoRuntimeApi": {
130             "methods": {
131                 "get_neuron_lite": {
132                     "params": [
133                         {
134                             "name": "netuid",
135                             "type": "u16",
136                         },
137                         {
138                             "name": "uid",
139                             "type": "u16",
140                         },
141                     ],
142                     "type": "Vec<u8>",
143                 },
144                 "get_neurons_lite": {
145                     "params": [
146                         {
147                             "name": "netuid",
148                             "type": "u16",
149                         },
150                     ],
151                     "type": "Vec<u8>",
152                 },
153             }
154         },
155         "StakeInfoRuntimeApi": {
156             "methods": {
157                 "get_stake_info_for_coldkey": {
158                     "params": [
159                         {
160                             "name": "coldkey_account_vec",
161                             "type": "Vec<u8>",
162                         },
163                     ],
164                     "type": "Vec<u8>",
165                 },
166                 "get_stake_info_for_coldkeys": {
167                     "params": [
168                         {
169                             "name": "coldkey_account_vecs",
170                             "type": "Vec<Vec<u8>>",
171                         },
172                     ],
173                     "type": "Vec<u8>",
174                 },
175             },
176         },
177         "ValidatorIPRuntimeApi": {
178             "methods": {
179                 "get_associated_validator_ip_info_for_subnet": {
180                     "params": [
181                         {
182                             "name": "netuid",
183                             "type": "u16",
184                         },
185                     ],
186                     "type": "Vec<u8>",
187                 },
188             },
189         },
190         "SubnetInfoRuntimeApi": {
191             "methods": {
192                 "get_subnet_hyperparams": {
193                     "params": [
194                         {
195                             "name": "netuid",
196                             "type": "u16",
197                         },
198                     ],
199                     "type": "Vec<u8>",
200                 }
201             }
202         },
203         "SubnetRegistrationRuntimeApi": {
204             "methods": {"get_network_registration_cost": {"params": [], "type": "u64"}}
205         },
206     },
207 }
208 
209 from .errors import (
210     BlacklistedException,
211     ChainConnectionError,
212     ChainError,
213     ChainQueryError,
214     ChainTransactionError,
215     IdentityError,
216     InternalServerError,
217     InvalidRequestNameError,
218     KeyFileError,
219     MetadataError,
220     NominationError,
221     NotDelegateError,
222     NotRegisteredError,
223     NotVerifiedException,
224     PostProcessException,
225     PriorityException,
226     RegistrationError,
227     RunException,
228     StakeError,
229     SynapseDendriteNoneException,
230     SynapseParsingError,
231     TransferError,
232     UnknownSynapseError,
233     UnstakeError,
234 )
235 
236 from substrateinterface import Keypair  # noqa: F401
237 from .config import InvalidConfigFile, DefaultConfig, config, T
238 from .keyfile import (
239     serialized_keypair_to_keyfile_data,
240     deserialize_keypair_from_keyfile_data,
241     validate_password,
242     ask_password_to_encrypt,
243     keyfile_data_is_encrypted_nacl,
244     keyfile_data_is_encrypted_ansible,
245     keyfile_data_is_encrypted_legacy,
246     keyfile_data_is_encrypted,
247     keyfile_data_encryption_method,
248     legacy_encrypt_keyfile_data,
249     encrypt_keyfile_data,
250     get_coldkey_password_from_environment,
251     decrypt_keyfile_data,
252     keyfile,
253     Mockkeyfile,
254 )
255 from .wallet import display_mnemonic_msg, wallet
256 
257 from .utils import (
258     ss58_to_vec_u8,
259     unbiased_topk,
260     version_checking,
261     strtobool,
262     strtobool_with_default,
263     get_explorer_root_url_by_network_from_map,
264     get_explorer_root_url_by_network_from_map,
265     get_explorer_url_for_network,
266     ss58_address_to_bytes,
267     U16_NORMALIZED_FLOAT,
268     U64_NORMALIZED_FLOAT,
269     u8_key_to_ss58,
270     hash,
271     wallet_utils,
272 )
273 
274 from .utils.balance import Balance as Balance
275 from .chain_data import (
276     AxonInfo,
277     NeuronInfo,
278     NeuronInfoLite,
279     PrometheusInfo,
280     DelegateInfo,
281     DelegateInfoLite,
282     StakeInfo,
283     SubnetInfo,
284     SubnetHyperparameters,
285     IPInfo,
286     ProposalCallData,
287     ProposalVoteData,
288 )
289 
290 # Allows avoiding name spacing conflicts and continue access to the `subtensor` module with `subtensor_module` name
291 from . import subtensor as subtensor_module
292 
293 # Double import allows using class `Subtensor` by referencing `bittensor.Subtensor` and `bittensor.subtensor`.
294 # This will be available for a while until we remove reference `bittensor.subtensor`
295 from .subtensor import Subtensor
296 from .subtensor import Subtensor as subtensor
297 
298 from .cli import cli as cli, COMMANDS as ALL_COMMANDS
299 from .btlogging import logging
300 from .metagraph import metagraph as metagraph
301 from .threadpool import PriorityThreadPoolExecutor as PriorityThreadPoolExecutor
302 
303 from .synapse import TerminalInfo, Synapse
304 from .stream import StreamingSynapse
305 from .tensor import tensor, Tensor
306 from .axon import axon as axon
307 from .dendrite import dendrite as dendrite
308 
309 from .mock.keyfile_mock import MockKeyfile as MockKeyfile
310 from .mock.subtensor_mock import MockSubtensor as MockSubtensor
311 from .mock.wallet_mock import MockWallet as MockWallet
312 
313 from .subnets import SubnetsAPI as SubnetsAPI
314 
315 configs = [
316     axon.config(),
317     subtensor.config(),
318     PriorityThreadPoolExecutor.config(),
319     wallet.config(),
320     logging.get_config(),
321 ]
322 defaults = config.merge_all(configs)
323
```
--- 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/bittensor/__init__.py b/bittensor/__init__.py
--- a/bittensor/__init__.py
+++ b/bittensor/__init__.py
@@ -16,15 +16,28 @@
 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
+import os
+import warnings
 
 from rich.console import Console
 from rich.traceback import install
 
-# Install and apply nest asyncio to allow the async functions
-# to run in a .ipynb
-import nest_asyncio
 
-nest_asyncio.apply()
+if (NEST_ASYNCIO_ENV := os.getenv("NEST_ASYNCIO")) in ("1", None):
+    if NEST_ASYNCIO_ENV is None:
+        warnings.warn(
+            "NEST_ASYNCIO implicitly set to '1'. In the future, the default value will be '0'."
+            "If you use `nest_asyncio` make sure to add it explicitly to your project dependencies,"
+            "as it will be removed from `bittensor` package dependencies in the future."
+            "To silence this warning, explicitly set the environment variable, e.g. `export NEST_ASYNCIO=0`.",
+            DeprecationWarning,
+        )
+    # Install and apply nest asyncio to allow the async functions
+    # to run in a .ipynb
+    import nest_asyncio
+
+    nest_asyncio.apply()
+
 
 # Bittensor code and protocol version.
 __version__ = "7.0.0"

{"golden_diff": "diff --git a/bittensor/__init__.py b/bittensor/__init__.py\n--- a/bittensor/__init__.py\n+++ b/bittensor/__init__.py\n@@ -16,15 +16,28 @@\n # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n # DEALINGS IN THE SOFTWARE.\n+import os\n+import warnings\n \n from rich.console import Console\n from rich.traceback import install\n \n-# Install and apply nest asyncio to allow the async functions\n-# to run in a .ipynb\n-import nest_asyncio\n \n-nest_asyncio.apply()\n+if (NEST_ASYNCIO_ENV := os.getenv(\"NEST_ASYNCIO\")) in (\"1\", None):\n+    if NEST_ASYNCIO_ENV is None:\n+        warnings.warn(\n+            \"NEST_ASYNCIO implicitly set to '1'. In the future, the default value will be '0'.\"\n+            \"If you use `nest_asyncio` make sure to add it explicitly to your project dependencies,\"\n+            \"as it will be removed from `bittensor` package dependencies in the future.\"\n+            \"To silence this warning, explicitly set the environment variable, e.g. `export NEST_ASYNCIO=0`.\",\n+            DeprecationWarning,\n+        )\n+    # Install and apply nest asyncio to allow the async functions\n+    # to run in a .ipynb\n+    import nest_asyncio\n+\n+    nest_asyncio.apply()\n+\n \n # Bittensor code and protocol version.\n __version__ = \"7.0.0\"\n", "issue": "Remove nest_asyncio from bittensor to allow uvloop support\n### Is your feature request related to a problem? Please describe.\r\n\r\nUvloop, which provides supperior speed, does not allow loop nesting.\r\n\r\nIt is also the case that uvloop is pulled in by popular packages, which [forces some subnets develop hacks to combat this](https://github.com/synapsec-ai/llm-defender-subnet/blob/6c37925c4f34a298607c97dfceebcc01fb74d562/scripts/run_neuron.sh#L140-L146).\r\n\r\nAnd perhaps more importantly, https://github.com/erdewit/nest_asyncio seems to have been abandodend \r\n\r\n### Describe the solution you'd like\r\n\r\nRemove nest_asyncio, and let bittensor users decide which asyncio loop they want to run. Perhaps even suggest (not mandate) running uvloop, since it consistently shows better results in benchmarks than CPython asyncio stdlib loop.\r\n\r\nSeems like there was some attempt of this in the past https://github.com/opentensor/bittensor/pull/1501 for some reason (?) \r\n\r\n### Describe alternatives you've considered\r\n\r\n_No response_\r\n\r\n### Additional context\r\n\r\n_No response_\n", "before_files": [{"content": "# The MIT License (MIT)\n# Copyright \u00a9 2021 Yuma Rao\n# Copyright \u00a9 2022-2023 Opentensor Foundation\n# Copyright \u00a9 2023 Opentensor Technologies Inc\n\n# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n# documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,\n# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n# The above copyright notice and this permission notice shall be included in all copies or substantial portions of\n# the Software.\n\n# THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n# DEALINGS IN THE SOFTWARE.\n\nfrom rich.console import Console\nfrom rich.traceback import install\n\n# Install and apply nest asyncio to allow the async functions\n# to run in a .ipynb\nimport nest_asyncio\n\nnest_asyncio.apply()\n\n# Bittensor code and protocol version.\n__version__ = \"7.0.0\"\n\nversion_split = __version__.split(\".\")\n__version_as_int__: int = (\n    (100 * int(version_split[0]))\n    + (10 * int(version_split[1]))\n    + (1 * int(version_split[2]))\n)\n__new_signature_version__ = 360\n\n# Rich console.\n__console__ = Console()\n__use_console__ = True\n\n# Remove overdue locals in debug training.\ninstall(show_locals=False)\n\n\ndef turn_console_off():\n    global __use_console__\n    global __console__\n    from io import StringIO\n\n    __use_console__ = False\n    __console__ = Console(file=StringIO(), stderr=False)\n\n\ndef turn_console_on():\n    global __use_console__\n    global __console__\n    __use_console__ = True\n    __console__ = Console()\n\n\nturn_console_off()\n\n\n# Logging helpers.\ndef trace(on: bool = True):\n    logging.set_trace(on)\n\n\ndef debug(on: bool = True):\n    logging.set_debug(on)\n\n\n# Substrate chain block time (seconds).\n__blocktime__ = 12\n\n# Pip address for versioning\n__pipaddress__ = \"https://pypi.org/pypi/bittensor/json\"\n\n# Raw GitHub url for delegates registry file\n__delegates_details_url__: str = \"https://raw.githubusercontent.com/opentensor/bittensor-delegates/main/public/delegates.json\"\n\n# Substrate ss58_format\n__ss58_format__ = 42\n\n# Wallet ss58 address length\n__ss58_address_length__ = 48\n\n__networks__ = [\"local\", \"finney\", \"test\", \"archive\"]\n\n__finney_entrypoint__ = \"wss://entrypoint-finney.opentensor.ai:443\"\n\n__finney_test_entrypoint__ = \"wss://test.finney.opentensor.ai:443/\"\n\n__archive_entrypoint__ = \"wss://archive.chain.opentensor.ai:443/\"\n\n# Needs to use wss://\n__bellagene_entrypoint__ = \"wss://parachain.opentensor.ai:443\"\n\n__local_entrypoint__ = \"ws://127.0.0.1:9944\"\n\n__tao_symbol__: str = chr(0x03C4)\n\n__rao_symbol__: str = chr(0x03C1)\n\n# Block Explorers map network to explorer url\n# Must all be polkadotjs explorer urls\n__network_explorer_map__ = {\n    \"opentensor\": {\n        \"local\": \"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer\",\n        \"endpoint\": \"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer\",\n        \"finney\": \"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer\",\n    },\n    \"taostats\": {\n        \"local\": \"https://x.taostats.io\",\n        \"endpoint\": \"https://x.taostats.io\",\n        \"finney\": \"https://x.taostats.io\",\n    },\n}\n\n# --- Type Registry ---\n__type_registry__ = {\n    \"types\": {\n        \"Balance\": \"u64\",  # Need to override default u128\n    },\n    \"runtime_api\": {\n        \"NeuronInfoRuntimeApi\": {\n            \"methods\": {\n                \"get_neuron_lite\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                        {\n                            \"name\": \"uid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n                \"get_neurons_lite\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n            }\n        },\n        \"StakeInfoRuntimeApi\": {\n            \"methods\": {\n                \"get_stake_info_for_coldkey\": {\n                    \"params\": [\n                        {\n                            \"name\": \"coldkey_account_vec\",\n                            \"type\": \"Vec<u8>\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n                \"get_stake_info_for_coldkeys\": {\n                    \"params\": [\n                        {\n                            \"name\": \"coldkey_account_vecs\",\n                            \"type\": \"Vec<Vec<u8>>\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n            },\n        },\n        \"ValidatorIPRuntimeApi\": {\n            \"methods\": {\n                \"get_associated_validator_ip_info_for_subnet\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n            },\n        },\n        \"SubnetInfoRuntimeApi\": {\n            \"methods\": {\n                \"get_subnet_hyperparams\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                }\n            }\n        },\n        \"SubnetRegistrationRuntimeApi\": {\n            \"methods\": {\"get_network_registration_cost\": {\"params\": [], \"type\": \"u64\"}}\n        },\n    },\n}\n\nfrom .errors import (\n    BlacklistedException,\n    ChainConnectionError,\n    ChainError,\n    ChainQueryError,\n    ChainTransactionError,\n    IdentityError,\n    InternalServerError,\n    InvalidRequestNameError,\n    KeyFileError,\n    MetadataError,\n    NominationError,\n    NotDelegateError,\n    NotRegisteredError,\n    NotVerifiedException,\n    PostProcessException,\n    PriorityException,\n    RegistrationError,\n    RunException,\n    StakeError,\n    SynapseDendriteNoneException,\n    SynapseParsingError,\n    TransferError,\n    UnknownSynapseError,\n    UnstakeError,\n)\n\nfrom substrateinterface import Keypair  # noqa: F401\nfrom .config import InvalidConfigFile, DefaultConfig, config, T\nfrom .keyfile import (\n    serialized_keypair_to_keyfile_data,\n    deserialize_keypair_from_keyfile_data,\n    validate_password,\n    ask_password_to_encrypt,\n    keyfile_data_is_encrypted_nacl,\n    keyfile_data_is_encrypted_ansible,\n    keyfile_data_is_encrypted_legacy,\n    keyfile_data_is_encrypted,\n    keyfile_data_encryption_method,\n    legacy_encrypt_keyfile_data,\n    encrypt_keyfile_data,\n    get_coldkey_password_from_environment,\n    decrypt_keyfile_data,\n    keyfile,\n    Mockkeyfile,\n)\nfrom .wallet import display_mnemonic_msg, wallet\n\nfrom .utils import (\n    ss58_to_vec_u8,\n    unbiased_topk,\n    version_checking,\n    strtobool,\n    strtobool_with_default,\n    get_explorer_root_url_by_network_from_map,\n    get_explorer_root_url_by_network_from_map,\n    get_explorer_url_for_network,\n    ss58_address_to_bytes,\n    U16_NORMALIZED_FLOAT,\n    U64_NORMALIZED_FLOAT,\n    u8_key_to_ss58,\n    hash,\n    wallet_utils,\n)\n\nfrom .utils.balance import Balance as Balance\nfrom .chain_data import (\n    AxonInfo,\n    NeuronInfo,\n    NeuronInfoLite,\n    PrometheusInfo,\n    DelegateInfo,\n    DelegateInfoLite,\n    StakeInfo,\n    SubnetInfo,\n    SubnetHyperparameters,\n    IPInfo,\n    ProposalCallData,\n    ProposalVoteData,\n)\n\n# Allows avoiding name spacing conflicts and continue access to the `subtensor` module with `subtensor_module` name\nfrom . import subtensor as subtensor_module\n\n# Double import allows using class `Subtensor` by referencing `bittensor.Subtensor` and `bittensor.subtensor`.\n# This will be available for a while until we remove reference `bittensor.subtensor`\nfrom .subtensor import Subtensor\nfrom .subtensor import Subtensor as subtensor\n\nfrom .cli import cli as cli, COMMANDS as ALL_COMMANDS\nfrom .btlogging import logging\nfrom .metagraph import metagraph as metagraph\nfrom .threadpool import PriorityThreadPoolExecutor as PriorityThreadPoolExecutor\n\nfrom .synapse import TerminalInfo, Synapse\nfrom .stream import StreamingSynapse\nfrom .tensor import tensor, Tensor\nfrom .axon import axon as axon\nfrom .dendrite import dendrite as dendrite\n\nfrom .mock.keyfile_mock import MockKeyfile as MockKeyfile\nfrom .mock.subtensor_mock import MockSubtensor as MockSubtensor\nfrom .mock.wallet_mock import MockWallet as MockWallet\n\nfrom .subnets import SubnetsAPI as SubnetsAPI\n\nconfigs = [\n    axon.config(),\n    subtensor.config(),\n    PriorityThreadPoolExecutor.config(),\n    wallet.config(),\n    logging.get_config(),\n]\ndefaults = config.merge_all(configs)\n", "path": "bittensor/__init__.py"}], "after_files": [{"content": "# The MIT License (MIT)\n# Copyright \u00a9 2021 Yuma Rao\n# Copyright \u00a9 2022-2023 Opentensor Foundation\n# Copyright \u00a9 2023 Opentensor Technologies Inc\n\n# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n# documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,\n# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n# The above copyright notice and this permission notice shall be included in all copies or substantial portions of\n# the Software.\n\n# THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n# DEALINGS IN THE SOFTWARE.\nimport os\nimport warnings\n\nfrom rich.console import Console\nfrom rich.traceback import install\n\n\nif (NEST_ASYNCIO_ENV := os.getenv(\"NEST_ASYNCIO\")) in (\"1\", None):\n    if NEST_ASYNCIO_ENV is None:\n        warnings.warn(\n            \"NEST_ASYNCIO implicitly set to '1'. In the future, the default value will be '0'.\"\n            \"If you use `nest_asyncio` make sure to add it explicitly to your project dependencies,\"\n            \"as it will be removed from `bittensor` package dependencies in the future.\"\n            \"To silence this warning, explicitly set the environment variable, e.g. `export NEST_ASYNCIO=0`.\",\n            DeprecationWarning,\n        )\n    # Install and apply nest asyncio to allow the async functions\n    # to run in a .ipynb\n    import nest_asyncio\n\n    nest_asyncio.apply()\n\n\n# Bittensor code and protocol version.\n__version__ = \"7.0.0\"\n\nversion_split = __version__.split(\".\")\n__version_as_int__: int = (\n    (100 * int(version_split[0]))\n    + (10 * int(version_split[1]))\n    + (1 * int(version_split[2]))\n)\n__new_signature_version__ = 360\n\n# Rich console.\n__console__ = Console()\n__use_console__ = True\n\n# Remove overdue locals in debug training.\ninstall(show_locals=False)\n\n\ndef turn_console_off():\n    global __use_console__\n    global __console__\n    from io import StringIO\n\n    __use_console__ = False\n    __console__ = Console(file=StringIO(), stderr=False)\n\n\ndef turn_console_on():\n    global __use_console__\n    global __console__\n    __use_console__ = True\n    __console__ = Console()\n\n\nturn_console_off()\n\n\n# Logging helpers.\ndef trace(on: bool = True):\n    logging.set_trace(on)\n\n\ndef debug(on: bool = True):\n    logging.set_debug(on)\n\n\n# Substrate chain block time (seconds).\n__blocktime__ = 12\n\n# Pip address for versioning\n__pipaddress__ = \"https://pypi.org/pypi/bittensor/json\"\n\n# Raw GitHub url for delegates registry file\n__delegates_details_url__: str = \"https://raw.githubusercontent.com/opentensor/bittensor-delegates/main/public/delegates.json\"\n\n# Substrate ss58_format\n__ss58_format__ = 42\n\n# Wallet ss58 address length\n__ss58_address_length__ = 48\n\n__networks__ = [\"local\", \"finney\", \"test\", \"archive\"]\n\n__finney_entrypoint__ = \"wss://entrypoint-finney.opentensor.ai:443\"\n\n__finney_test_entrypoint__ = \"wss://test.finney.opentensor.ai:443/\"\n\n__archive_entrypoint__ = \"wss://archive.chain.opentensor.ai:443/\"\n\n# Needs to use wss://\n__bellagene_entrypoint__ = \"wss://parachain.opentensor.ai:443\"\n\n__local_entrypoint__ = \"ws://127.0.0.1:9944\"\n\n__tao_symbol__: str = chr(0x03C4)\n\n__rao_symbol__: str = chr(0x03C1)\n\n# Block Explorers map network to explorer url\n# Must all be polkadotjs explorer urls\n__network_explorer_map__ = {\n    \"opentensor\": {\n        \"local\": \"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer\",\n        \"endpoint\": \"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer\",\n        \"finney\": \"https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fentrypoint-finney.opentensor.ai%3A443#/explorer\",\n    },\n    \"taostats\": {\n        \"local\": \"https://x.taostats.io\",\n        \"endpoint\": \"https://x.taostats.io\",\n        \"finney\": \"https://x.taostats.io\",\n    },\n}\n\n# --- Type Registry ---\n__type_registry__ = {\n    \"types\": {\n        \"Balance\": \"u64\",  # Need to override default u128\n    },\n    \"runtime_api\": {\n        \"NeuronInfoRuntimeApi\": {\n            \"methods\": {\n                \"get_neuron_lite\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                        {\n                            \"name\": \"uid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n                \"get_neurons_lite\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n            }\n        },\n        \"StakeInfoRuntimeApi\": {\n            \"methods\": {\n                \"get_stake_info_for_coldkey\": {\n                    \"params\": [\n                        {\n                            \"name\": \"coldkey_account_vec\",\n                            \"type\": \"Vec<u8>\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n                \"get_stake_info_for_coldkeys\": {\n                    \"params\": [\n                        {\n                            \"name\": \"coldkey_account_vecs\",\n                            \"type\": \"Vec<Vec<u8>>\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n            },\n        },\n        \"ValidatorIPRuntimeApi\": {\n            \"methods\": {\n                \"get_associated_validator_ip_info_for_subnet\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                },\n            },\n        },\n        \"SubnetInfoRuntimeApi\": {\n            \"methods\": {\n                \"get_subnet_hyperparams\": {\n                    \"params\": [\n                        {\n                            \"name\": \"netuid\",\n                            \"type\": \"u16\",\n                        },\n                    ],\n                    \"type\": \"Vec<u8>\",\n                }\n            }\n        },\n        \"SubnetRegistrationRuntimeApi\": {\n            \"methods\": {\"get_network_registration_cost\": {\"params\": [], \"type\": \"u64\"}}\n        },\n    },\n}\n\nfrom .errors import (\n    BlacklistedException,\n    ChainConnectionError,\n    ChainError,\n    ChainQueryError,\n    ChainTransactionError,\n    IdentityError,\n    InternalServerError,\n    InvalidRequestNameError,\n    KeyFileError,\n    MetadataError,\n    NominationError,\n    NotDelegateError,\n    NotRegisteredError,\n    NotVerifiedException,\n    PostProcessException,\n    PriorityException,\n    RegistrationError,\n    RunException,\n    StakeError,\n    SynapseDendriteNoneException,\n    SynapseParsingError,\n    TransferError,\n    UnknownSynapseError,\n    UnstakeError,\n)\n\nfrom substrateinterface import Keypair  # noqa: F401\nfrom .config import InvalidConfigFile, DefaultConfig, config, T\nfrom .keyfile import (\n    serialized_keypair_to_keyfile_data,\n    deserialize_keypair_from_keyfile_data,\n    validate_password,\n    ask_password_to_encrypt,\n    keyfile_data_is_encrypted_nacl,\n    keyfile_data_is_encrypted_ansible,\n    keyfile_data_is_encrypted_legacy,\n    keyfile_data_is_encrypted,\n    keyfile_data_encryption_method,\n    legacy_encrypt_keyfile_data,\n    encrypt_keyfile_data,\n    get_coldkey_password_from_environment,\n    decrypt_keyfile_data,\n    keyfile,\n    Mockkeyfile,\n)\nfrom .wallet import display_mnemonic_msg, wallet\n\nfrom .utils import (\n    ss58_to_vec_u8,\n    unbiased_topk,\n    version_checking,\n    strtobool,\n    strtobool_with_default,\n    get_explorer_root_url_by_network_from_map,\n    get_explorer_root_url_by_network_from_map,\n    get_explorer_url_for_network,\n    ss58_address_to_bytes,\n    U16_NORMALIZED_FLOAT,\n    U64_NORMALIZED_FLOAT,\n    u8_key_to_ss58,\n    hash,\n    wallet_utils,\n)\n\nfrom .utils.balance import Balance as Balance\nfrom .chain_data import (\n    AxonInfo,\n    NeuronInfo,\n    NeuronInfoLite,\n    PrometheusInfo,\n    DelegateInfo,\n    DelegateInfoLite,\n    StakeInfo,\n    SubnetInfo,\n    SubnetHyperparameters,\n    IPInfo,\n    ProposalCallData,\n    ProposalVoteData,\n)\n\n# Allows avoiding name spacing conflicts and continue access to the `subtensor` module with `subtensor_module` name\nfrom . import subtensor as subtensor_module\n\n# Double import allows using class `Subtensor` by referencing `bittensor.Subtensor` and `bittensor.subtensor`.\n# This will be available for a while until we remove reference `bittensor.subtensor`\nfrom .subtensor import Subtensor\nfrom .subtensor import Subtensor as subtensor\n\nfrom .cli import cli as cli, COMMANDS as ALL_COMMANDS\nfrom .btlogging import logging\nfrom .metagraph import metagraph as metagraph\nfrom .threadpool import PriorityThreadPoolExecutor as PriorityThreadPoolExecutor\n\nfrom .synapse import TerminalInfo, Synapse\nfrom .stream import StreamingSynapse\nfrom .tensor import tensor, Tensor\nfrom .axon import axon as axon\nfrom .dendrite import dendrite as dendrite\n\nfrom .mock.keyfile_mock import MockKeyfile as MockKeyfile\nfrom .mock.subtensor_mock import MockSubtensor as MockSubtensor\nfrom .mock.wallet_mock import MockWallet as MockWallet\n\nfrom .subnets import SubnetsAPI as SubnetsAPI\n\nconfigs = [\n    axon.config(),\n    subtensor.config(),\n    PriorityThreadPoolExecutor.config(),\n    wallet.config(),\n    logging.get_config(),\n]\ndefaults = config.merge_all(configs)\n", "path": "bittensor/__init__.py"}]}