API Reference
Here you can find all learnware interfaces.
Market
- class learnware.market.LearnwareMarket
Market for Learnware
# Provide some python examples learnmarket = LearnwareMarket()
- add_learnware(learnware_name: str, model_path: str, stat_spec_path: str, properties: dict, desc: str) Tuple[str, bool]
Add a learnware into the market.
Note
Given a prediction of a certain time, all signals before this time will be prepared well.
- Parameters:
learnware_name (str) – Name of new learnware.
model_path (str) – Filepath for learnware model, a zipped file.
stat_spec_path (str) – Filepath for statistical specification, a ‘.npy’ file. How to pass parameters requires further discussion.
properties (dict) – property for new learnware, in dictionary format.
desc (str) – Brief desciption for new learnware.
- Returns:
str indicating model_id, bool indicating whether the learnware is added successfully.
- Return type:
Tuple[str, bool]
- Raises:
FileNotFoundError – file for model or statistical specification not found
- delete_learnware(id: str) bool
deleted a learnware from market
- Parameters:
id (str) – id of learnware to be deleted
- Returns:
True if the target learnware is deleted successfully.
- Return type:
bool
- Raises:
Exception – Raise an excpetion when give id is NOT found in learnware list
- get_learnware_by_ids(id: str | List[str]) Learnware | List[Learnware]
Get Learnware from market by id
- Parameters:
id (Union[str, List[str]]) – Given one id or a list of ids as target.
- Returns:
Return a Learnware object or a list of Learnware objects based on the type of input param.
The returned items are search results.
’None’ indicating the target id not found.
- Return type:
- get_property_list() dict
Return all properties available
- Returns:
All properties in dictionary format
- Return type:
dict
- reload_market(market_path: str, property_list_path: str, load_mode: str = 'database') bool
Reload the market when server restared.
- Parameters:
market_path (str) – Directory for market data. ‘_IP_:_port_’ for loading from database.
property_list_path (str) – Directory for available properties. Should be a json file.
load_mode (str, optional) – Type of reload source. Currently, only ‘database’ is available. Defaults to ‘database’, by default “database”
- Returns:
A flag indicating whether the market is reload successfully.
- Return type:
bool
- Raises:
NotImplementedError – Reload method NOT implemented. Currently, only loading from database is supported.
FileNotFoundError – Loading source/property_list NOT found. Check whether the source and property_list are available.
- search_learnware(target_properties: dict | None = None, target_stat_specification: str | None = None) Tuple[Any, Dict[str, List[Any]]]
Search Learnware based on properties and statistical specification.
Return random learnwares when both target_properties and target_stat_specification is None
Search only based on properties when target_stat_specification is None
Filter through properties and rank according to statistical specification otherwise
- Parameters:
target_properties (dict, optional) – Properties selected by user, by default None
target_stat_specification (str, optional) – statistical specification uploaded by user, by default None
- Returns:
return two items:
first is recommended combination, None when no recommended combination is calculated or statistical specification is not provided.
second is a list of matched learnwares
- Return type:
Tuple[Any, Dict[str, List[Any]]]
- Raises:
FileNotFoundError – Give file path is empty.
- update_learnware(id: str) bool
Update Learnware with id and content to be updated. Empty interface. TODO
- Parameters:
id (str) – id of target learnware.
Learnware
- class learnware.learnware.Learnware(id: str, name: str, model_path: str, specification: Specification, desc: str)
Specification
- class learnware.specification.Specification
- class learnware.specification.StatSpecification