A jpype based wrapper for using TRADE with Python
Project description
Disclaimer
This is a MAJOR work in progress, and everything is subject to change. Questions and bug reports are encouraged!
What is PyTRADE?
The purpose of this project is to enable developers to use TRADE, a java-based middleware, in Python. DIARC is a cognitive architecture that utilizes TRADE as its middleware.
With this wrapper, developers are able to utilize, integrate, and implement java-based DIARC components with Python. Example use cases include as Python-based simulation environments or Python reinforcement learning libraries.
The process for using PyTRADE is simple: Install it with pip, initialize your TRADE wrapper, and you're good to go. You can also create python implementations of Java interfaces, allowing you to implement new TRADE services in Python.
Installation
To install this package, make sure you have pip installed on your machine and then run:
pip install pytrade-wrapper
Setup
- Set up DIARC. See the DIARC readme for install instructions.
- In your DIARC directory, Run the command:
./gradlew publishToMavenLocal. - From the DIARC readme, follow instructions for setting up Metric-FF. This will include creating/modifying
gradle.properties. - From the DIARC repo's
trade.properties.defaultfile, follow the instructions for making your own trade.properties file for java. - In your personal
trade.properties, changeSTARTDISCOVERYtotrue.
Using the Wrapper
Initializing
- If you just want to use TRADE, you can just import
pyTRADE.core.wrapper. The JVM will automatically start. - If you want to use the DIARC wrapper, instantiate the
TRADEWrapperobject. - You can now use its various methods, most importantly
call_trade(...).
Note: After importing trade_wrapper, you can also import anything from the DIARC and TRADE jars, following normal JPype standards. Import order matters here!
Implementing an Existing Java Interface
The primary reason you would want to implement an existing Java interface is to provide Python implementations for TRADE services. For example, if you wish to control a robotic arm through Python, and advertise that controller to TRADE, you can implement the ArmInterface from edu.tufts.hrilab.interfaces.ArmInterface.
It may be useful to read the JPype documentation on this process first.
- Create a new python class, such as
PythonArmComponent - Decorate it with
@JImplements([YourInterface]), e.g.@JImplements(ArmInterface). Make sure you have [YourInterface] imported! - For every method in the interface, implement it by decorating a standard python function definition with
@JOverride - Instantiate an instance of the class you just created, and register it with TRADE using:
TRADE.registerAllServices([your_object], "")
Your methods from your new class should now be available via TRADE, assuming they implement a function annotated with @TRADEService in Java.
Please see the examples for additional guidance.
Making a new interface
If you need to advertise new TRADE services that aren't covered by any existing interfaces in DIARC, follow these steps.
- Create your new interface in the appropriate location in Java.
- Make sure you annotate the relevant methods with
@TRADEService - Run
./gradlew publishToMavenLocal
You can now follow the steps from the previous section to implement your new interface.
Example
import time
from pyTRADE.core.wrapper import TRADEWrapper
from ai.thinkingrobots.trade import TRADE
from jpype import JImplements, JOverride, JClass
from edu.tufts.hrilab.interfaces import DockingInterface
@JImplements(DockingInterface)
class dummyWrapper:
@JOverride
def dock(self, dockId):
pass
@JOverride
def undock(self):
print("Undocking")
pass
if __name__ == '__main__':
wrapper = TRADEWrapper()
dummyObject = dummyWrapper()
TRADE.registerAllServices(dummyObject, "")
time.sleep(1)
print(TRADE.getAvailableServices())
wrapper.call_trade("undock", )
Todo:
- Use uberjar instead of regular jar to remove hosting dependency jars on pypi
- Implement DIARC detectors
- Let users add to the classpath
For questions, email (marlow.fawn@gmail.com)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytrade_wrapper-1.1.0.tar.gz.
File metadata
- Download URL: pytrade_wrapper-1.1.0.tar.gz
- Upload date:
- Size: 797.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a61bad0d3e6a4bff95b7ffa0a4ef7cdaae62b99dd0a02f853773a7f6595116f
|
|
| MD5 |
b92308be263b311d721f2f6f65686d55
|
|
| BLAKE2b-256 |
f26dcd8b266f7a5fdbbf6a38fc341de2b7f71bca30d42bd912da5eaff5ef1cb8
|
File details
Details for the file pytrade_wrapper-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pytrade_wrapper-1.1.0-py3-none-any.whl
- Upload date:
- Size: 799.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d57c167511ba669a595c717fa33fe30cee4c0f522bfd9c937db615dee5309061
|
|
| MD5 |
d362b20efffa4b67dac4a83747a1cf6e
|
|
| BLAKE2b-256 |
8bf24cf7037cae7546d9bf36b4255e5d3d7c97c431b3b394f682d9393cd5890c
|