ansatz#
Ansatze: various quantum circuits
Classes
|
A base class for Ansatz. |
|
Controlled multiplier. |
|
Controlled Ua gate. |
|
A quantum circuit for the HHL algorithm. |
|
Convert number to corresponding encoding circuit. |
|
Phi adder. |
|
Phi modular adder. |
|
Quantum convolutional neural network. |
|
Quantum Fourier transform. |
|
Quantum phase estimation for arbitrary unitary operator. |
|
Quantum phase estimation for single-qubit gate. |
|
Random circuit of G3 family. |
|
Circuit for Shor's algorithm. |
|
Circuit for Shor's algorithm to factor number 15. |
- class Ansatz(nqubit: int, wires: int | list[int] | None = None, minmax: list[int] | None = None, ancilla: int | list[int] | None = None, controls: int | list[int] | None = None, init_state: Any = 'zeros', name: str | None = None, den_mat: bool = False, reupload: bool = False, mps: bool = False, chi: int | None = None)[source]#
Bases:
QubitCircuitA base class for Ansatz.
- Parameters:
nqubit (int) – The number of qubits in the circuit.
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneminmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Only valid when
wiresisNone. Default:Noneancilla (int | list[int] | None) – The indices of the ancilla qubits. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Noneinit_state (Any) – The initial state of the circuit. Default:
'zeros'name (str | None) – The name of the circuit. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsereupload (bool) – Whether to use data re-uploading. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
None
- class ControlledMultiplier(nqubit: int, a: int, mod: int, minmax: list[int] | None = None, nqubitx: int | None = None, ancilla: int | list[int] | None = None, controls: int | list[int] | None = None, den_mat: bool = False, mps: bool = False, chi: int | None = None, debug: bool = False)[source]#
Bases:
AnsatzControlled multiplier.
See https://arxiv.org/pdf/quant-ph/0205095.pdf Fig.6
- Parameters:
nqubit (int) – The number of qubits in the circuit.
a (int) – Number
ain \(b+a*x \mod N\).mod (int) – The modulus in \(b+a*x \mod N\).
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Noneancilla (int | list[int] | None) – The indices of the ancilla qubits. Default:
Nonenqubitx (int | None) – The number of qubits in the register x.
controls (int | list[int] | None) – The indices of the control qubits. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Nonedebug (bool) – Whether to print the debug information. Default:
False
- class ControlledUa(nqubit: int, a: int, mod: int, minmax: list[int] | None = None, ancilla: int | list[int] | None = None, controls: int | list[int] | None = None, den_mat: bool = False, mps: bool = False, chi: int | None = None, debug: bool = False)[source]#
Bases:
AnsatzControlled Ua gate.
ahas a modular inverse only ifais coprime tomod. See https://arxiv.org/pdf/quant-ph/0205095.pdf Fig.7- Parameters:
nqubit (int) – The number of qubits in the circuit.
a (int) – Number
ain \(a*x \mod N\).mod (int) – The modulus in \(a*x \mod N\).
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Noneancilla (int | list[int] | None) – The indices of the ancilla qubits. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Nonedebug (bool) – Whether to print the debug information. Default:
False
- class HHL(ncount: int, mat: Any, t0: float = 1, den_mat: bool = False, mps: bool = False, chi: int | None = None, show_barrier: bool = False)[source]#
Bases:
AnsatzA quantum circuit for the HHL algorithm.
- Parameters:
ncount (int) – The number of counting qubits.
mat (Any) – The Hermitian matrix A.
t0 (float) – The time parameter for the matrix exponential in units of \(2\pi\). Default: 1
den_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Noneshow_barrier (bool) – Whether to show the barriers in the circuit. Default:
False
- class NumberEncoder(nqubit: int, number: int, minmax: list[int] | None = None, den_mat: bool = False, mps: bool = False, chi: int | None = None)[source]#
Bases:
AnsatzConvert number to corresponding encoding circuit.
- Parameters:
nqubit (int) – The number of qubits in the circuit.
number (int) – The integer for converting to bit string.
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
None
- class PhiAdder(nqubit: int, number: int, minmax: list[int] | None = None, controls: int | list[int] | None = None, den_mat: bool = False, mps: bool = False, chi: int | None = None, debug: bool = False)[source]#
Bases:
AnsatzPhi adder.
See https://arxiv.org/pdf/quant-ph/0205095.pdf Fig.2 and Fig.3
- Parameters:
nqubit (int) – The number of qubits in the circuit.
number (int) – Number
ain \(\Phi(a+b)\).minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Nonedebug (bool) – Whether to print the debug information. Default:
False
- class PhiModularAdder(nqubit: int, number: int, mod: int, minmax: list[int] | None = None, ancilla: int | list[int] | None = None, controls: int | list[int] | None = None, den_mat: bool = False, mps: bool = False, chi: int | None = None, debug: bool = False)[source]#
Bases:
AnsatzPhi modular adder.
See https://arxiv.org/pdf/quant-ph/0205095.pdf Fig.5
- Parameters:
nqubit (int) – The number of qubits in the circuit.
number (int) – Number
ain \(\Phi(a+b \mod N)\).mod (int) – The modulus in \(\Phi(a+b \mod N)\).
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Noneancilla (int | list[int] | None) – The indices of the ancilla qubits. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Nonedebug (bool) – Whether to print the debug information. Default:
False
- class QuantumConvolutionalNeuralNetwork(nqubit: int, nlayer: int, minmax: list[int] | None = None, init_state: Any = 'zeros', den_mat: bool = False, requires_grad: bool = True, mps: bool = False, chi: int | None = None)[source]#
Bases:
AnsatzQuantum convolutional neural network.
See https://readpaper.com/paper/4554418257818296321 Fig.1 or https://pennylane.ai/qml/demos/tutorial_learning_few_data
- Parameters:
nqubit (int) – The number of qubits in the circuit.
nlayer (int) – The number of layers.
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Noneinit_state (Any) – The initial state of the circuit. Default:
'zeros'den_mat (bool) – Whether to use density matrix representation. Default:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:True(which meansnn.Parameter)mps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
None
- class QuantumFourierTransform(nqubit: int, minmax: list[int] | None = None, reverse: bool = False, init_state: Any = 'zeros', den_mat: bool = False, mps: bool = False, chi: int | None = None, show_barrier: bool = False)[source]#
Bases:
AnsatzQuantum Fourier transform.
- Parameters:
nqubit (int) – The number of qubits in the circuit.
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Nonereverse (bool) – Whether to reverse the output order. Default:
False(which means the default output order of phase is \(x/2, ..., x/2^n\). Ifreverse=True, the output order of phase is \(x/2^n, ..., x/2\))init_state (Any) – The initial state of the circuit. Default:
'zeros'den_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Noneshow_barrier (bool) – Whether to show the barriers in the circuit. Default:
False
- class QuantumPhaseEstimation(nqubit: int, ncount: int, unitary: Any, minmax: list[int] | None = None, den_mat: bool = False, mps: bool = False, chi: int | None = None, show_barrier: bool = False)[source]#
Bases:
AnsatzQuantum phase estimation for arbitrary unitary operator.
- Parameters:
nqubit (int) – The number of qubits in the circuit.
ncount (int) – The number of counting qubits.
unitary (Any) – The unitary operator.
minmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Noneshow_barrier (bool) – Whether to show the barriers in the circuit. Default:
False
- class QuantumPhaseEstimationSingleQubit(t: int, phase: Any, den_mat: bool = False, mps: bool = False, chi: int | None = None)[source]#
Bases:
AnsatzQuantum phase estimation for single-qubit gate.
- Parameters:
t (int) – The number of counting qubits.
phase (Any) – The phase to be estimated.
den_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
None
- class RandomCircuitG3(nqubit: int, ngate: int, wires: list[int] | None = None, minmax: list[int] | None = None, init_state: Any = 'zeros', den_mat: bool = False, mps: bool = False, chi: int | None = None)[source]#
Bases:
AnsatzRandom circuit of G3 family.
- Parameters:
nqubit (int) – The number of qubits in the circuit.
ngate (int) – The number of random gates in the circuit.
wires (list[int] | None) – The indices of the qubits that the random gates act on. Default:
Noneminmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Only valid when
wiresisNone. Default:Noneinit_state (Any) – The initial state of the circuit. Default:
'zeros'den_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
None
- class ShorCircuit(mod: int, ncount: int, a: int, den_mat: bool = False, mps: bool = False, chi: int | None = None, debug: bool = False)[source]#
Bases:
AnsatzCircuit for Shor’s algorithm.
- Parameters:
mod (int) – The odd integer to be factored.
ncount (int) – The number of counting qubits.
a (int) – Any integer that satisfies \(1 < a < N\) and \(\gcd(a, N) = 1\).
den_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Nonedebug (bool) – Whether to print the debug information. Default:
False
- class ShorCircuitFor15(ncount: int, a: int, den_mat: bool = False, mps: bool = False, chi: int | None = None)[source]#
Bases:
AnsatzCircuit for Shor’s algorithm to factor number 15.
See https://learn.qiskit.org/course/ch-algorithms/shors-algorithm
- Parameters:
ncount (int) – The number of counting qubits.
a (int) – Any integer that satisfies \(1 < a < N\) and \(\gcd(a, N) = 1\).
den_mat (bool) – Whether to use density matrix representation. Default:
Falsemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
None