Skip to content

Commit

Permalink
clean + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fenke committed Jun 24, 2024
1 parent 8aed56c commit bb9394a
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 25 deletions.
78 changes: 67 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fetching data and parameters and converting the result for the caller.

### AICore modules

For AICore users define a class, always named `Module` with a
For AICore users define a class, always named `CustomModule` with a
constructor `__init__` and a method `infer`.

This package defines a baseclass to quickly construct a custom `Module`
This package defines a baseclass to quickly construct a `CustomModule`
class that is able to use a wodan processor function inside the AICore
system:

Expand All @@ -59,7 +59,7 @@ import corebridge
def multiply(data:np.ndarray, multiplier:float=1.0):
return data * multiplier
class Module(corebridge.aicorebridge.AICoreModule):
class CustomModule(corebridge.aicorebridge.AICoreModule):
def __init__(self, save_dir, assets_dir, *args, **kwargs):
super().__init__(multiply, save_dir, assets_dir, *args, **kwargs)
Expand All @@ -74,22 +74,78 @@ Wodan service.

## Development

### NBDev

This library is developed with [NBDev](https://nbdev.fast.ai/) - a
literate programming toolkit that supports developing code using jupyter
notebooks and mix code with documentation.

Literate programming is a methodology - introduced in 1984 by Donald
Knuth - that combines a programming language with a documentation
language. In this approach, a program is explained in a human language
(such as English) alongside code snippets. The literate source file is
then processed by a preprocessor to produce both source code and
formatted documentation.

This paradigm enhances program robustness, portability, and
maintainability, making it a valuable tool in scientific computing and
data science[^1]

### Quarto

Documentation is prepared from the notebook with
[Quarto](https://quarto.org/). Quarto too combines code with
documentation but it does not extract source code into modules like
nbdev.

### Installation

#### Quarto

Quarto uses Pandoc and, for pdf format, LaTeX. These must be available
on your system.

Install [Quarto](https://quarto.org/docs/get-started/) as you see fit,
there is a [VSCode
extension](https://marketplace.visualstudio.com/items?itemName=quarto.quarto)
which handles this.

#### NBDev

NBDev is available as PyPi package and is installed with

pip install nbdev

or if you are using conda

conda install -c fastai -y nbdev

If so desired you can let NBDev install Quarto with

nbdev_install_quarto

But this ask for the system admin password.

### Local editing & testing

Setup a virtual environment, activate it and install the development
package and dependencies with, on linux

pip install -e ‘.\[dev\]’
pip install -e ‘.[dev]’

or on Windows

pip install -e .\[dev\]
pip install -e .[dev]

### nbdev cycle

- edit
- nbdev_export
- nbdev_test
- nbdev_clean
- nbdev_readme
- nbdev_prepare
- git add .
-

The latter performs - nbdev_export - nbdev_test - nbdev_clean -
nbdev_readme

Then commit and to upload to Pypi with `nbdev_pypi`

[^1]: [Wikipedia on ‘Literate
Programming’](https://en.wikipedia.org/wiki/Literate_programming)
2 changes: 0 additions & 2 deletions corebridge/aicorebridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def init_annotated_param(self:AICoreModule, K, value):
"Get arguments for the processor call"

annotation = self.processor_signature.parameters[K].annotation
print(K, annotation, value)

for T in typing.get_args(annotation):
try:
Expand All @@ -197,7 +196,6 @@ def init_annotated_param(self:AICoreModule, K, value):
except TypeError as err:
syslog.exception(f"Exception {str(err)} in fallback conversion to {self.processor_signature.parameters[K].annotation} of {type(value)}")

return None


# %% ../nbs/01_aicorebridge.ipynb 19
Expand Down
3 changes: 3 additions & 0 deletions corebridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def timeseries_dataframe_to_datadict(
sum=lambda R: R.sum(),
std=lambda R: R.std(),
var=lambda R: R.var(),
cumsum=lambda R: R.cumsum(),
cummax=lambda R: R.cummax(),
cummin=lambda R: R.cummin(),

)

Expand Down
3 changes: 3 additions & 0 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@
" sum=lambda R: R.sum(),\n",
" std=lambda R: R.std(),\n",
" var=lambda R: R.var(),\n",
" cumsum=lambda R: R.cumsum(),\n",
" cummax=lambda R: R.cummax(),\n",
" cummin=lambda R: R.cummin(),\n",
"\n",
")\n",
"\n",
Expand Down
6 changes: 2 additions & 4 deletions nbs/01_aicorebridge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@
" \"Get arguments for the processor call\"\n",
"\n",
" annotation = self.processor_signature.parameters[K].annotation\n",
" print(K, annotation, value)\n",
"\n",
" for T in typing.get_args(annotation):\n",
" try:\n",
Expand All @@ -374,11 +373,10 @@
" #syslog.exception(f\"Exception {str(err)} in conversion to {T} of {type(value)}\")\n",
" continue\n",
" try:\n",
" return self.processor_signature.parameters[K].annotation(value)\n",
" return annotation(value)\n",
" except TypeError as err:\n",
" syslog.exception(f\"Exception {str(err)} in fallback conversion to {self.processor_signature.parameters[K].annotation} of {type(value)}\")\n",
" syslog.exception(f\"Exception {str(err)} in fallback conversion to {annotation} of {type(value)}\")\n",
"\n",
" return None\n",
" "
]
},
Expand Down
92 changes: 84 additions & 8 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
"source": [
"### AICore modules\n",
"\n",
"For AICore users define a class, always named `Module` with a constructor `__init__` and a method `infer`.\n",
"For AICore users define a class, always named `CustomModule` with a constructor `__init__` and a method `infer`.\n",
"\n",
"This package defines a baseclass to quickly construct a custom `Module` class that is able to use a wodan processor function inside the AICore system:\n",
"This package defines a baseclass to quickly construct a `CustomModule` class that is able to use a wodan processor function inside the AICore system:\n",
"\n",
"\n",
"\n",
Expand All @@ -109,7 +109,7 @@
"def multiply(data:np.ndarray, multiplier:float=1.0):\n",
" return data * multiplier\n",
"\n",
"class Module(corebridge.aicorebridge.AICoreModule):\n",
"class CustomModule(corebridge.aicorebridge.AICoreModule):\n",
" def __init__(self, save_dir, assets_dir, *args, **kwargs):\n",
" super().__init__(multiply, save_dir, assets_dir, *args, **kwargs)\n",
" \n",
Expand All @@ -131,17 +131,86 @@
"source": [
"## Development\n",
"\n",
"### NBDev\n",
"\n",
"This library is developed with [NBDev](https://nbdev.fast.ai/) - a literate programming \n",
"toolkit that supports developing code using jupyter notebooks and mix code with documentation.\n",
"\n",
"Literate programming is a methodology - introduced in 1984 by Donald Knuth - that combines a \n",
"programming language with a documentation language. In this approach, a program is explained \n",
"in a human language (such as English) alongside code snippets.\n",
"The literate source file is then processed by a preprocessor to produce both source code \n",
"and formatted documentation.\n",
"\n",
"This paradigm enhances program robustness, portability, and maintainability, making it a \n",
"valuable tool in scientific computing and data science[^1]\n",
"\n",
"[^1]: [Wikipedia on 'Literate Programming'](https://en.wikipedia.org/wiki/Literate_programming)\n",
"\n",
"### Quarto\n",
"\n",
"Documentation is prepared from the notebook with [Quarto](https://quarto.org/). Quarto too\n",
"combines code with documentation but it does not extract source code into modules like nbdev.\n",
"\n",
"### Installation\n",
"\n",
"#### Quarto\n",
"\n",
"Quarto uses Pandoc and, for pdf format, LaTeX. These must be available on your system.\n",
"\n",
"Install [Quarto](https://quarto.org/docs/get-started/) as you see fit, there is a \n",
"[VSCode extension](https://marketplace.visualstudio.com/items?itemName=quarto.quarto) which \n",
"handles this. \n",
"\n",
"#### NBDev\n",
"\n",
"NBDev is available as PyPi package and is installed with\n",
"\n",
" pip install nbdev\n",
"\n",
"or if you are using conda\n",
"\n",
" conda install -c fastai -y nbdev\n",
"\n",
"If so desired you can let NBDev install Quarto with \n",
"\n",
" nbdev_install_quarto\n",
"\n",
"But this ask for the system admin password.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"### Local editing & testing\n",
"\n",
"Setup a virtual environment, activate it and install the development package and dependencies with, on linux\n",
"\n",
"``` \n",
" pip install -e ‘.\\[dev\\]’\n",
" pip install -e ‘.[dev]’\n",
"\n",
"```\n",
"\n",
"or on Windows\n",
"\n",
"```\n",
" pip install -e .\\[dev\\]\n",
" pip install -e .[dev]\n",
"\n",
"```"
]
Expand All @@ -153,14 +222,21 @@
"### nbdev cycle\n",
"\n",
"- edit\n",
"- nbdev_prepare\n",
"\n",
"The latter performs\n",
"- nbdev_export\n",
"- nbdev_test\n",
"- nbdev_clean\n",
"- nbdev_readme\n",
"- nbdev_prepare\n",
"- git add .\n",
"- \n"
"\n",
"Then commit and to upload to Pypi with `nbdev_pypi`\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit bb9394a

Please sign in to comment.