Example #1
0
 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)
Example #2
0
 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))
         ]
Example #3
0
 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": "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)
Example #4
0
        "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)
        },
        "label": "ZX"
    }, {
        "coeff": {
            "imag": 0.0,
            "real": 0.1115
        },
        "label": "ZZ"
    }]
}

# Create input variable that specifies we want the energy value
algo_input = get_input_instance("EnergyInput")

# Adds the Hamiltonian information to the input variable
algo_input.qubit_op = Operator.load_from_dict(pauli_dict)

# Defines the algorithm input in terms of the pauli dict and that we want the energy value
# Specifies the attributes of the algorithm that will be used to find the ground state energy
# algorithm: we will use the VQE
# optimiser: best choice for optimisation dependent on the simulated system
# variational_form: the ansatz or first guess at a solution
# depth: the complexity of the circuit used in the algorithm
# backend: the actual device the code will be run on
params = {
    "algorithm": {
        "name": "VQE"
    },
    "optimizer": {
        "name": "SPSA"
    },
Example #6
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 = 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'
                },
                'problem': {
                    'name': 'energy',
                    'random_seed': 50,
                    'circuit_caching': False,
                    'skip_qobj_deepcopy': False,
                    'skip_qobj_validation': False,
                    'circuit_cache_file': None,
                },
                'backend': {
                    'name': backend,
                    'shots': 1000
                },
            }
            res[backend] = run_algorithm(params_no_caching, self.algo_input)
        self.reference_vqe_result = res