Exemple #1
0
 def setUp(self):
     super().setUp()
     qubit_op_simple = MatrixOperator(matrix=TestIQPE.H1)
     qubit_op_simple = op_converter.to_weighted_pauli_operator(qubit_op_simple)
     qubit_op_h2_with_2_qubit_reduction = WeightedPauliOperator.from_dict(TestIQPE.PAULI_DICT)
     qubit_op_zz = WeightedPauliOperator.from_dict(TestIQPE.PAULI_DICT_ZZ)
     self._dict = {
         'QUBIT_OP_SIMPLE': qubit_op_simple.to_opflow(),
         'QUBIT_OP_ZZ': qubit_op_zz.to_opflow(),
         'QUBIT_OP_H2_WITH_2_QUBIT_REDUCTION': qubit_op_h2_with_2_qubit_reduction.to_opflow()
     }
 def from_params(cls, params):
     if EnergyInput.PROP_KEY_QUBITOP not in params:
         raise AquaError("Qubit operator is required.")
     qparams = params[EnergyInput.PROP_KEY_QUBITOP]
     qubit_op = WeightedPauliOperator.from_dict(qparams)
     if EnergyInput.PROP_KEY_AUXOPS in params:
         auxparams = params[EnergyInput.PROP_KEY_AUXOPS]
         aux_ops = [
             WeightedPauliOperator.from_dict(auxparams[i])
             for i in range(len(auxparams))
         ]
     return cls(qubit_op, aux_ops)
Exemple #3
0
    def setUp(self):
        super().setUp()
        self.seed = 50
        aqua_globals.random_seed = self.seed
        pauli_dict = {
            'paulis': [{
                "coeff": {
                    "imag": 0.0,
                    "real": -1.052373245772859
                },
                "label": "II"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.39793742484318045
                },
                "label": "IZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.39793742484318045
                },
                "label": "ZI"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.01128010425623538
                },
                "label": "ZZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.18093119978423156
                },
                "label": "XX"
            }]
        }
        self.qubit_op = WeightedPauliOperator.from_dict(pauli_dict).to_opflow()

        num_qubits = self.qubit_op.num_qubits
        ansatz = TwoLocal(num_qubits,
                          rotation_blocks=['ry', 'rz'],
                          entanglement_blocks='cz')
        warnings.filterwarnings('ignore', category=DeprecationWarning)
        self.ryrz_wavefunction = {
            'wrapped': RYRZ(num_qubits),
            'circuit': QuantumCircuit(num_qubits).compose(ansatz),
            'library': ansatz
        }

        ansatz = ansatz.copy()
        ansatz.rotation_blocks = 'ry'
        self.ry_wavefunction = {
            'wrapped': RY(num_qubits),
            'circuit': QuantumCircuit(num_qubits).compose(ansatz),
            'library': ansatz
        }
        warnings.filterwarnings('always', category=DeprecationWarning)
Exemple #4
0
def get_hamiltonian_operator(i_coef, z_coef, x_coef, y_coef):
    pauli_dict = {
        'paulis': [{"coeff": {"imag": 0.0, "real": i_coef}, "label": "II"},
                   {"coeff": {"imag": 0.0, "real": z_coef}, "label": "ZZ"},
                   {"coeff": {"imag": 0.0, "real": x_coef}, "label": "XX"},
                   {"coeff": {"imag": 0.0, "real": y_coef}, "label": "YY"}
                   ]
    }

    return WeightedPauliOperator.from_dict(pauli_dict)
Exemple #5
0
 def setUp(self):
     super().setUp()
     pauli_dict = {
         'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"},
                    {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "ZI"},
                    {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "IZ"},
                    {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"},
                    {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}
                    ]
     }
     self.qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
 def setUp(self):
     super().setUp()
     self.random_seed = 0
     np.random.seed(self.random_seed)
     pauli_dict = {
         'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"},
                    {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "IZ"},
                    {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "ZI"},
                    {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"},
                    {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}
                    ]
     }
     qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
     self.algo_input = EnergyInput(qubit_op)
Exemple #7
0
def hamiltonian_operator:
    """
    Creates the Hamilton for which we want to 
    estimate the least eigenvalue.
    
    """
    pauli_dict = {
        'paulis': [{"coeff": {"imag": 0.0, "real": -0.5}, "label": "II"},
                   {"coeff": {"imag": 0.0, "real": -0.5}, "label": "ZZ"},
                   {"coeff": {"imag": 0.0, "real": 0.5}, "label": "XX"},
                   {"coeff": {"imag": 0.0, "real": 0.5}, "label": "YY"}
                   ]
    }
    return WeightedPauliOperator.from_dict(pauli_dict)
Exemple #8
0
 def setUp(self):
     super().setUp()
     warnings.filterwarnings("ignore",
                             message=aqua_globals.CONFIG_DEPRECATION_MSG,
                             category=DeprecationWarning)
     # np.random.seed(50)
     self.seed = 50
     aqua_globals.random_seed = self.seed
     pauli_dict = {
         'paulis': [{
             "coeff": {
                 "imag": 0.0,
                 "real": -1.052373245772859
             },
             "label": "II"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": 0.39793742484318045
             },
             "label": "IZ"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": -0.39793742484318045
             },
             "label": "ZI"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": -0.01128010425623538
             },
             "label": "ZZ"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": 0.18093119978423156
             },
             "label": "XX"
         }]
     }
     self.qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
Exemple #9
0
    def setUp(self):
        super().setUp()
        np.random.seed(50)
        pauli_dict = {
            'paulis': [{
                "coeff": {
                    "imag": 0.0,
                    "real": -1.052373245772859
                },
                "label": "II"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.39793742484318045
                },
                "label": "IZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.39793742484318045
                },
                "label": "ZI"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.01128010425623538
                },
                "label": "ZZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.18093119978423156
                },
                "label": "XX"
            }]
        }
        qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
        self.algo_input = EnergyInput(qubit_op)
        self.reference_vqe_result = None

        # TODO: only work with optimization_level 0 now
        self.optimization_level = 0
Exemple #10
0
 def test_legacy_operator(self):
     """Test the VQE accepts and converts the legacy WeightedPauliOperator."""
     pauli_dict = {
         'paulis': [{
             "coeff": {
                 "imag": 0.0,
                 "real": -1.052373245772859
             },
             "label": "II"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": 0.39793742484318045
             },
             "label": "IZ"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": -0.39793742484318045
             },
             "label": "ZI"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": -0.01128010425623538
             },
             "label": "ZZ"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": 0.18093119978423156
             },
             "label": "XX"
         }]
     }
     h2_op = WeightedPauliOperator.from_dict(pauli_dict)
     vqe = VQE(h2_op)
     self.assertEqual(vqe.operator, self.h2_op)
Exemple #11
0
        "label": "ZI"
    }, {
        "coeff": {
            "imag": 0.0,
            "real": -0.01128010425623538
        },
        "label": "ZZ"
    }, {
        "coeff": {
            "imag": 0.0,
            "real": 0.18093119978423156
        },
        "label": "XX"
    }]
}
QUBIT_OP_H2_WITH_2_QUBIT_REDUCTION = WeightedPauliOperator.from_dict(
    PAULI_DICT)

PAULI_DICT_ZZ = {
    'paulis': [{
        "coeff": {
            "imag": 0.0,
            "real": 1.0
        },
        "label": "ZZ"
    }]
}
QUBIT_OP_ZZ = WeightedPauliOperator.from_dict(PAULI_DICT_ZZ)


class TestQPE(QiskitAquaTestCase):
    """QPE tests."""
Exemple #12
0
from qiskit.aqua.operators import WeightedPauliOperator, X, Z

W1 = np.array([[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]])
P1 = 1
M1 = WeightedPauliOperator.from_dict({
    'paulis': [{
        'label': 'IIIX',
        'coeff': {
            'real': 1
        }
    }, {
        'label': 'IIXI',
        'coeff': {
            'real': 1
        }
    }, {
        'label': 'IXII',
        'coeff': {
            'real': 1
        }
    }, {
        'label': 'XIII',
        'coeff': {
            'real': 1
        }
    }]
}).to_opflow()
S1 = {'0101', '1010'}

W2 = np.array([
    [0., 8., -9., 0.],
Exemple #13
0
Z = np.array([[1, 0], [0, -1]])
_I = np.array([[1, 0], [0, 1]])
h1 = X + Y + Z + _I
qubit_op_simple = MatrixOperator(matrix=h1)
qubit_op_simple = op_converter.to_weighted_pauli_operator(qubit_op_simple)

pauli_dict = {
    'paulis': [
        {"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"},
        {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "IZ"},
        {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "ZI"},
        {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"},
        {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}
    ]
}
qubit_op_h2_with_2_qubit_reduction = WeightedPauliOperator.from_dict(pauli_dict)


pauli_dict_zz = {
    'paulis': [
        {"coeff": {"imag": 0.0, "real": 1.0}, "label": "ZZ"}
    ]
}
qubit_op_zz = WeightedPauliOperator.from_dict(pauli_dict_zz)


class TestQPE(QiskitAquaTestCase):
    """QPE tests."""

    @parameterized.expand([
        [qubit_op_simple, 'qasm_simulator', 1, 5],
Exemple #14
0
    def setUp(self):
        super().setUp()
        pauli_dict = {
            'paulis': [{
                "coeff": {
                    "imag": 0.0,
                    "real": -1.052373245772859
                },
                "label": "II"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.39793742484318045
                },
                "label": "ZI"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.39793742484318045
                },
                "label": "IZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.01128010425623538
                },
                "label": "ZZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.18093119978423156
                },
                "label": "XX"
            }]
        }
        self.qubit_op = WeightedPauliOperator.from_dict(pauli_dict)

        aux_dict_1 = {
            'paulis': [{
                'coeff': {
                    'imag': 0.0,
                    'real': 2.0
                },
                'label': 'II'
            }]
        }
        aux_dict_2 = {
            'paulis': [{
                'coeff': {
                    'imag': 0.0,
                    'real': 0.5
                },
                'label': 'II'
            }, {
                'coeff': {
                    'imag': 0.0,
                    'real': 0.5
                },
                'label': 'ZZ'
            }, {
                'coeff': {
                    'imag': 0.0,
                    'real': 0.5
                },
                'label': 'YY'
            }, {
                'coeff': {
                    'imag': 0.0,
                    'real': -0.5
                },
                'label': 'XX'
            }]
        }
        self.aux_ops = [
            WeightedPauliOperator.from_dict(aux_dict_1),
            WeightedPauliOperator.from_dict(aux_dict_2)
        ]
    }, {
        "coeff": {
            "imag": 0.0,
            "real": -0.01128010425623538
        },
        "label": "ZZ"
    }, {
        "coeff": {
            "imag": 0.0,
            "real": 0.18093119978423156
        },
        "label": "XX"
    }]
}

qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
num_qubits = qubit_op.num_qubits
print('Number of qubits: {}'.format(num_qubits))

# ### Picking Quantum Circuit to Represent Wavefunction
# We will be discussing details on these waveforms tomorrow

# In[3]:

init_state = Zero(num_qubits)
var_form = RY(num_qubits, initial_state=init_state)

# # Using Simulator Backend

# In[4]: