nunet-py


Namenunet-py JSON
Version 0.1.2 PyPI version JSON
download
home_page
Summary
upload_time2023-11-23 04:54:36
maintainer
docs_urlNone
authorElder Millenial
requires_python>=3.10,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

  <img src="https://raw.github.com/theeldermillenial/nunet-py/master/imgs/nunet-py.png" alt="nunet-py" width="200" height="auto" />
  <p>
    A Python client for NuNet!
  </p>

<!-- Badges -->
<p>
  <a href="https://pypi.org/project/nunet-py/">
    <img src="https://img.shields.io/pypi/v/nunet-py" alt="version" />
  </a>
  <a href="https://pypi.org/project/nunet-py/">
    <img src="https://img.shields.io/pepy/dt/nunet-py" alt="downloads" />
  </a>
  <a href="">
    <img src="https://img.shields.io/badge/code_format-black-black" alt="open issues" />
  </a>
  <a href="https://github.com/theeldermillenial/nunet-py/blob/master/LICENSE">
    <img src="https://img.shields.io/github/license/theeldermillenial/nunet-py.svg" alt="license" />
  </a>
</p>

<h4>
    <a href="https://github.com/theeldermillenial/nunet-py">Documentation (Coming Soon!)</a>
  <span> · </span>
    <a href="https://github.com/theeldermillenial/nunet-py/issues/">Report Bug</a>
  <span> · </span>
    <a href="https://github.com/theeldermillenial/nunet-py/issues/">Request Feature</a>
  </h4>
</div>

`nunet-py` is a Python package for running jobs on NuNet!

<!-- Table of Contents -->
<details>
  <summary>Table of Contents</summary>
  <ol>
    <li>
      <a href="#introduction">Introduction</a>
    </li>
    <li>
      <a href="#how-do-i-use-it">How To</a>
      <ul>
        <li><a href="#getting-started">Pre-Requisites</a></li>
        <li><a href="#submit-a-job">Submit a Job</a></li>
        <li><a href="#full-example">Full Example</a></li>
      </ul>
    </li>
    <li><a href="#how-can-i-help">Contribute</a></li>
  </ol>
</details>

## Introduction

`nunet-py` is a Python client for submitting jobs to NuNet. It is intended to be a
direct interface to the DMS.

This is considered an alpha project. The NuNet network is in active development, so it
is possible this package will break as changes are made to the DMS. Currently,
everything happens on the Cardano preprod testnet.

## How do I use it?

Right now, the setup is fairly involved unless you're already a NuNet alpha tester.
I highly recommend joining the NuNet Discord for assistance. I (Elder Millenial) tend
to hang out there as well as a lot of other highly knowledgeable people, and the team
is very responsive.

### Getting Started

The basic steps to setup your computer to use `nunet-py` are as follows:
1. Join the NuNet Alpha Testing Program. Follow the directions to become both a resource
provider and service provider.
2. Create a [Blockfrost](www.blockfrost.io) account, and create a project id for the
predprod testnet.
3. (Optional) Save `sample.env` as `.env`, and replace the values. For the seed phrase,
use the seed phrase used when setting up your system for the Alpha Testing Program. Also
put in your Blockfrost project id.

### Submit a Job

This example will submit one of the example ML jobs provided for the NuNet Alpha Testers
program. This will break up the entire example into sections, and the complete example
can be found at the end and in [the examples](example/simple_cpu.py).

#### Install `nunet-py`

During development of this tool a bug was found in
[pycardano](https://github.com/python-cardano/pycardano), a dependency of this project.
The bug was fixed and merged into the project, but the fix has not been released so
the project cannot be pushed to PyPI. The best way to install and get started is to
install directly from this repo:

```bash
pip install git+https://github.com/theeldermillenial/nunet-py
```

#### Initializing the NuNet Adapter

Assuming you made the `.env` with your preprod wallet seed phrase as described in under
[Getting Started](#getting-started), we start by loading the the environment file,
loading the seed phrase from the environment, and initializing the adapter with the seed
phrase. The reason why we take this approach is that you should never put your seed
phrase into code, and even though this is a preprod wallet, we want to use best
practices.

```python
import os

from dotenv import load_dotenv

from nunet import NuNetAdapter

# Load the environment file
load_dotenv()

# Get your seed phrase from the environment
seed = os.environ["SEED"]

# Create a NuNet adapter
adapter = NuNetAdapter(seed)
```

Now we can get a list of peers and print off the information we get about them.

```python
import pprint

peer_list = adapter.peer_list()

pprint.pprint(peer_list.model_dump(), indent=2)
```

#### Configuring the Job

There are a number of details needed to configure your job to ensure your job request
is matched with an appropriate resource provider. However, this can also be burdensome
so some convenience objects have been created to make it easier to get started. In this
example, we just use a very low resource request (`CONSTRAINTS_LOW`).

```python
from nunet import CONSTRAINTS_LOW

pprint.pprint(CONSTRAINTS_LOW.model_dump(), indent=2)
```

Next we need to configure some additional information about our job, including whether
we need a GPU or if a CPU will suffice. In addition to that, we need to indicate what
piece of code we want to run and configure the package dependencies. For this, we just
use the simple ml-test from the NuNet Test Program examples, which has no package
requirements.

```python
from nunet import JobParams, ImageId, MachineType

params = JobParams(
    machine_type=MachineType.GPU,
    image_id=ImageId.ML_ON_CPU_REGISTRY,
    model_url="https://gitlab.com/nunet/ml-on-gpu/ml-on-cpu-service/-/raw/develop/examples/cpu-ml-test-scikit-learn.py",
    packages=[],
)
```

Next we need to compile this data together and indicate the maximum NTX we are willing
to pay and our address.

```python
from nunet import JobRequest, ServiceType

job_config = JobRequest(
    address_user=adapter.address.encode(),
    max_ntx=10,
    service_type=ServiceType.CPU,
    params=params,
    constraints=CONSTRAINTS_LOW,
)
```

Finally, we need to request a service provider, pay the contract to execute the job,
then submit the job to the network and listen for the output.

```python
job_request = adapter.request_service(job_config=job_config)

txid = adapter.pay(job_request)

for log in adapter.job(txid):
    print(log)
```

When you execute the last piece of code, it will likely hang a bit as the order is
submitted, then wait for the job to begin executed. If you don't see activity after a
few minutes, use ctrl+c to exit the code. You will see logs until the code completes,
and the code will exit when it completes.

Once this happens, you've successfully run your first job on NuNet!

### Full example

```python
import os
import pprint

from dotenv import load_dotenv
from nunet import (
    CONSTRAINTS_LOW,
    ImageId,
    JobParams,
    JobRequest,
    MachineType,
    NuNetAdapter,
    ServiceType,
)

# Load the environment file
load_dotenv()

# Get your seed phrase from the environment
seed = os.environ["SEED"]

# Create a NuNet adapter
adapter = NuNetAdapter(seed)

# Get a list of peers
print("Peers:")
peer_list = adapter.peer_list()
pprint.pprint(peer_list.model_dump(), indent=2)
print()

print("CONSTRAINTS_LOW:")
pprint.pprint(CONSTRAINTS_LOW.model_dump(), indent=2)
print()

params = JobParams(
    machine_type=MachineType.GPU,
    image_id=ImageId.ML_ON_CPU_REGISTRY,
    model_url="https://gitlab.com/nunet/ml-on-gpu/ml-on-cpu-service/-/raw/develop/examples/cpu-ml-test-scikit-learn.py",
    packages=[],
)

job_request: JobRequest = JobRequest(
    address_user=adapter.address.encode(),
    max_ntx=10,
    service_type=ServiceType.CPU,
    params=params,
    constraints=CONSTRAINTS_LOW,
)

job_request = adapter.request_service(job_request=job_request)

txid = adapter.pay(job_request)

for msg_type, msg in adapter.job(txid):
    print(msg, flush=True)
```

## How can I help?

I can always use volunteers to take on specific chunks of the project. I work on this
in my free time, along with some other Cardano projects. You can help by reaching out
on Twitter or Discord. Alternatively, sending tips is also helpful to cover the costs
of production. Tips can be sent to:

```bash
addr1q9hw8fuex09vr3rqwtn4fzh9qxjlzjzh8aww684ln0rv0cfu3f0de6qkmh7c7yysfz808978wwe6ll30wu8l3cgvgdjqa7egnl
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "nunet-py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Elder Millenial",
    "author_email": "eldermillenial@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/21/d2/47005e51d6794ed4f246f510ec7ffd8ee86cecf0fa7086425d02eee0d493/nunet_py-0.1.2.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n  <img src=\"https://raw.github.com/theeldermillenial/nunet-py/master/imgs/nunet-py.png\" alt=\"nunet-py\" width=\"200\" height=\"auto\" />\n  <p>\n    A Python client for NuNet!\n  </p>\n\n<!-- Badges -->\n<p>\n  <a href=\"https://pypi.org/project/nunet-py/\">\n    <img src=\"https://img.shields.io/pypi/v/nunet-py\" alt=\"version\" />\n  </a>\n  <a href=\"https://pypi.org/project/nunet-py/\">\n    <img src=\"https://img.shields.io/pepy/dt/nunet-py\" alt=\"downloads\" />\n  </a>\n  <a href=\"\">\n    <img src=\"https://img.shields.io/badge/code_format-black-black\" alt=\"open issues\" />\n  </a>\n  <a href=\"https://github.com/theeldermillenial/nunet-py/blob/master/LICENSE\">\n    <img src=\"https://img.shields.io/github/license/theeldermillenial/nunet-py.svg\" alt=\"license\" />\n  </a>\n</p>\n\n<h4>\n    <a href=\"https://github.com/theeldermillenial/nunet-py\">Documentation (Coming Soon!)</a>\n  <span> \u00b7 </span>\n    <a href=\"https://github.com/theeldermillenial/nunet-py/issues/\">Report Bug</a>\n  <span> \u00b7 </span>\n    <a href=\"https://github.com/theeldermillenial/nunet-py/issues/\">Request Feature</a>\n  </h4>\n</div>\n\n`nunet-py` is a Python package for running jobs on NuNet!\n\n<!-- Table of Contents -->\n<details>\n  <summary>Table of Contents</summary>\n  <ol>\n    <li>\n      <a href=\"#introduction\">Introduction</a>\n    </li>\n    <li>\n      <a href=\"#how-do-i-use-it\">How To</a>\n      <ul>\n        <li><a href=\"#getting-started\">Pre-Requisites</a></li>\n        <li><a href=\"#submit-a-job\">Submit a Job</a></li>\n        <li><a href=\"#full-example\">Full Example</a></li>\n      </ul>\n    </li>\n    <li><a href=\"#how-can-i-help\">Contribute</a></li>\n  </ol>\n</details>\n\n## Introduction\n\n`nunet-py` is a Python client for submitting jobs to NuNet. It is intended to be a\ndirect interface to the DMS.\n\nThis is considered an alpha project. The NuNet network is in active development, so it\nis possible this package will break as changes are made to the DMS. Currently,\neverything happens on the Cardano preprod testnet.\n\n## How do I use it?\n\nRight now, the setup is fairly involved unless you're already a NuNet alpha tester.\nI highly recommend joining the NuNet Discord for assistance. I (Elder Millenial) tend\nto hang out there as well as a lot of other highly knowledgeable people, and the team\nis very responsive.\n\n### Getting Started\n\nThe basic steps to setup your computer to use `nunet-py` are as follows:\n1. Join the NuNet Alpha Testing Program. Follow the directions to become both a resource\nprovider and service provider.\n2. Create a [Blockfrost](www.blockfrost.io) account, and create a project id for the\npredprod testnet.\n3. (Optional) Save `sample.env` as `.env`, and replace the values. For the seed phrase,\nuse the seed phrase used when setting up your system for the Alpha Testing Program. Also\nput in your Blockfrost project id.\n\n### Submit a Job\n\nThis example will submit one of the example ML jobs provided for the NuNet Alpha Testers\nprogram. This will break up the entire example into sections, and the complete example\ncan be found at the end and in [the examples](example/simple_cpu.py).\n\n#### Install `nunet-py`\n\nDuring development of this tool a bug was found in\n[pycardano](https://github.com/python-cardano/pycardano), a dependency of this project.\nThe bug was fixed and merged into the project, but the fix has not been released so\nthe project cannot be pushed to PyPI. The best way to install and get started is to\ninstall directly from this repo:\n\n```bash\npip install git+https://github.com/theeldermillenial/nunet-py\n```\n\n#### Initializing the NuNet Adapter\n\nAssuming you made the `.env` with your preprod wallet seed phrase as described in under\n[Getting Started](#getting-started), we start by loading the the environment file,\nloading the seed phrase from the environment, and initializing the adapter with the seed\nphrase. The reason why we take this approach is that you should never put your seed\nphrase into code, and even though this is a preprod wallet, we want to use best\npractices.\n\n```python\nimport os\n\nfrom dotenv import load_dotenv\n\nfrom nunet import NuNetAdapter\n\n# Load the environment file\nload_dotenv()\n\n# Get your seed phrase from the environment\nseed = os.environ[\"SEED\"]\n\n# Create a NuNet adapter\nadapter = NuNetAdapter(seed)\n```\n\nNow we can get a list of peers and print off the information we get about them.\n\n```python\nimport pprint\n\npeer_list = adapter.peer_list()\n\npprint.pprint(peer_list.model_dump(), indent=2)\n```\n\n#### Configuring the Job\n\nThere are a number of details needed to configure your job to ensure your job request\nis matched with an appropriate resource provider. However, this can also be burdensome\nso some convenience objects have been created to make it easier to get started. In this\nexample, we just use a very low resource request (`CONSTRAINTS_LOW`).\n\n```python\nfrom nunet import CONSTRAINTS_LOW\n\npprint.pprint(CONSTRAINTS_LOW.model_dump(), indent=2)\n```\n\nNext we need to configure some additional information about our job, including whether\nwe need a GPU or if a CPU will suffice. In addition to that, we need to indicate what\npiece of code we want to run and configure the package dependencies. For this, we just\nuse the simple ml-test from the NuNet Test Program examples, which has no package\nrequirements.\n\n```python\nfrom nunet import JobParams, ImageId, MachineType\n\nparams = JobParams(\n    machine_type=MachineType.GPU,\n    image_id=ImageId.ML_ON_CPU_REGISTRY,\n    model_url=\"https://gitlab.com/nunet/ml-on-gpu/ml-on-cpu-service/-/raw/develop/examples/cpu-ml-test-scikit-learn.py\",\n    packages=[],\n)\n```\n\nNext we need to compile this data together and indicate the maximum NTX we are willing\nto pay and our address.\n\n```python\nfrom nunet import JobRequest, ServiceType\n\njob_config = JobRequest(\n    address_user=adapter.address.encode(),\n    max_ntx=10,\n    service_type=ServiceType.CPU,\n    params=params,\n    constraints=CONSTRAINTS_LOW,\n)\n```\n\nFinally, we need to request a service provider, pay the contract to execute the job,\nthen submit the job to the network and listen for the output.\n\n```python\njob_request = adapter.request_service(job_config=job_config)\n\ntxid = adapter.pay(job_request)\n\nfor log in adapter.job(txid):\n    print(log)\n```\n\nWhen you execute the last piece of code, it will likely hang a bit as the order is\nsubmitted, then wait for the job to begin executed. If you don't see activity after a\nfew minutes, use ctrl+c to exit the code. You will see logs until the code completes,\nand the code will exit when it completes.\n\nOnce this happens, you've successfully run your first job on NuNet!\n\n### Full example\n\n```python\nimport os\nimport pprint\n\nfrom dotenv import load_dotenv\nfrom nunet import (\n    CONSTRAINTS_LOW,\n    ImageId,\n    JobParams,\n    JobRequest,\n    MachineType,\n    NuNetAdapter,\n    ServiceType,\n)\n\n# Load the environment file\nload_dotenv()\n\n# Get your seed phrase from the environment\nseed = os.environ[\"SEED\"]\n\n# Create a NuNet adapter\nadapter = NuNetAdapter(seed)\n\n# Get a list of peers\nprint(\"Peers:\")\npeer_list = adapter.peer_list()\npprint.pprint(peer_list.model_dump(), indent=2)\nprint()\n\nprint(\"CONSTRAINTS_LOW:\")\npprint.pprint(CONSTRAINTS_LOW.model_dump(), indent=2)\nprint()\n\nparams = JobParams(\n    machine_type=MachineType.GPU,\n    image_id=ImageId.ML_ON_CPU_REGISTRY,\n    model_url=\"https://gitlab.com/nunet/ml-on-gpu/ml-on-cpu-service/-/raw/develop/examples/cpu-ml-test-scikit-learn.py\",\n    packages=[],\n)\n\njob_request: JobRequest = JobRequest(\n    address_user=adapter.address.encode(),\n    max_ntx=10,\n    service_type=ServiceType.CPU,\n    params=params,\n    constraints=CONSTRAINTS_LOW,\n)\n\njob_request = adapter.request_service(job_request=job_request)\n\ntxid = adapter.pay(job_request)\n\nfor msg_type, msg in adapter.job(txid):\n    print(msg, flush=True)\n```\n\n## How can I help?\n\nI can always use volunteers to take on specific chunks of the project. I work on this\nin my free time, along with some other Cardano projects. You can help by reaching out\non Twitter or Discord. Alternatively, sending tips is also helpful to cover the costs\nof production. Tips can be sent to:\n\n```bash\naddr1q9hw8fuex09vr3rqwtn4fzh9qxjlzjzh8aww684ln0rv0cfu3f0de6qkmh7c7yysfz808978wwe6ll30wu8l3cgvgdjqa7egnl\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5fda786f2f5656b027edadf572853141b715ef344f85a1a81f214e6297bdb613",
                "md5": "9ce95f6e22b91ae9e911788e4ed8f14e",
                "sha256": "1fd879cf458b663b65fcf6aee6d58ed94063e0c4a3202b8ce898e7077ccdc12a"
            },
            "downloads": -1,
            "filename": "nunet_py-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ce95f6e22b91ae9e911788e4ed8f14e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 10120,
            "upload_time": "2023-11-23T04:54:35",
            "upload_time_iso_8601": "2023-11-23T04:54:35.255044Z",
            "url": "https://files.pythonhosted.org/packages/5f/da/786f2f5656b027edadf572853141b715ef344f85a1a81f214e6297bdb613/nunet_py-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "21d247005e51d6794ed4f246f510ec7ffd8ee86cecf0fa7086425d02eee0d493",
                "md5": "5e1de69594a1a536d675d14207cdb51c",
                "sha256": "387b5e45a6d56309958ea82d2624a6a1850a9a43291201567323dc885db399d0"
            },
            "downloads": -1,
            "filename": "nunet_py-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "5e1de69594a1a536d675d14207cdb51c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 9120,
            "upload_time": "2023-11-23T04:54:36",
            "upload_time_iso_8601": "2023-11-23T04:54:36.506102Z",
            "url": "https://files.pythonhosted.org/packages/21/d2/47005e51d6794ed4f246f510ec7ffd8ee86cecf0fa7086425d02eee0d493/nunet_py-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-23 04:54:36",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nunet-py"
}
        
Elapsed time: 0.15450s