Skip to content

Commit

Permalink
refactored and optimized code (#9292)
Browse files Browse the repository at this point in the history
* refactored and optimized code

* refactored code

* formatted the code

* undid changes
added comment explaining the deprecated logic

* reformatted using tox -e black

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jeevesh2002 and mergify[bot] authored Jan 11, 2023
1 parent 9e25f65 commit c29b273
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/python/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

# Desired vector
print("Desired probabilities: ")
print(str(list(map(lambda x: format(abs(x * x), ".3f"), desired_vector))))
print(list(map(lambda x: format(abs(x * x), ".3f"), desired_vector)))

# Initialize on local simulator
sim_backend = BasicAer.get_backend("qasm_simulator")
Expand All @@ -64,6 +64,6 @@

counts = result.get_counts(circuit)

qubit_strings = [format(i, "0%sb" % 4) for i in range(2**4)]
qubit_strings = [format(i, "04b") for i in range(2**4)]
print("Probabilities from simulator: ")
print([format(counts.get(s, 0) / shots, ".3f") for s in qubit_strings])
2 changes: 1 addition & 1 deletion qiskit/algorithms/amplitude_amplifiers/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def amplify(self, amplification_problem: AmplificationProblem) -> "GroverResult"
}
top_measurement, max_probability = max(circuit_results.items(), key=lambda x: x[1])

else:
else: # use of else brach instead of elif as this seperates out the deprecated logic
if self._quantum_instance.is_statevector:
qc = self.construct_circuit(amplification_problem, power, measurement=False)
circuit_results = self._quantum_instance.execute(qc).get_statevector()
Expand Down

0 comments on commit c29b273

Please sign in to comment.