Prerequisites: Python + an IDE (a code editor)

Optionally, to more easily manage Python packages, you’ll need a Python package manager.

See the Setup page if you’re missing any of these.

Initialising a code repository

To create and run a Generative Function you need somewhere to store and run the code. This is simply a folder anywhere on your computer that has access to Python.

If you're using VS Code, then you should end up with something like this

1

Create an empty folder

Call it something like GenerativeEngineering

2

Open the folder in your IDE

If you’re using an IDE (Integrated Development Environment) like VS Code, open your folder in it.

If you’re not using an IDE, skip this step.

3

Open a terminal at your folder

If you’re using an IDE, you can most easily do this there.

Make sure the terminal is open at the folder you’ve created. In the terminal prompt you can normally see the folder the terminal is running in.

4

Install the Generative packages

Install Generative packages generative-core and generative-server Python packages from pypi.generative.vision.

Open a terminal window, navigate to the folder you created, and run:

pip
pip install --extra-index-url https://pypi.generative.vision/simple generative-server
python -m generative.server --version

If this is successful, the version of generative-server will be printed.

If you’re not using a virtual environment (venv), this installs Generative packages globally - so you’d only need to do this once per machine. If you are using a venv then you will need to install generative server inside the venv.

5

Create a folder within your repository

Make a folder, for example called functions, within your repository. This will hold your Python code.

6

Create a Python file within your folder

Create a file, for example called generative_functions.py within your folder to hold the Python code.

Writing a Generative Function

In the Python file created above, define a function which describes the engineering system you want to explore over, and add the @generative_function decorator to make it accessible in the app.

For example, copy the below code to define a simple function which divides two numbers.

generative_functions.py
from generative.core import generative_function


@generative_function
def divide(numerator: float, denominator: float) -> float:
    if denominator == 0:
        raise ValueError("Denominator can't be zero")
    return numerator / denominator

Connecting to the app

Now you have finished creating your first Generative Function, the next step is to connect to the app to start generating designs.

1

Start a function server

Run the following command from a terminal at the root of your repository or in the folder your Generative Function is in

The command assumes that your generative functions are in a folder within your repository called functions. If that’s not true, replace the word functions with the relative path to where your generative functions Python file is, or remove it entirely if your Python file is in the folder where your terminal is running.

python -m generative.server start functions --no-reload

When you make changes to your function, manually stop the server (Ctrl + C) and run the above command again. If you want the server to automatically restart when you make changes to your function, you can remove the --no-reload option or use --reload, but on Windows this is known to cause issues so we recommend using --no-reload.

To learn more, see the concepts section.

2

Login to the app

Account is required to proceed. If you haven’t already, sign up at generative.vision.

Open app

3

Create an empty project

Create and navigate to an empty project. Under the ‘Experiment’ tab, your local function server will be automatically detected if it’s running on port 3000.

If your function server is not detected, check the logs in your terminal where you’re running the server. If the server started correctly, you should see a link, which will take you the server’s API docs page.

Generating your first designs

You should now have a project open in the app connected to your new Generative Function.

If you haven’t got the Generative Function running on a Function Server, you can go to the app and open a copy of the tutorial project ''.

From here you can use the Generative Function running in our cloud to continue with the rest of the tutorial.

1

Set up an experiment

Before you start generating designs, you need to constrain the parameters exposed by your Generative Function by giving them values.

For example, set numerator and denominator parameters to vary between 0 and 4.

Experiment is set up and ready to generate designs

2

Click 'Generate' to start

Once you have some values set, you can start generating data for all parameters specified in your Generative Function.

The algorithm will try to work within the constraints you set and generate data that you can visualise next.

Visualising generated data

Navigate to the ‘Discover’ tab. This is where you can visualise the generated data and curate it to find new insights.

You can follow the instructions to create a visualisation of the latest experiment across numerator, denominator and output parameters.

View results on the Discover page

This is a very simple function, but you can already see that the output increases strongly as the denominator approaches 0.

Finished project

Congratulations, you finished the tutorial!

To see the finished project:

  1. Go to the app
  2. Open a copy of the tutorial project ''
  3. Navigate to the ‘Discover’ tab to view generated designs

More learning

Now you’ve run your first experiment, if you want to learn more, check out the key concepts or try a more complex tutorial like exploring tradeoffs of an airfoil design.