HRSModMultiplier
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.Carry ¶
Bases: CompositeGate
Construct a module called 'Carry' which is part of Toffoli based modular multiplier used to factor. This module compute the overflow of \(a(\text{quantum})+c(\text{classical})\) with borrowed ancilla qubits called 'g'. it's worth noting that at most 2 control qubits can be used in this module.
Note
If the number of control qubits is 2 and the quantum register size of \(a\) is 1, then the module will do:
$$ \vert{0}\rangle_1 \vert{\text{ctrls}}\rangle_2 \vert{a}\rangle_1 \vert{g}\rangle_1 \to \vert{\text{overflow}}\rangle_1 \vert{\text{ctrls}}\rangle_2 \vert{a}\rangle_1 \vert{g}\rangle_1 $$
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Parameters:
-
qreg_a(int) –The quantum register size for the quantum addend.
-
n_control(int) –The number of control qubits, which ranges from 0 to 2.
-
val_c(int) –The value of the classical addend.
-
name(str, default:None) –The name of this module. Defaults to None.
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.Incrementer ¶
Bases: CompositeGate
Construct a module called 'Incrementer' which is part of Toffoli based modular multiplier used to factor.
References
[1]: Craig Gidney. StackExchange: Creating bigger controlled nots from single qubit, Toffoli, and CNOT gates, without workspace. 2015. http://cs.stackexchange.com/questions/40933/.
Parameters:
-
qreg_size(int) –The quantum register size for the operator 'v'.
-
ctrl(bool, default:False) –whether this incrementer have control qubit. Defaults to False.
-
name(str, default:None) –The name of this module. Defaults to None.
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.RecAdder ¶
Bases: CompositeGate
The recursively applied partial-circuit in HRSAdder.The order of input is different from Fig.5 in the reference.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
qreg_size (int): The quantum register size for the quantum addend. val_c (int): The value of the classical addend. ctrl (bool): Whether this module have control qubit. Defaults to False. name (str): The name of this module. Defaults to None.
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.CtrlHRSSubtractor ¶
Bases: CompositeGate
Compute x(quantum) - c(classical) with borrowed qubits with 1-controlled.
Constructed on the basis of CtrlHRSAdder with complement technique.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Parameters:
-
qreg_size(int) –The quantum register size for the minus.
-
val_c(int) –The value of the classical minus.
-
name(str, default:'CtrlHRSSubtractor') –The name of this module. Defaults to "CtrlHRSSubtractor".
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.HRSCompare ¶
Bases: CompositeGate
Compare x(quantum) and c(classical) with borrowed qubits with at most 2-controlled. The Indicator toggles if c > x, not if c <= x.
Constructed on the basis of Carry.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Parameters:
-
qreg_size(int) –The quantum register size for the quantum number.
-
n_control(int) –The number of control qubits, which ranges from 0 to 2.
-
val_c(int) –The value of the classical number.
-
name(str, default:'HRSCompare') –The name of this module. Defaults to None.
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.HRSAdder ¶
Bases: CompositeGate
Compute x(quantum) + c(classical) with borrowed qubits without controlled.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Parameters:
-
qreg_size(int) –The quantum register size for the addend.
-
val_c(int) –The value of the classical addend.
-
name(str, default:'HRSAdder') –The name of this module. Defaults to "HRSAdder".
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.CtrlHRSAdder ¶
Bases: CompositeGate
Compute x(quantum) + c(classical) with borrowed qubits with 1-controlled.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Parameters:
-
qreg_size(int) –The quantum register size for the addend.
-
val_c(int) –The value of the classical addend.
-
name(str, default:'CtrlHRSAdder') –The name of this module. Defaults to "CtrlHRSAdder".
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.HRSAdderMod ¶
HRSAdderMod(qreg_size: int, val_a: int, val_n: int, n_control: int = 0, reverse: bool = False, name: str = 'HRSAdderMod')
Bases: CompositeGate
Compute b(quantum) + a(classical) mod N(classical), with n-1 dirty ancilla qubits g and one clean ancilla qubit indicator. The controlled qubits number of this adder is range from 0 to 2.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Note
[1]: Note that this circuit works only when n > 2. So for smaller numbers, use another design. [2]: If you want to recover dirty ancilla qubits, b and a must be smaller than N.
Parameters:
-
qreg_size(int) –The quantum register size for the addend.
-
val_a(int) –The value of the classical addend.
-
val_n(int) –The value of the classical modulus.
-
n_control(int, default:0) –The number of control qubits, which ranges from 0 to 2. Defaults to 0.
-
reverse(bool, default:False) –Whether reverse the circuit of this adder.
-
name(str, default:'HRSAdderMod') –The name of this module. Defaults to "HRSAdderMod".
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.HRSMulModRaw ¶
HRSMulModRaw(qreg_size: int, val_a: int, val_n: int, ctrl: bool = False, reverse: bool = False, name: str = 'HRSMulModRaw')
Bases: CompositeGate
Compute b(quantum) + x(quantum) * a(classical) mod N(classical), with one clean ancilla qubit indicator. The controlled qubits number of this module is range from 0 to 1.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Note
[1]: Note that this circuit works only when n > 2. So for smaller numbers, use another design.
Parameters:
-
qreg_size(int) –The quantum register size for the multiplicand.
-
val_a(int) –The value of the classical multiplicand.
-
val_n(int) –The value of the classical modulus.
-
ctrl(int, default:False) –Whether this module have control qubits. Defaults to False.
-
reverse(bool, default:False) –Whether reverse the circuit of this module.
-
name(str, default:'HRSMulModRaw') –The name of this module. Defaults to "HRSMulModRaw".
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.HRSMulMod ¶
Bases: CompositeGate
Compute x(quantum) * a(classical) mod N(classical), with n dirty ancilla qubits g and one clean ancilla qubit indicator. The controlled qubits number of this module is range from 0 to 1.
References
[1]: "Factoring using 2n+2 qubits with Toffoli based modular multiplication" by Thomas Häner, Martin Roetteler and Krysta M. Svorehttps://arxiv.org/abs/1611.07995.
Note
[1]: Note that this circuit works only when n > 2. So for smaller numbers, use another design.
Parameters:
-
qreg_size(int) –The quantum register size for the multiplicand.
-
val_a(int) –The value of the classical multiplicand.
-
val_n(int) –The value of the classical modulus.
-
ctrl(int, default:False) –Whether this module have control qubits. Defaults to False.
-
name(str, default:'HRSMulMod') –The name of this module. Defaults to "HRSMulMod".
Source code in QuICT/algorithm/arithmetic/multiplier/hrs_mod_multiplier.py
QuICT.algorithm.arithmetic.multiplier.hrs_mod_multiplier.CHRSMulMod ¶
Bases: CompositeGate
Controlled modular multiplication
For reg_size is n:
|control>|x>{n}|0> --> |control>|a*x mod N>{n}|0> , control == 1 |control>|x>{n}|0> --> |control>|x>{n}|0> , control == 0
Construct the modular multiplication gate
Parameters:
-
qreg_size(int) –size of the register to hold the result of the modular multiplication.
-
multiple(int) –the multiple in the modular multiplication.
-
modulus(int) –the modulus in the modular multiplication.
-
name(str, default:None) –name of the gate.