I need to optimize hyperparameters of this structure in Python:
#Transforming into dedicated structures
xdm_train = xgboost.DMatrix(X, Y, enable_categorical=True, missing=True)
xdm_test  = xgboost.DMatrix(X_test, Y_test, enable_categorical=True, missing=True)

#Model training
model = xgboost.train({'n_estimators': 908, 'max_depth': 1, 'learning_rate': 0.11575834769675744, 'subsample': 0.5942016415422035, 'gamma': 8.93125490769455, 'reg_alpha': 0.14364869510112377, 'reg_lambda': 0.7243048640150956,'eval_metric': 'auc','objective': 'binary:logitraw'}, xdm_train, 20, [(xdm_test, 'eval'), (xdm_train, 'train')])
print(model)

using those optuna functions:
def objective(trial):
    n_estimators =  trial.suggest_int('n_estimators', 15,1000)
    max_depth = trial.suggest_int('max_depth', 1,20) 
    learning_rate = trial.suggest_float('learning_rate', 0,0.5)
    subsample = trial.suggest_float('subsample', 0,1)
    gamma = trial.suggest_float("gamma", 1e-4, 1e2)
    reg_alpha = trial.suggest_float('reg_alpha', 0,1)
    reg_lambda = trial.suggest_float('reg_lambda', 0,1)
    
    model = XGBClassifier(
            n_estimators=n_estimators,
            max_depth=max_depth,
            learning_rate=learning_rate,
            subsample=subsample,
            gamma=gamma,
            reg_alpha=reg_alpha,
            reg_lambda=reg_lambda,
            eval_metric='auc'
        )
    
    score, is_overfitted = validate(model, X, Y)
    
    if is_overfitted:
        return 0
    else:
        return score

study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=500)

and 
def validate(model, X, y, X_test=None, y_test=None, show_results=False):
    is_classification = is_classifier(model)
    use_cross_validation = X_test is None or y_test is None
        
    if use_cross_validation:
        if is_classification:
            scoring = "roc_auc"
        else:
            scoring = "r2"
            
        val_results = cross_validate(model, X, y, scoring=scoring, n_jobs=-1, return_train_score=True, cv=3)
        train_score = np.mean(val_results["train_score"])
        test_score = np.mean(val_results["test_score"])
    else:           
        model.fit(X, y)
        pred_train = model.predict(X)
        pred_test = model.predict(X_test)
        
        if is_classification:
            train_score = metrics.accuracy_score(y, pred_train)
            test_score = metrics.accuracy_score(y_test, pred_test)
            
            if show_results:
                plot_confusion_matrix(y_test, pred_test)
        else:
            train_score = metrics.r2_score(y, pred_train)
            test_score = metrics.r2_score(y_test, pred_test)
            
            if show_results:
                raw_y_train = exp_y(y)
                raw_y_test = exp_y(y_test)
                raw_pred_train = exp_y(pred_train)
                raw_pred_test = exp_y(pred_test)
                
                plot_pred_data(raw_y_test, raw_pred_test)
                print(f"train MAE on y:", metrics.mean_absolute_error(raw_y_train, raw_pred_train))
                print(f"test MAE on y:", metrics.mean_absolute_error(raw_y_test, raw_pred_test))
            
    is_overfitted = train_score - test_score > 0.025 
        
    if show_results:
        if is_classification:
            print(f"train acc:", train_score)
            print(f"test acc:", test_score)
        else:
            print(f"train r2 on log y:", train_score)
            print(f"test r2 on log y:", test_score)
            
        if is_overfitted:
            print("Overfitted")
        
    return test_score, is_overfitted    

Replace the necessery elements to fit the model mentioned in the first place.