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 = Operator.load_from_dict(qparams) if EnergyInput.PROP_KEY_AUXOPS in params: auxparams = params[EnergyInput.PROP_KEY_AUXOPS] aux_ops = [Operator.load_from_dict(auxparams[i]) for i in range(len(auxparams))] return cls(qubit_op, aux_ops)
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 = Operator.load_from_dict(pauli_dict) self.algo_input = EnergyInput(qubit_op) backends = ['statevector_simulator', 'qasm_simulator'] res = {} for backend in backends: params_no_caching = { 'algorithm': {'name': 'VQE', 'operator_mode': 'matrix' if backend == 'statevector_simulator' else 'paulis'}, 'problem': {'name': 'energy', 'random_seed': 50, 'circuit_caching': False, 'skip_qobj_deepcopy': False, 'skip_qobj_validation': False, 'circuit_cache_file': None, }, 'backend': {'provider': 'qiskit.BasicAer', 'name': backend, 'shots': 1000}, } qiskit_aqua = QiskitAqua(params_no_caching, self.algo_input) res[backend] = qiskit_aqua.run() self.reference_vqe_result = res
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 = Operator.load_from_dict(pauli_dict) self.algo_input = EnergyInput(qubit_op)
def getPauliMatrix(matrix): rows = matrix.shape[0] paulis = [] for row_pos in range(rows): for col_pos in range(matrix.shape[1]): temp = {} temp["imag"] = 0.0 temp["real"] = matrix[row_pos, col_pos] label_pauli = ["I" for _ in range(rows)] if row_pos != col_pos: label_pauli[row_pos] = 'Z' label_pauli[col_pos] = 'Z' label_pauli = "".join(label_pauli) paulis.append({"coeff": temp, "label": label_pauli}) paulis_dict = {"paulis": paulis} for i in paulis_dict["paulis"]: print(i) pauli_matrix = Operator.load_from_dict(paulis_dict) return pauli_matrix
"label": "ZI" }, { "coeff": { "imag": 0.0, "real": -0.01128010425623538 }, "label": "ZZ" }, { "coeff": { "imag": 0.0, "real": 0.18093119978423156 }, "label": "XX" }] } qubitOp_h2_with_2_qubit_reduction = Operator.load_from_dict(pauli_dict) class TestIQPE(QiskitAquaTestCase): """IQPE tests.""" @parameterized.expand([ [qubitOp_simple, 'qasm_simulator'], [qubitOp_h2_with_2_qubit_reduction, 'statevector_simulator'], ]) def test_iqpe(self, qubitOp, simulator): self.algorithm = 'IQPE' self.log.debug('Testing IQPE') self.qubitOp = qubitOp exact_eigensolver = ExactEigensolver(self.qubitOp, k=1)
# Here an Operator instance is created for our Hamiltonian. In this case the paulis are from a previously computed Hamiltonian for simplicity pauli_dict = { 'paulis': [ { "coeff": { "imag": 0.0, "real": 1 }, "label": "Z" }, ] } qubitOp = Operator.load_from_dict(pauli_dict) print(qubitOp) algorithm_cfg = {'name': 'VQE', 'operator_mode': 'matrix'} optimizer_cfg = {'name': 'L_BFGS_B', 'maxfun': 1000} var_form_cfg = {'name': 'RYRZ', 'depth': 3, 'entanglement': 'linear'} params = { 'algorithm': algorithm_cfg, 'optimizer': optimizer_cfg, 'variational_form': var_form_cfg, 'backend': { 'name': 'statevector_simulator' }