albertnieto / quantum_convolutional_nn_benchmark

Benchmarking quanvolutional neural networks with QCML and Pennylane.
Apache License 2.0
3 stars 1 forks source link

Define flexible network architecture #6

Open albertnieto opened 1 month ago

albertnieto commented 1 month ago

Example:

hyperparameters = {
    'learning_rate': [0.001, 0.0001],
    'quanv1_params': [
        {'qkernel_shape': 2, 'params': params1},
        {'qkernel_shape': 3, 'params': params2},
    ],
    'quanv2_params': [
        {'qkernel_shape': 2, 'params': params3},
        {'qkernel_shape': 3, 'params': params4},
    ],
    'conv_layers': [
        [{'type': 'Conv2d', 'out_channels': 16, 'kernel_size': 3}],
        [{'type': 'Conv2d', 'out_channels': 32, 'kernel_size': 5}],
    ],
    # ...
}
albertnieto commented 1 month ago

Something like this

        self.layers = nn.ModuleList()
        for layer_config in architecture:
            layer_type = layer_config['type']
            params = layer_config['params']
            if layer_type == 'QuanvLayer':
                self.layers.append(QuanvLayer(**params))
            elif layer_type == 'Conv2d':
                self.layers.append(nn.Conv2d(**params))
            elif layer_type == 'Linear':
                self.layers.append(nn.Linear(**params))