mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 09:10:16 +00:00
Fix errors in Quantum algorithm (#3273)
* Fix pre-commit errors in Quantum algorithm * updating DIRECTORY.md * Fix doctest * Update not_gate.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
34d63d5155
commit
23ab159f30
|
@ -684,6 +684,7 @@
|
||||||
* [Validate Solutions](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py)
|
* [Validate Solutions](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py)
|
||||||
|
|
||||||
## Quantum
|
## Quantum
|
||||||
|
* [Not Gate](https://github.com/TheAlgorithms/Python/blob/master/quantum/not_gate.py)
|
||||||
* [Single Qubit Measure](https://github.com/TheAlgorithms/Python/blob/master/quantum/single_qubit_measure.py)
|
* [Single Qubit Measure](https://github.com/TheAlgorithms/Python/blob/master/quantum/single_qubit_measure.py)
|
||||||
|
|
||||||
## Scheduling
|
## Scheduling
|
||||||
|
|
|
@ -11,11 +11,13 @@ import qiskit as q
|
||||||
|
|
||||||
def single_qubit_measure(qubits: int, classical_bits: int) -> q.result.counts.Counts:
|
def single_qubit_measure(qubits: int, classical_bits: int) -> q.result.counts.Counts:
|
||||||
"""
|
"""
|
||||||
>>> single_qubit_measure(1, 1)
|
>>> single_qubit_measure(2, 2)
|
||||||
{'11': 1000}
|
{'11': 1000}
|
||||||
|
>>> single_qubit_measure(4, 4)
|
||||||
|
{'0011': 1000}
|
||||||
"""
|
"""
|
||||||
# Use Aer's qasm_simulator
|
# Use Aer's qasm_simulator
|
||||||
simulator = q.Aer.get_backend('qasm_simulator')
|
simulator = q.Aer.get_backend("qasm_simulator")
|
||||||
|
|
||||||
# Create a Quantum Circuit acting on the q register
|
# Create a Quantum Circuit acting on the q register
|
||||||
circuit = q.QuantumCircuit(qubits, classical_bits)
|
circuit = q.QuantumCircuit(qubits, classical_bits)
|
||||||
|
@ -34,6 +36,6 @@ def single_qubit_measure(qubits: int, classical_bits: int) -> q.result.counts.Co
|
||||||
return job.result().get_counts(circuit)
|
return job.result().get_counts(circuit)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
counts = single_qubit_measure(2, 2)
|
counts = single_qubit_measure(2, 2)
|
||||||
print(f'Total count for various states are: {counts}')
|
print(f"Total count for various states are: {counts}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user