Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Apr 17, 2023
1 parent 374209c commit e9e6a4f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
4 changes: 1 addition & 3 deletions test/python/algorithms/test_observables_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def _run_test(
observables: ListOrDict[BaseOperator | PauliSumOp],
estimator: Estimator,
):
result = estimate_observables(
estimator, quantum_state, observables, None, self.threshold
)
result = estimate_observables(estimator, quantum_state, observables, None, self.threshold)

if isinstance(observables, dict):
np.testing.assert_equal(list(result.keys()), list(expected_result.keys()))
Expand Down
1 change: 0 additions & 1 deletion test/python/circuit/library/test_evolved_op_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_evolved_op_ansatz(self, use_opflow):
evo = EvolvedOperatorAnsatz(ops, 2)
parameters = evo.parameters


else:
ops = [Pauli("Z" * num_qubits), Pauli("Y" * num_qubits), Pauli("X" * num_qubits)]
evo = EvolvedOperatorAnsatz(ops, 2)
Expand Down
1 change: 0 additions & 1 deletion test/python/opflow/test_expectation_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ def test_aer_simulator_pauli_sum(self):
with self.subTest("Include custom"):
expectation = ExpectationFactory.build(op, backend, include_custom=True)
self.assertIsInstance(expectation, AerPauliExpectation)
16 changes: 9 additions & 7 deletions test/python/opflow/test_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,9 @@ def grad_combo_fn(x):
qc = RealAmplitudes(2, reps=1)

with self.assertWarns(DeprecationWarning):
grad_op = ListOp([StateFn(qc.decompose())], combo_fn=combo_fn, grad_combo_fn=grad_combo_fn)
grad_op = ListOp(
[StateFn(qc.decompose())], combo_fn=combo_fn, grad_combo_fn=grad_combo_fn
)
grad = Gradient(grad_method=method).convert(grad_op)

value_dict = dict(zip(qc.ordered_parameters, np.random.rand(len(qc.ordered_parameters))))
Expand Down Expand Up @@ -1152,13 +1154,13 @@ def test_gradient_wrapper(self, backend_type):
with self.assertWarns(DeprecationWarning):
if method == "fin_diff":
np.random.seed(8)
prob_grad = Gradient(grad_method=method, epsilon=shots ** (-1 / 6.0)).gradient_wrapper(
prob_grad = Gradient(
grad_method=method, epsilon=shots ** (-1 / 6.0)
).gradient_wrapper(operator=op, bind_params=params, backend=q_instance)
else:
prob_grad = Gradient(grad_method=method).gradient_wrapper(
operator=op, bind_params=params, backend=q_instance
)
else:
prob_grad = Gradient(grad_method=method).gradient_wrapper(
operator=op, bind_params=params, backend=q_instance
)

values = [[np.pi / 4, 0], [np.pi / 4, np.pi / 4], [np.pi / 2, np.pi]]
correct_values = [
Expand Down Expand Up @@ -1535,7 +1537,7 @@ def test_overlap_qfi_raises_on_multiparam(self):

with self.assertRaises(NotImplementedError):
with self.assertWarns(DeprecationWarning):
_ = QFI("overlap_diag").convert(StateFn(circuit), [x])
_ = QFI("overlap_diag").convert(StateFn(circuit), [x])

def test_overlap_qfi_raises_on_unsupported_gate(self):
"""Test the overlap QFI raises an appropriate error on multi-param unbound gates."""
Expand Down
8 changes: 6 additions & 2 deletions test/python/opflow/test_matrix_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ def test_pauli_expect_op_vector_state_vector(self):

valids = [[+0, 0, 1, -1], [+0, 0, 0, 0], [-1, 1, 0, -0], [+1, 1, 1, 1]]
converted_meas = self.expect.convert(~StateFn(paulis_op))
np.testing.assert_array_almost_equal((converted_meas @ states_op).eval(), valids, decimal=1)
np.testing.assert_array_almost_equal(
(converted_meas @ states_op).eval(), valids, decimal=1
)

sampled = self.sampler.convert(states_op)
np.testing.assert_array_almost_equal((converted_meas @ sampled).eval(), valids, decimal=1)
np.testing.assert_array_almost_equal(
(converted_meas @ sampled).eval(), valids, decimal=1
)

def test_multi_representation_ops(self):
"""Test observables with mixed representations"""
Expand Down
4 changes: 3 additions & 1 deletion test/python/opflow/test_pauli_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ def test_grouped_pauli_expectation(self):
num_circuits_ungrouped = len(self.sampler._circuit_ops_cache)
self.assertEqual(num_circuits_ungrouped, 5)

expect_op_grouped = PauliExpectation(group_paulis=True).convert(~StateFn(two_qubit_H2) @ wf)
expect_op_grouped = PauliExpectation(group_paulis=True).convert(
~StateFn(two_qubit_H2) @ wf
)

q_instance = QuantumInstance(
BasicAer.get_backend("statevector_simulator"),
Expand Down

0 comments on commit e9e6a4f

Please sign in to comment.