Buenas!
Ayer comente como la operación MResetZ() nos permite obtener el estado de un Qubit y liberar al mismo. Pues bien, al final de cada operación los Qubits tienen que ser liberados para que el simulador funcione correctamente.
Nota: La palabra en inglés es Release, la traducción de “liberado” no me termina de gustar.
En un código como el siguiente, donde se utiliza un Qubit y no se libera correctamente, nos encontraremos con el siguiente error:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operation HGateWithOutReset (initial: Result) : (Result) | |
{ | |
body | |
{ | |
mutable res = Zero; | |
using (qubits = Qubit[2]) | |
{ | |
let qubit1 = qubits[0]; | |
let qubit2 = qubits[1]; | |
H(qubit1); | |
set res = M(qubit1); | |
} | |
return (res); | |
} | |
} |
Microsoft.Quantum.Simulation.Simulators.Exceptions.ReleasedQubitsAreNotInZeroState
HResult=0x80131500
Message=Released qubits are not in zero state.
Source=Microsoft.Quantum.Simulation.Simulators
Microsoft Quantum Development Kit nos ofrece una serie de operaciones que nos ayudan a liberar Qubits: Reset() y ResetAll(). Como su nombre lo indica Reset() esta pensado para liberar un único Qubit y ResetAll() para liberar un array de Qubits.
Dado un solo qubit, Reset() evalua su etado y se asegura que está en el estado |0⟩ tal que pueda ser liberado con seguridad
La siguientes 2 operaciones muestran ejemplos sobre como utilizar estas operaciones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operation HGateWithResetEachQubit (initial: Result) : (Result) | |
{ | |
body | |
{ | |
mutable res = Zero; | |
using (qubits = Qubit[2]) | |
{ | |
let qubit1 = qubits[0]; | |
let qubit2 = qubits[1]; | |
H(qubit1); | |
set res = M(qubit1); | |
Reset(qubit1); | |
Reset(qubit2); | |
} | |
return (res); | |
} | |
} | |
operation HGateWithResetAllQubits (initial: Result) : (Result) | |
{ | |
body | |
{ | |
mutable res = Zero; | |
using (qubits = Qubit[2]) | |
{ | |
let qubit1 = qubits[0]; | |
let qubit2 = qubits[1]; | |
H(qubit1); | |
set res = M(qubit1); | |
ResetAll(qubits); | |
} | |
return (res); | |
} | |
} |
Happy QCoding!
Saludos @ Toronto
El Bruno
References
- Microsoft Quantum Development Kit
- Q# Reference, M operation
- Q# Reference, H operation
- Q# Reference, MResetZ operation
- Q# Reference, Reset operation
- Q# Reference, ResetAll operation
My Posts
- El Bruno, Using MResetZ() to reset Qubits in Q#
- El Bruno, Qubit operations in Q#
- El Bruno, Information about Simulators on Microsoft Quantum Development Kit (Do you have 16 TB RAM?)
- El Bruno, Hello QWorld using Microsoft #Quantum Development Kit (fix to build the project) [Updated]
- El Bruno, More information about the Microsoft bet in Quantum Computing
- El Bruno, Quantum Computing, let’s add this one to Artificial Intelligence and Mixed Reality!