• Members 19 posts
    Oct. 24, 2021, 10:40 a.m.

    In Qiskit, I want to use MinimumEigenOptimizer to find the minimum value and the corresponding vector for a quadratic problem. I am looking for a binary vector solution in this quadratic problem, namely $x \in { 0,1 }$. I thought the MinimumEigenOptimizer can automatically translate a quadratic program into an Ising Hamiltonian and back, but I got an error says 'Unsupported variable type VarType.BINARY'.

    Below is the code:

    import numpy as np
    
    mu = np.array([2.5, 4.2, 1])
    sigma = np.array([[1, 0, -1],
                      [0, 1, 0.7],
                     [-1, 0.7, 1]])
    budget = 2 # select 2 out of 3 assets
    risk_factor = 0.7 # risk factor "q"
    
    from qiskit_finance.applications.optimization import PortfolioOptimization
    popt = PortfolioOptimization(expected_returns = mu, covariances = sigma, risk_factor = risk_factor, budget = budget)
    
    # Define the quadratic program
    qp = popt.to_quadratic_program()
    
    from qiskit import Aer
    sim = Aer.get_backend('qasm_simulator')
    
    
    from qiskit.circuit.library import RealAmplitudes
    # Choose real amplitudes because the amplitude z (whether to choose the asset) is supposed to be real
    ansatz = RealAmplitudes(3, reps = 2)
    
    from qiskit.algorithms import VQE
    from qiskit.algorithms.optimizers import SLSQP
    from qiskit.optimization.algorithms import MinimumEigenOptimizer
    
    vqe = VQE(ansatz, optimizer=SLSQP(), quantum_instance=sim)
    vqe_optimizer = MinimumEigenOptimizer(vqe)
    
    # The MinimumEigenOptimizer should internally maps the quadratic program to an Ising Hamiltonian and back
    vqe_result = vqe_optimizer.solve(qp)
    

    This is the information about my quadratic program:

    \ This file has been generated by DOcplex
    \ ENCODING=ISO-8859-1
    \Problem name: Portfolio optimization
    
    Minimize
     obj: - 2.500000000000 x_0 - 4.200000000000 x_1 - x_2 + [ 1.400000000000 x_0^2
          - 2.800000000000 x_0*x_2 + 1.400000000000 x_1^2 + 1.960000000000 x_1*x_2
          + 1.400000000000 x_2^2 ]/2
    Subject To
     c0: x_0 + x_1 + x_2 = 2
    
    Bounds
     0 <= x_0 <= 1
     0 <= x_1 <= 1
     0 <= x_2 <= 1
    
    Binaries
     x_0 x_1 x_2
    End
    

    And the error message:

    QiskitOptimizationError: 'Unsupported variable type VarType.BINARY'