def from_params(self, params): if EnergyInput.PROP_KEY_QUBITOP not in params: raise AlgorithmError("Qubit operator is required.") qparams = params[EnergyInput.PROP_KEY_QUBITOP] self._qubit_op = Operator.load_from_dict(qparams) if EnergyInput.PROP_KEY_AUXOPS in params: auxparams = params[EnergyInput.PROP_KEY_AUXOPS] self._aux_ops = [Operator.load_from_dict(auxparams[i]) for i in range(len(auxparams))]
def setUp(self): np.random.seed(50) 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" }] } qubitOp = Operator.load_from_dict(pauli_dict) self.algo_input = get_input_instance('EnergyInput') self.algo_input.qubit_op = qubitOp
"label": "IZ" }, { "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(QISKitAcquaTestCase): """QPE tests.""" @parameterized.expand([ [qubitOp_h2_with_2_qubit_reduction], ]) def test_qpe(self, qubitOp): self.algorithm = 'QPE' self.log.debug('Testing QPE') self.qubitOp = qubitOp exact_eigensolver = get_algorithm_instance('ExactEigensolver') exact_eigensolver.init_args(self.qubitOp, k=1)
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================= from qiskit_acqua import Operator, run_algorithm from qiskit_acqua.input import get_input_instance 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": "ZZ"}, {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"} ] } algo_input = get_input_instance('EnergyInput') algo_input.qubit_op = Operator.load_from_dict(pauli_dict) params = { 'algorithm': {'name': 'VQE'}, 'optimizer': {'name': 'SPSA'}, 'variational_form': {'name': 'RY', 'depth': 5}, 'backend': {'name': 'local_qasm_simulator'} } result = run_algorithm(params, algo_input) print(result['energy'])