Genetic Algorithm for VQC ansatz search

raw JSON →
1.0.14 verified Sat May 09 auth: no python

GA-VQC provides a genetic algorithm to automatically search for optimal variational quantum circuit (VQC) ansätze for quantum machine learning tasks. Version 1.0.14 is the latest; development appears to be active on GitHub.

pip install ga-vqc
error ModuleNotFoundError: No module named 'ga_vqc'
cause Incorrect import path; correct module name is 'gavqc'.
fix
Use: from gavqc import GenAlg
error TypeError: __init__() got an unexpected keyword argument 'X'
cause GenAlg expects 'X' and 'y' as positional or keyword arguments, but older versions used different parameter names.
fix
Ensure you are using the latest version (pip install --upgrade ga-vqc). The current API accepts 'X' and 'y'.
breaking Import path changed: module name is 'gavqc' (not 'ga_vqc' or 'ga-vqc').
fix Use 'from gavqc import ...' instead of 'import ga_vqc'.
gotcha GenAlg.run() modifies the instance; best circuit stored in GenAlg.best_circuit attribute.
fix Access results via the GenAlg instance after calling run().
deprecated Support for Qiskit <0.45 is dropped.
fix Upgrade to Qiskit 0.45+.

Minimal example to run genetic algorithm for VQC ansatz search.

from gavqc import GenAlg
from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import RealAmplitudes
import numpy as np

# Example: optimize a simple circuit structure
ansatz = RealAmplitudes(2, reps=1)
X = np.random.rand(10, 2)
y = np.random.randint(0, 2, 10)

ga = GenAlg(
    ansatz=ansatz,
    X=X, y=y,
    generations=10,
    population_size=10,
    mutation_rate=0.1
)
ga.run()
print("Best fitness:", ga.best_fitness)
print("Best circuit:", ga.best_circuit)