Reference: Gidney Arithmetic Qubricks¶
Contents¶
- AddBase
- GidneyAdd
- NaiveAdd
- ConditionallyCleanAdd
- CuccaroAdd
- CuccaroDepthOptimisedAdd
- Square
- GidneySquare
- NaiveSquare
- MultiplyAdd
- GidneyMultiplyAdd
- NaiveMultiplyAdd
- CuccaroMultiplyAdd
- OptimizedGidneyMultiplyAdd
- OptimizedNaiveMultiplyAdd
- GidneyLadder
AddBase ¶
AddBase(add_engine=gidney_add_engine, expand_dest_qreg: bool = False, release_ancillae: bool = True, **kwargs)
Bases: Qubrick
Basic boilerplate for adder.
compute ¶
compute(lhs: QType, rhs: QType, ctrl: Qubits | None = None, *, carry_in: bool = None, subtract_condition: bool = False, alloc_result: bool = False, release_ancillae: bool = None, condition: bool = None)
This computes (lhs += rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
rhs
|
Qubits or int
|
Right-hand operand |
required |
ctrl
|
Qubits
|
Quantum condition |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
alloc_result
|
bool
|
If True, compute into a new register |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
None
|
carry_in
|
Qubits or int or None
|
Additional value to add, if any |
None
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
GidneyAdd ¶
Bases: AddBase
Wrapper for Gidney Add.
compute ¶
compute(lhs: QType, rhs: QType, ctrl: Qubits | None = None, *, carry_in: bool = None, subtract_condition: bool = False, alloc_result: bool = False, release_ancillae: bool = None, condition: bool = None)
This computes (lhs += rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
rhs
|
Qubits or int
|
Right-hand operand |
required |
ctrl
|
Qubits
|
Quantum condition |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
alloc_result
|
bool
|
If True, compute into a new register |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
None
|
carry_in
|
Qubits or int or None
|
Additional value to add, if any |
None
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
NaiveAdd ¶
Bases: AddBase
Wrapper for Naive Add.
compute ¶
compute(lhs: QType, rhs: QType, ctrl: Qubits | None = None, *, carry_in: bool = None, subtract_condition: bool = False, alloc_result: bool = False, release_ancillae: bool = None, condition: bool = None)
This computes (lhs += rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
rhs
|
Qubits or int
|
Right-hand operand |
required |
ctrl
|
Qubits
|
Quantum condition |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
alloc_result
|
bool
|
If True, compute into a new register |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
None
|
carry_in
|
Qubits or int or None
|
Additional value to add, if any |
None
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
CuccaroAdd ¶
Bases: AddBase
Wrapper for Cuccaro Add.
compute ¶
compute(lhs: QType, rhs: QType, ctrl: Qubits | None = None, *, carry_in: bool = None, subtract_condition: bool = False, alloc_result: bool = False, release_ancillae: bool = None, condition: bool = None)
This computes (lhs += rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
rhs
|
Qubits or int
|
Right-hand operand |
required |
ctrl
|
Qubits
|
Quantum condition |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
alloc_result
|
bool
|
If True, compute into a new register |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
None
|
carry_in
|
Qubits or int or None
|
Additional value to add, if any |
None
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
ConditionallyCleanAdd ¶
Bases: AddBase
Wrapper for Conditionally Clean Add.
compute ¶
compute(lhs: QType, rhs: QType, ctrl: Qubits | None = None, *, carry_in: bool = None, subtract_condition: bool = False, alloc_result: bool = False, release_ancillae: bool = None, condition: bool = None)
This computes (lhs += rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
rhs
|
Qubits or int
|
Right-hand operand |
required |
ctrl
|
Qubits
|
Quantum condition |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
alloc_result
|
bool
|
If True, compute into a new register |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
None
|
carry_in
|
Qubits or int or None
|
Additional value to add, if any |
None
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
CuccaroDepthOptimisedAdd ¶
Bases: AddBase
Wrapper for Cuccaro Depth Optimised Add.
compute ¶
compute(lhs: QType, rhs: QType, ctrl: Qubits | None = None, *, carry_in: bool = None, subtract_condition: bool = False, alloc_result: bool = False, release_ancillae: bool = None, condition: bool = None)
This computes (lhs += rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
rhs
|
Qubits or int
|
Right-hand operand |
required |
ctrl
|
Qubits
|
Quantum condition |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
alloc_result
|
bool
|
If True, compute into a new register |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
None
|
carry_in
|
Qubits or int or None
|
Additional value to add, if any |
None
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
Square ¶
Square(add_engine=gidney_add_engine, square_engine=square_engine, allow_negative_input=None, **kwargs)
Bases: Qubrick
Basic Gidney square.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow_negative_input
|
bool or None
|
Set to allow negative input values. If None, decide based on input params. |
None
|
compute ¶
compute(lhs, ctrl=None, dst=None, alloc_result=None, add_to_dest=None, release_ancillae: bool = True, condition=None) -> None
This computes (lhs * lhs) into a new register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
ctrl
|
Qubits
|
Quantum ctrl |
None
|
dst
|
Qubits or None
|
If provided, ADD result into this reg |
None
|
alloc_result
|
None
|
Deprecated and will be removed in WB 5.0.0. To allocate a new result, pass None as dst. |
None
|
add_to_dest
|
None
|
If False or dst=None, just compute square assuming dst is zero. Otherwise, add to dst |
None
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
GidneySquare ¶
Bases: Square
Wrapper for Gidney Square.
compute ¶
compute(lhs, ctrl=None, dst=None, alloc_result=None, add_to_dest=None, release_ancillae: bool = True, condition=None) -> None
This computes (lhs * lhs) into a new register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
ctrl
|
Qubits
|
Quantum ctrl |
None
|
dst
|
Qubits or None
|
If provided, ADD result into this reg |
None
|
alloc_result
|
None
|
Deprecated and will be removed in WB 5.0.0. To allocate a new result, pass None as dst. |
None
|
add_to_dest
|
None
|
If False or dst=None, just compute square assuming dst is zero. Otherwise, add to dst |
None
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
NaiveSquare ¶
Bases: Square
Wrapper for Naive Square.
compute ¶
compute(lhs, ctrl=None, dst=None, alloc_result=None, add_to_dest=None, release_ancillae: bool = True, condition=None) -> None
This computes (lhs * lhs) into a new register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Qubits
|
Left-hand operand and destination |
required |
ctrl
|
Qubits
|
Quantum ctrl |
None
|
dst
|
Qubits or None
|
If provided, ADD result into this reg |
None
|
alloc_result
|
None
|
Deprecated and will be removed in WB 5.0.0. To allocate a new result, pass None as dst. |
None
|
add_to_dest
|
None
|
If False or dst=None, just compute square assuming dst is zero. Otherwise, add to dst |
None
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
MultiplyAdd ¶
MultiplyAdd(add_engine=gidney_add_engine, mul_engine=naive_mul_engine, allow_negative_input=None, **kwargs)
Bases: Qubrick
Basic Gidney Multiply-Add.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow_negative_input
|
bool or None
|
Set to allow negative input values. If None, decide based on input params. |
None
|
compute ¶
compute(dst, lhs, rhs, ctrl=None, release_ancillae: bool = True, condition=None, subtract_condition: bool = False)
This computes dst + (lhs * rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Qubits or None
|
Destination to add into. If None, allocate a new register |
required |
lhs
|
Qubits
|
Left-hand multiply operand |
required |
rhs
|
Qubits
|
Right-hand multiply operand |
required |
ctrl
|
Qubits
|
Quantum control |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
GidneyMultiplyAdd ¶
Bases: MultiplyAdd
Wrapper for Gidney Multiply-Add.
compute ¶
compute(dst, lhs, rhs, ctrl=None, release_ancillae: bool = True, condition=None, subtract_condition: bool = False)
This computes dst + (lhs * rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Qubits or None
|
Destination to add into. If None, allocate a new register |
required |
lhs
|
Qubits
|
Left-hand multiply operand |
required |
rhs
|
Qubits
|
Right-hand multiply operand |
required |
ctrl
|
Qubits
|
Quantum control |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
NaiveMultiplyAdd ¶
Bases: MultiplyAdd
Wrapper for Naive Multiply-Add.
compute ¶
compute(dst, lhs, rhs, ctrl=None, release_ancillae: bool = True, condition=None, subtract_condition: bool = False)
This computes dst + (lhs * rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Qubits or None
|
Destination to add into. If None, allocate a new register |
required |
lhs
|
Qubits
|
Left-hand multiply operand |
required |
rhs
|
Qubits
|
Right-hand multiply operand |
required |
ctrl
|
Qubits
|
Quantum control |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
CuccaroMultiplyAdd ¶
Bases: MultiplyAdd
Wrapper for Cuccaro Multiply-Add.
compute ¶
compute(dst, lhs, rhs, ctrl=None, release_ancillae: bool = True, condition=None, subtract_condition: bool = False)
This computes dst + (lhs * rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Qubits or None
|
Destination to add into. If None, allocate a new register |
required |
lhs
|
Qubits
|
Left-hand multiply operand |
required |
rhs
|
Qubits
|
Right-hand multiply operand |
required |
ctrl
|
Qubits
|
Quantum control |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
OptimizedGidneyMultiplyAdd ¶
Bases: MultiplyAdd
Wrapper for Gidney Multiply-Add.
compute ¶
compute(dst, lhs, rhs, ctrl=None, release_ancillae: bool = True, condition=None, subtract_condition: bool = False)
This computes dst + (lhs * rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Qubits or None
|
Destination to add into. If None, allocate a new register |
required |
lhs
|
Qubits
|
Left-hand multiply operand |
required |
rhs
|
Qubits
|
Right-hand multiply operand |
required |
ctrl
|
Qubits
|
Quantum control |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.
OptimizedNaiveMultiplyAdd ¶
Bases: MultiplyAdd
Wrapper for Naive Multiply-Add.
compute ¶
compute(dst, lhs, rhs, ctrl=None, release_ancillae: bool = True, condition=None, subtract_condition: bool = False)
This computes dst + (lhs * rhs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Qubits or None
|
Destination to add into. If None, allocate a new register |
required |
lhs
|
Qubits
|
Left-hand multiply operand |
required |
rhs
|
Qubits
|
Right-hand multiply operand |
required |
ctrl
|
Qubits
|
Quantum control |
None
|
subtract_condition
|
Qubits or bool
|
If True (classically or quantumly), subtract instead of adding |
False
|
release_ancillae
|
bool
|
If True, uncompute and release auxiliary qubits. If False, hold auxiliary qubits till uncompute. |
True
|
Notes
release_ancillae allows us to trade off Toffoli cost vs. qubit cost:
- If True, then the ONLY effect remaining after compute() is the desired sum.
- If False, it uses fewer gates but rhs and the auxiliary qubits will be scrambled until uncompute.