Skip to main content

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

Project description

Grid Looper

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

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

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.

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]}}]
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')
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.

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

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}

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

gridlooper-0.0.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

gridlooper-0.0.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file gridlooper-0.0.2.tar.gz.

File metadata

  • Download URL: gridlooper-0.0.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for gridlooper-0.0.2.tar.gz
Algorithm Hash digest
SHA256 499e14d86c97b370eee544d07888b6cfff0a33ae84ceaf629f70f23dad9fb957
MD5 ad8cd8abfb3102e32a9f0222f5673ee7
BLAKE2b-256 e8b2beaa9c8d2df61e7730092c5292fc5cd536c538e25467a009988983b143c3

See more details on using hashes here.

File details

Details for the file gridlooper-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gridlooper-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for gridlooper-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cfebbe02dc6c5c99e8715e647f8ec2e96504c704994a297afdef1f61110a8b86
MD5 7b8048f167cc7d7919a7bc77ab3780d7
BLAKE2b-256 8ea5b287a6c6a35a46d088d183a9bbd0cacdbb130b395fa09c0c53899f92a48e

See more details on using hashes here.

Supported by

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