Skip to content

Take-Me1010/Deap-supporter

Repository files navigation

Deap-supporter

Visual Studio Marketplace installs rating

An useful extension when you use Deap, which is a framework for Evolutionary Algorithm.

Features

This extension provides some useful code compliments when coding deap in python.

deap.creator.create is useful, however this function dynamically generates python class, so there is no code compliment for its class name and attributes. Now, if you install this extension, you are free to compliment them!!

Deap-supporter supports compliment, detail, a brief documentation and definition jump against

  • your classes generated by deap.creator.create()
  • your aliases registered by deap.base.ToolBox.register()

Usages

First of all, you must activate this extension by the command 'deap-supporter.activate'.

For this, execute the command:deap-supporter.activate.(keybinding: ctrl+alt+l)

I believe you can make sense easily by reading below example.

example

You will write...

from deap import base, creator, tools

creator.create('FitnessMax', base.Fitness, weights=(1.0, ))

then, execute the command:deap-supporter.activate from command pallet. ./images/commands.jpg

Well, keybinding: ctrl+alt+L is naturally more useful.

After you execute the command, the editor suggests FitnessMax with a brief documentation if you type creator. like below. you can see its base class and its attributes ./images/compliment-1.jpg

This documentation format may be changed in future version, but absolutely holds the information of its base class and its attributes.

In addition, the editor suggests its attributes with its initial value. This detail format may be changed in future version as well. ./images/compliment-2.jpg

And now, suppose you add the code below.

creator.create('Individual', list, fitness=creator.FitnessMax)

Then editor will suggest creator.Individual.

./images/compliment-3.jpg

examples above are for creator.create(), but ToolBox.register() is same. You will write codes like below.

import random
from deap import base, creator, tools

toolbox = base.Toolbox()
toolbox.register('attr_bool', random.randint, 0, 1)

The editor will suggest toolbox.attr_bool with its equivalent code like below . ./images/compliment-4.jpg

where additional args means the rest of its arguments, as ToolBox.register just do partial application.

If you use another name for the instance of deap.base.ToolBox, you must change settings for this extension. See Settings.

Attention

if your code is invalid like below,

creator.create('Individual', list, 

This extension won't load this line. The rule is that the line

  • starts with creator.create (or you can change its value. see Settings)
  • ends with )
  • has class name as a first argument; like creator.create('Foo', ...) or creator.create("Bar", ...)

Some of examples of invalid codes are

  • creator.create('Individual', list,
    • because the line does not end ')'.
  • creator.create(Hoge, fuga)
    • because it has no '' or "".

Extension Commands

deap-supporter.activate

keybinding: ctrl+alt+L

It is the command for you to activate this extension. Once you execute this command, the compliment for deap will be valid until you close VSCode. Why don't I always activate this extension? --- Apparently, I use python not always for deap.

Extension Settings

deap-supporter.alwaysOverwrite

default: true

If false, the classes and aliases will not be overwrote by deap-supporter.loadDocument or deap-supporter.loadSelection. You can overwrite them only by deap-supporter.reloadDocument.

deap-supporter.neverShowSuccessfulInformation

default: false

If true, never show the message to notify its process to load has finished successfully.

deap-supporter.createCallWay

default: "creator.create"

The coding style to call create().

If your coding style is like deap.creator.create(),

import deap
deap.creator.create('Hoge', Fuga, attr=10)

you should set this configuration 'deap.creator.create'.

For extreme example, if your code is like below,

from deap import creator as c
c.create('Foo', Bar, foobar=10)

you should set deap-supporter.createCallWay : c.create

deap-supporter.InstanceNameOfToolBox

default: "toolbox"

The name for instance of deap.base.ToolBox.

If your coding style is like below,

from deap import base

toolBox = base.ToolBox()

toolBox.register('Hoge', fuga)

You should set this configuration "toolBox".

This extension does not depend on how to call deap.base.ToolBox.

Requirements

No special requirements. You should just use the latest version of VScode.

Contributions

I want to implement a function to show the documentation and its signature, but I don't know how to do it. I'm waiting for your contribution.

Known Issues

  • Extension could not parse the string for "" before.
    • already fixed in version 1.0.1.

Changelog

See CHANGELOG.md

About

a useful extension for VScode when you use Deap

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published