gridlooper


Namegridlooper JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryA tool to run experiments based on defined grid and function with single iteration.
upload_time2024-05-19 00:16:06
maintainerNone
docs_urlNone
authorKyrylo Mordan
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Grid Looper

A tool to run experiments based on defined grid and function with single iteration.


```python
import sys
sys.path.append('../')
from python_modules.gridlooper import GridLooper
```

## Usage examples

The examples contain:

1. preparing runner function
2. preparing search grid
3. running experiments
4. analysing results
    

### 1. Preparing runner function

Runner funtion should contain logic of experiment in a way that the parameters could be supplied with `embedder_params` 


```python
def runner_function(runner_params : dict, c : int):

    result = int(runner_params['a']) + runner_params['b'] + c

    return result
```

### 2. Preparing search grid

Experiment combos can be defined in short form, transformed into a list and filtered with `exlusion_combos`. Some of the parameters in experiment definition could be ignored durring experiment with a use of `exclusion_keys` parameter.


```python
experiments_settings = {
    'runner_params': {'a' : ['1', '2','4'],
                        'b' : [2, 6,10,100]},

    'c' : [100, 500],#, 1000, 5000]
    'name' : 'example experiment'
}

exclusion_keys = {'name'}

exclusion_combos = [{'runner_params': {'a': ['1','2'],
                                       'b': [100, 6,10]}}]
```


```python
gl = GridLooper(
    # dictionary of all possible parameter combos
    experiments_settings = experiments_settings,
    # keys from the experiments_settings to be ignored
    exclusion_keys = exclusion_keys,
    # combos from experiments_settings to be exluded
    exclusion_combos = exclusion_combos,
    # function that be run for each of experiment combos
    runner_function = runner_function,
    # optional parameter to be supplied to runner function outside of experiment settings
    data = None,
    # path to save experiment results
    save_path = 'example_run.dill')
```


```python
gl.prepare_search_grid(
    # optional if definer earlier
    experiments_settings = experiments_settings,
    exclusion_keys = exclusion_keys,
    exclusion_combos = exclusion_combos
)


gl.experiment_configs
```




    [{'runner_params': {'a': '1', 'b': 2},
      'c': 100,
      'config_id': '54eac3ee5ce6ae6d126502ee87dbbafce54111b346b895e1d5e29c50097fa800'},
     {'runner_params': {'a': '1', 'b': 2},
      'c': 500,
      'config_id': 'b2ef1c49a36375e88203f9ff1f01db69457fc9eb6435333aaafee68bb871d9da'},
     {'runner_params': {'a': '2', 'b': 2},
      'c': 100,
      'config_id': '4b1a723841dbf9f6e2a415159d0deb938373ba21506285289e46cafdcf455f05'},
     {'runner_params': {'a': '2', 'b': 2},
      'c': 500,
      'config_id': '44a22efdfe7e385b4fbaeb84976ac0d10703a98902ce134cddd1000e09ba156a'},
     {'runner_params': {'a': '4', 'b': 2},
      'c': 100,
      'config_id': '6dc5a94f832532513b1d739fdad694029b6b9d97cec9fa869ce3d75b822c23ce'},
     {'runner_params': {'a': '4', 'b': 2},
      'c': 500,
      'config_id': '9e7ec3d2e9d7d5ccf4b8c05b9a7a145fc443f77cd7031dcdaf139a77f88d5944'},
     {'runner_params': {'a': '4', 'b': 6},
      'c': 100,
      'config_id': 'dcd7c1aeb1b3c41ab924ece9ed471d682cef319304a9675dfd1f7d27f6e29c7c'},
     {'runner_params': {'a': '4', 'b': 6},
      'c': 500,
      'config_id': 'ad38629f25dd962d157ee8b36b1fc34a54079f8b08d0d4e79fd45cecfa167d49'},
     {'runner_params': {'a': '4', 'b': 10},
      'c': 100,
      'config_id': '6cd8cc53587798f4fc2583a122a7cad6e79cb7b6c10639e6a9714d12fa2c3092'},
     {'runner_params': {'a': '4', 'b': 10},
      'c': 500,
      'config_id': '495efcc2399e24fed5a5dee4b3909f27688b7723eb62b28be6ff6eb74c4e8574'},
     {'runner_params': {'a': '4', 'b': 100},
      'c': 100,
      'config_id': '2dcdd7a719ce8fa4731c8d9adefd131d809fd29e014aa9acd3be8a6538cc8765'},
     {'runner_params': {'a': '4', 'b': 100},
      'c': 500,
      'config_id': '64f83d857c2c3a0030bd187330da30dc6d4aaf2ae1418f150b9902a269a4f3d8'}]



### 3. Running experiments

`executing_experimets` function will run `runner_function` for each set of parameters from defined `experiment_configs` for a select loop strategy.


```python
gl.executing_experimets(
    # optional of defined earlier
    runner_function = runner_function,
    experiment_configs = gl.experiment_configs,
    data = None,
    loop_type= 'brute',
    save_path = 'example_run.dill'
)
```

    
Looping:   0%|          | 0/12 [00:00<?, ?item/s]

    
Looping: 100%|██████████| 12/12 [00:00<00:00, 156796.41item/s]

    


### 4. Analysing results


```python
gl.experiment_results['results']
```




    {'54eac3ee5ce6ae6d126502ee87dbbafce54111b346b895e1d5e29c50097fa800': 103,
     'b2ef1c49a36375e88203f9ff1f01db69457fc9eb6435333aaafee68bb871d9da': 503,
     '4b1a723841dbf9f6e2a415159d0deb938373ba21506285289e46cafdcf455f05': 104,
     '44a22efdfe7e385b4fbaeb84976ac0d10703a98902ce134cddd1000e09ba156a': 504,
     '6dc5a94f832532513b1d739fdad694029b6b9d97cec9fa869ce3d75b822c23ce': 106,
     '9e7ec3d2e9d7d5ccf4b8c05b9a7a145fc443f77cd7031dcdaf139a77f88d5944': 506,
     'dcd7c1aeb1b3c41ab924ece9ed471d682cef319304a9675dfd1f7d27f6e29c7c': 110,
     'ad38629f25dd962d157ee8b36b1fc34a54079f8b08d0d4e79fd45cecfa167d49': 510,
     '6cd8cc53587798f4fc2583a122a7cad6e79cb7b6c10639e6a9714d12fa2c3092': 114,
     '495efcc2399e24fed5a5dee4b3909f27688b7723eb62b28be6ff6eb74c4e8574': 514,
     '2dcdd7a719ce8fa4731c8d9adefd131d809fd29e014aa9acd3be8a6538cc8765': 204,
     '64f83d857c2c3a0030bd187330da30dc6d4aaf2ae1418f150b9902a269a4f3d8': 604}



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gridlooper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Kyrylo Mordan",
    "author_email": "parachute.repo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/b2/beaa9c8d2df61e7730092c5292fc5cd536c538e25467a009988983b143c3/gridlooper-0.0.2.tar.gz",
    "platform": null,
    "description": "# Grid Looper\n\nA tool to run experiments based on defined grid and function with single iteration.\n\n\n```python\nimport sys\nsys.path.append('../')\nfrom python_modules.gridlooper import GridLooper\n```\n\n## Usage examples\n\nThe examples contain:\n\n1. preparing runner function\n2. preparing search grid\n3. running experiments\n4. analysing results\n    \n\n### 1. Preparing runner function\n\nRunner funtion should contain logic of experiment in a way that the parameters could be supplied with `embedder_params` \n\n\n```python\ndef runner_function(runner_params : dict, c : int):\n\n    result = int(runner_params['a']) + runner_params['b'] + c\n\n    return result\n```\n\n### 2. Preparing search grid\n\nExperiment combos can be defined in short form, transformed into a list and filtered with `exlusion_combos`. Some of the parameters in experiment definition could be ignored durring experiment with a use of `exclusion_keys` parameter.\n\n\n```python\nexperiments_settings = {\n    'runner_params': {'a' : ['1', '2','4'],\n                        'b' : [2, 6,10,100]},\n\n    'c' : [100, 500],#, 1000, 5000]\n    'name' : 'example experiment'\n}\n\nexclusion_keys = {'name'}\n\nexclusion_combos = [{'runner_params': {'a': ['1','2'],\n                                       'b': [100, 6,10]}}]\n```\n\n\n```python\ngl = GridLooper(\n    # dictionary of all possible parameter combos\n    experiments_settings = experiments_settings,\n    # keys from the experiments_settings to be ignored\n    exclusion_keys = exclusion_keys,\n    # combos from experiments_settings to be exluded\n    exclusion_combos = exclusion_combos,\n    # function that be run for each of experiment combos\n    runner_function = runner_function,\n    # optional parameter to be supplied to runner function outside of experiment settings\n    data = None,\n    # path to save experiment results\n    save_path = 'example_run.dill')\n```\n\n\n```python\ngl.prepare_search_grid(\n    # optional if definer earlier\n    experiments_settings = experiments_settings,\n    exclusion_keys = exclusion_keys,\n    exclusion_combos = exclusion_combos\n)\n\n\ngl.experiment_configs\n```\n\n\n\n\n    [{'runner_params': {'a': '1', 'b': 2},\n      'c': 100,\n      'config_id': '54eac3ee5ce6ae6d126502ee87dbbafce54111b346b895e1d5e29c50097fa800'},\n     {'runner_params': {'a': '1', 'b': 2},\n      'c': 500,\n      'config_id': 'b2ef1c49a36375e88203f9ff1f01db69457fc9eb6435333aaafee68bb871d9da'},\n     {'runner_params': {'a': '2', 'b': 2},\n      'c': 100,\n      'config_id': '4b1a723841dbf9f6e2a415159d0deb938373ba21506285289e46cafdcf455f05'},\n     {'runner_params': {'a': '2', 'b': 2},\n      'c': 500,\n      'config_id': '44a22efdfe7e385b4fbaeb84976ac0d10703a98902ce134cddd1000e09ba156a'},\n     {'runner_params': {'a': '4', 'b': 2},\n      'c': 100,\n      'config_id': '6dc5a94f832532513b1d739fdad694029b6b9d97cec9fa869ce3d75b822c23ce'},\n     {'runner_params': {'a': '4', 'b': 2},\n      'c': 500,\n      'config_id': '9e7ec3d2e9d7d5ccf4b8c05b9a7a145fc443f77cd7031dcdaf139a77f88d5944'},\n     {'runner_params': {'a': '4', 'b': 6},\n      'c': 100,\n      'config_id': 'dcd7c1aeb1b3c41ab924ece9ed471d682cef319304a9675dfd1f7d27f6e29c7c'},\n     {'runner_params': {'a': '4', 'b': 6},\n      'c': 500,\n      'config_id': 'ad38629f25dd962d157ee8b36b1fc34a54079f8b08d0d4e79fd45cecfa167d49'},\n     {'runner_params': {'a': '4', 'b': 10},\n      'c': 100,\n      'config_id': '6cd8cc53587798f4fc2583a122a7cad6e79cb7b6c10639e6a9714d12fa2c3092'},\n     {'runner_params': {'a': '4', 'b': 10},\n      'c': 500,\n      'config_id': '495efcc2399e24fed5a5dee4b3909f27688b7723eb62b28be6ff6eb74c4e8574'},\n     {'runner_params': {'a': '4', 'b': 100},\n      'c': 100,\n      'config_id': '2dcdd7a719ce8fa4731c8d9adefd131d809fd29e014aa9acd3be8a6538cc8765'},\n     {'runner_params': {'a': '4', 'b': 100},\n      'c': 500,\n      'config_id': '64f83d857c2c3a0030bd187330da30dc6d4aaf2ae1418f150b9902a269a4f3d8'}]\n\n\n\n### 3. Running experiments\n\n`executing_experimets` function will run `runner_function` for each set of parameters from defined `experiment_configs` for a select loop strategy.\n\n\n```python\ngl.executing_experimets(\n    # optional of defined earlier\n    runner_function = runner_function,\n    experiment_configs = gl.experiment_configs,\n    data = None,\n    loop_type= 'brute',\n    save_path = 'example_run.dill'\n)\n```\n\n    \nLooping:   0%|          | 0/12 [00:00<?, ?item/s]\n\n    \nLooping: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 12/12 [00:00<00:00, 156796.41item/s]\n\n    \n\n\n### 4. Analysing results\n\n\n```python\ngl.experiment_results['results']\n```\n\n\n\n\n    {'54eac3ee5ce6ae6d126502ee87dbbafce54111b346b895e1d5e29c50097fa800': 103,\n     'b2ef1c49a36375e88203f9ff1f01db69457fc9eb6435333aaafee68bb871d9da': 503,\n     '4b1a723841dbf9f6e2a415159d0deb938373ba21506285289e46cafdcf455f05': 104,\n     '44a22efdfe7e385b4fbaeb84976ac0d10703a98902ce134cddd1000e09ba156a': 504,\n     '6dc5a94f832532513b1d739fdad694029b6b9d97cec9fa869ce3d75b822c23ce': 106,\n     '9e7ec3d2e9d7d5ccf4b8c05b9a7a145fc443f77cd7031dcdaf139a77f88d5944': 506,\n     'dcd7c1aeb1b3c41ab924ece9ed471d682cef319304a9675dfd1f7d27f6e29c7c': 110,\n     'ad38629f25dd962d157ee8b36b1fc34a54079f8b08d0d4e79fd45cecfa167d49': 510,\n     '6cd8cc53587798f4fc2583a122a7cad6e79cb7b6c10639e6a9714d12fa2c3092': 114,\n     '495efcc2399e24fed5a5dee4b3909f27688b7723eb62b28be6ff6eb74c4e8574': 514,\n     '2dcdd7a719ce8fa4731c8d9adefd131d809fd29e014aa9acd3be8a6538cc8765': 204,\n     '64f83d857c2c3a0030bd187330da30dc6d4aaf2ae1418f150b9902a269a4f3d8': 604}\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A tool to run experiments based on defined grid and function with single iteration.",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ea5b287a6c6a35a46d088d183a9bbd0cacdbb130b395fa09c0c53899f92a48e",
                "md5": "7b8048f167cc7d7919a7bc77ab3780d7",
                "sha256": "cfebbe02dc6c5c99e8715e647f8ec2e96504c704994a297afdef1f61110a8b86"
            },
            "downloads": -1,
            "filename": "gridlooper-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b8048f167cc7d7919a7bc77ab3780d7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7564,
            "upload_time": "2024-05-19T00:16:04",
            "upload_time_iso_8601": "2024-05-19T00:16:04.609205Z",
            "url": "https://files.pythonhosted.org/packages/8e/a5/b287a6c6a35a46d088d183a9bbd0cacdbb130b395fa09c0c53899f92a48e/gridlooper-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8b2beaa9c8d2df61e7730092c5292fc5cd536c538e25467a009988983b143c3",
                "md5": "ad8cd8abfb3102e32a9f0222f5673ee7",
                "sha256": "499e14d86c97b370eee544d07888b6cfff0a33ae84ceaf629f70f23dad9fb957"
            },
            "downloads": -1,
            "filename": "gridlooper-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ad8cd8abfb3102e32a9f0222f5673ee7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10007,
            "upload_time": "2024-05-19T00:16:06",
            "upload_time_iso_8601": "2024-05-19T00:16:06.265837Z",
            "url": "https://files.pythonhosted.org/packages/e8/b2/beaa9c8d2df61e7730092c5292fc5cd536c538e25467a009988983b143c3/gridlooper-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-19 00:16:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gridlooper"
}
        
Elapsed time: 0.27436s