Skip to main content

package providing core agent classes

Project description

Core-Py

Example

Prerequisites

Install smcore

pip install smcore

Get the address of a blackboard to talk to

If you don't have an address already (something like bb.myhost.com:8080 or bb.host.com), you can install the core tool and run your own locally.

go install gitlab.com/hoffman-lab/core@latest
core start server

The default address when running locally is localhost:8080

This is great for debugging and getting started. The core tool also has other good stuff.

Use an agent to post data

from smcore import agent
from smcore import hardcore

bb_addr = "localhost:8080"

async def main():
  bb = hardcore.HTTPTransit(bb_addr)
  a = agent.Agent(bb)
  

  for i in range(n_messages):
    metadata=b"hello"
    data=b"world"
    tags = ["upload-test", str(i)]
    await a.post(metadata, data, tags)
  
if __name__=="__main__":
  asyncio.run(main())

Use an agent to listen for data

from smcore import agent
from smcore import hardcore

bb_addr = "localhost:8080"

async def main():
  bb = hardcore.HTTPTransit(bb_addr)
  a = agent.Agent(bb)

  # Listen for messages matching the listed tags
  in_queue = a.listen_for(["important","segmentation"])

  # listening is an active process and must be started.
  # although listen_for can be called after start it is 
  # best practice to make all calls in advance.
  # 
  task = a.start()
  while True:
    post = await in_queue.get()
    await a.reply([post], None, None, ["received!"])
  
  # The started coroutine for listening can be cancelled normally
  task.cancel()

if __name__=="__main__":
  asyncio.run(main())

(De)serialization

Serialization is the process of converting abstract structures into binary-encodable formats for saving and sharing. Common language allows agents to communicate.

from smcore import serialize, deserialize

data = serialize.file("path/to/file.ext")
deserialize.file(data, "path/to/new/file.ext")

data = serialize.numpy(np.random.random((512,512,1)))
array = deserialize.numpy(data)

The serialize/deserialize modules give you some basics to get started.

These allow you to easily set data and metadata in your posts:

bb = hardcore.HTTPTransit(bb_addr)
post = bb.message_post()

fp_to_upload = "data/for/sharing/file.ext"
post.set_data(serialize.file(fp_to_upload))
post.set_metadata(serialize.dictionary({"path": fp_to_upload}))

You can decode it in other agents using the paired deserialize function:

post = await incoming.get()

finfo = deserialize.dictionary(post.metadata())
deserialize.file(post.data(), finfo["path"])

Motivation

The main core repo is getting a little unwieldy. CI/CD and organization could benefit from giving the python API for Core a little breathing room.

Short term goals

  1. Get the Python API updated to utilize the hardcore protocol
  2. Debug the message stoppage issue @mattbrown7 has identified
  3. Discuss, enumerate, and begin prototyping key tests to validate that the Core API fulfills its contract

Long term goals

  • Resilient CI/CD that runs tests in real world conditions
  • Shared maintenance of the Python API with other developers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smcore-1.1.2.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smcore-1.1.2-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file smcore-1.1.2.tar.gz.

File metadata

  • Download URL: smcore-1.1.2.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for smcore-1.1.2.tar.gz
Algorithm Hash digest
SHA256 10be90b866f0d5d31530e77a320af51a7f7f1821597db640f626172b7670fd93
MD5 378049c0cc8e36217601baef3377e509
BLAKE2b-256 acb61a8ee8a9d8fd0ea146f1a332617f461b43c7caf131c52479c996d7aeb778

See more details on using hashes here.

File details

Details for the file smcore-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: smcore-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for smcore-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b8d31cdd00325ec741f0c48f2f1a9bceb52716d652a32ee8e8b8f61e42849521
MD5 8bedb22cf733395d00ad835b5d8f4ea1
BLAKE2b-256 984606d753a9f192cec88144eb5237d4b2a160b1192f70cd61d4020c403e4451

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page