yaf2q package
Subpackages
Submodules
yaf2q.f2q_mapper module
- class yaf2q.f2q_mapper.F2QMapper(kind: str | None = None, num_qubits: int = 0, ttspec: TernaryTreeSpec | None = None)
Bases:
objectFermion to qubit mapper
- kind
kind of the fermion to qubit mapper (jordan-wigner,parity,bravyi-kitaev)
- Type:
str
- num_qubits
number of qubits
- Type:
int
- ttspec
ternary tree specification
- Type:
- encoding_matrix
endoding matrix for the fermion to qubit mapper
- Type:
numpy.ndarray
- encoding_matrix_inv
inverse of the endoding matrix for the fermion to qubit mapper
- Type:
numpy.ndarray
- property encoding_matrix: ndarray
getter of the encoding_matrix
- property encoding_matrix_inv: ndarray
getter of the encoding_matrix_inv
- fermion_to_qubit_operator(fermion_operator: InteractionOperator, method: str = 'tt') QubitOperatorSet
Get the qubit operator from the fermion operator
- Parameters:
fermion_operator (InteractionOperator) – fermion operator
- Returns:
set of the qubit operators
- Return type:
- fock_to_qubit_state(fock_state: list[int]) list[int]
Get the qubit state from the fock state
- Parameters:
fock_state (list[int]) – fock state
- Returns:
qubit_state – qubit state
- Return type:
list[int]
- property kind: str
getter of the kind
- property num_qubits: int
getter of the num_qubits
- qubit_to_fock_state(qubit_state: list[int]) list[int]
Get the fock state from the qubit state
- Parameters:
qubit_state (list[int]) – qubit state
- Returns:
fock_state – fock state
- Return type:
list[int]
- to_string() str
Get the string of the F2QMapper
- Parameters:
None
- Returns:
string of the F2QMapper
- Return type:
str
- property ttspec: int
getter of the ttspec
yaf2q.qubit_operator_set module
- class yaf2q.qubit_operator_set.QubitOperatorSet(num_qubits: int = 0, openfermion_form: QubitOperator = None)
Bases:
objectSet of qubit operators
- num_qubits
number of qubits
- Type:
int
- openfermion_form
qubit operator in openfermion format
- Type:
QubitOperator
- qiskit_form
qubit operator in qiskit format
- Type:
SparsePauliOp
- pytket_form
qubit operator in pytket format
- Type:
QubitPauliOperator
- eigenvalues(num: int = 1) ndarray[float]
Get the eigen-values of QubitOperator
- Parameters:
num (int) – number of the eigen-values in order from smallest to largest
- Returns:
eigenvalues – list of eigenvalues
- Return type:
list[float]
- eigenvectors(num: int = 1) ndarray[ndarray[complex]]
Get the eigen-vectors of QubitOperator
- Parameters:
num (int) – number of the eigen-values in order from smallest to largest
- Returns:
eigenvectors – list of eigenvectors
- Return type:
np.ndarray
- eigsh(num: int = 1) tuple[ndarray, ndarray[ndarray]]
Get the eigen-values and eigen-vectors of QubitOperator
- Parameters:
num (int) – number of the eigen-values,eigen-vectors in order from smallest to largest
- Returns:
eigenvalues, eigenvectors – list of the eigenvalues
- Return type:
tuple[list,list]
- num_qubits: int = 0
- openfermion_form: QubitOperator = None
- pauli_weights() list[int]
Get the pauli weights of QubitOperator
- Parameters:
None
- Returns:
weights – pauli weights of QubitOperator
- Return type:
list[int]
Notes
If the qubit operator is 0.1*X[0]*Z[1]+0.2*X[1]*Y[2]*Z[3], then returned list is [2, 3].
- property pytket_form
getter of the pytket_form
- property qiskit_form
getter of the qiskit_form
- to_string() str
Get the string of QubitOperator
- Parameters:
None
- Returns:
string of the QubitOperator
- Return type:
str
yaf2q.ternary_tree_spec module
- class yaf2q.ternary_tree_spec.TernaryTreeSpec(indices: list[int] = [], edges: dict[int, int] = {})
Bases:
objectSpecification of ternary tree
- num_qubits
number of qubits
- Type:
int
- indices
node indices list
- Type:
list[int]
- edges
dictionary data with child node indices as keys, parent node indices and Pauli strings as values
- Type:
dict[int,tuple[int,str]]
- _parent_dict
dictionary data with child indices as keys, parent indices as values
- Type:
dict[int,int]
- _mask
list with a size three times the number of nodes in the graph, that the position corresponding to the value of the parent dict is 1 and the other positions are 0.
- Type:
list[int]
Notes
Child index is equal to the graph node index, parent index is 3 times the graph node index plus the Pauli operator index. Pauli operator index is defined as X=>0,Y=>1,Z=>2.
- change_parent() Self
get the TernaryTreeSpec that parent node corresponding to the child node has been changed randomly
- Parameters:
None
- Returns:
ttspec – TernaryTreeSpec that parent node corresponding to the child node has been changed randomly
- Return type:
- property edges: dict[int, int]
Get the edges of the TernaryTreeSpec
- Parameters:
None
Reterns
-------
edges (dict[int,tuple[int,str]]) – dictionary data with child node numbers as keys, parent node numbers and Pauli strings as values
- property indices: int
Get the indices
- is_valid() bool
check validity
- Parameters:
None
- Returns:
the TernaryTreeSpec is valid or not
- Return type:
bool
- property num_qubits: int
Get the number of qubits
- classmethod random(num_indices: int) Self
Get a TernaryTreeSpec randomly
- Parameters:
num_indices (int) – number of indices
- Returns:
ttspec – ternary tree specification
- Return type:
- show()
show the ternary tree
- Parameters:
None
- Return type:
None
- swap_indices() Self
get the TernaryTreeSpec that swapped two indices randomly
- Parameters:
None
- Returns:
ttspec – TernaryTreeSpec that swaped two indices randomly
- Return type:
- to_string() str
Get the string of TernaryTreeSpec
- Parameters:
None
- Returns:
s – string of the TernaryTreeSpec
- Return type:
str
Module contents
- class yaf2q.F2QMapper(kind: str | None = None, num_qubits: int = 0, ttspec: TernaryTreeSpec | None = None)
Bases:
objectFermion to qubit mapper
- kind
kind of the fermion to qubit mapper (jordan-wigner,parity,bravyi-kitaev)
- Type:
str
- num_qubits
number of qubits
- Type:
int
- ttspec
ternary tree specification
- Type:
- encoding_matrix
endoding matrix for the fermion to qubit mapper
- Type:
numpy.ndarray
- encoding_matrix_inv
inverse of the endoding matrix for the fermion to qubit mapper
- Type:
numpy.ndarray
- property encoding_matrix: ndarray
getter of the encoding_matrix
- property encoding_matrix_inv: ndarray
getter of the encoding_matrix_inv
- fermion_to_qubit_operator(fermion_operator: InteractionOperator, method: str = 'tt') QubitOperatorSet
Get the qubit operator from the fermion operator
- Parameters:
fermion_operator (InteractionOperator) – fermion operator
- Returns:
set of the qubit operators
- Return type:
- fock_to_qubit_state(fock_state: list[int]) list[int]
Get the qubit state from the fock state
- Parameters:
fock_state (list[int]) – fock state
- Returns:
qubit_state – qubit state
- Return type:
list[int]
- property kind: str
getter of the kind
- property num_qubits: int
getter of the num_qubits
- qubit_to_fock_state(qubit_state: list[int]) list[int]
Get the fock state from the qubit state
- Parameters:
qubit_state (list[int]) – qubit state
- Returns:
fock_state – fock state
- Return type:
list[int]
- to_string() str
Get the string of the F2QMapper
- Parameters:
None
- Returns:
string of the F2QMapper
- Return type:
str
- property ttspec: int
getter of the ttspec
- class yaf2q.QubitOperatorSet(num_qubits: int = 0, openfermion_form: QubitOperator = None)
Bases:
objectSet of qubit operators
- num_qubits
number of qubits
- Type:
int
- openfermion_form
qubit operator in openfermion format
- Type:
QubitOperator
- qiskit_form
qubit operator in qiskit format
- Type:
SparsePauliOp
- pytket_form
qubit operator in pytket format
- Type:
QubitPauliOperator
- eigenvalues(num: int = 1) ndarray[float]
Get the eigen-values of QubitOperator
- Parameters:
num (int) – number of the eigen-values in order from smallest to largest
- Returns:
eigenvalues – list of eigenvalues
- Return type:
list[float]
- eigenvectors(num: int = 1) ndarray[ndarray[complex]]
Get the eigen-vectors of QubitOperator
- Parameters:
num (int) – number of the eigen-values in order from smallest to largest
- Returns:
eigenvectors – list of eigenvectors
- Return type:
np.ndarray
- eigsh(num: int = 1) tuple[ndarray, ndarray[ndarray]]
Get the eigen-values and eigen-vectors of QubitOperator
- Parameters:
num (int) – number of the eigen-values,eigen-vectors in order from smallest to largest
- Returns:
eigenvalues, eigenvectors – list of the eigenvalues
- Return type:
tuple[list,list]
- num_qubits: int = 0
- openfermion_form: QubitOperator = None
- pauli_weights() list[int]
Get the pauli weights of QubitOperator
- Parameters:
None
- Returns:
weights – pauli weights of QubitOperator
- Return type:
list[int]
Notes
If the qubit operator is 0.1*X[0]*Z[1]+0.2*X[1]*Y[2]*Z[3], then returned list is [2, 3].
- property pytket_form
getter of the pytket_form
- property qiskit_form
getter of the qiskit_form
- to_string() str
Get the string of QubitOperator
- Parameters:
None
- Returns:
string of the QubitOperator
- Return type:
str
- class yaf2q.TernaryTreeSpec(indices: list[int] = [], edges: dict[int, int] = {})
Bases:
objectSpecification of ternary tree
- num_qubits
number of qubits
- Type:
int
- indices
node indices list
- Type:
list[int]
- edges
dictionary data with child node indices as keys, parent node indices and Pauli strings as values
- Type:
dict[int,tuple[int,str]]
- _parent_dict
dictionary data with child indices as keys, parent indices as values
- Type:
dict[int,int]
- _mask
list with a size three times the number of nodes in the graph, that the position corresponding to the value of the parent dict is 1 and the other positions are 0.
- Type:
list[int]
Notes
Child index is equal to the graph node index, parent index is 3 times the graph node index plus the Pauli operator index. Pauli operator index is defined as X=>0,Y=>1,Z=>2.
- change_parent() Self
get the TernaryTreeSpec that parent node corresponding to the child node has been changed randomly
- Parameters:
None
- Returns:
ttspec – TernaryTreeSpec that parent node corresponding to the child node has been changed randomly
- Return type:
- property edges: dict[int, int]
Get the edges of the TernaryTreeSpec
- Parameters:
None
Reterns
-------
edges (dict[int,tuple[int,str]]) – dictionary data with child node numbers as keys, parent node numbers and Pauli strings as values
- property indices: int
Get the indices
- is_valid() bool
check validity
- Parameters:
None
- Returns:
the TernaryTreeSpec is valid or not
- Return type:
bool
- property num_qubits: int
Get the number of qubits
- classmethod random(num_indices: int) Self
Get a TernaryTreeSpec randomly
- Parameters:
num_indices (int) – number of indices
- Returns:
ttspec – ternary tree specification
- Return type:
- show()
show the ternary tree
- Parameters:
None
- Return type:
None
- swap_indices() Self
get the TernaryTreeSpec that swapped two indices randomly
- Parameters:
None
- Returns:
ttspec – TernaryTreeSpec that swaped two indices randomly
- Return type:
- to_string() str
Get the string of TernaryTreeSpec
- Parameters:
None
- Returns:
s – string of the TernaryTreeSpec
- Return type:
str
- yaf2q.yaf2q_encoding_matrix(kind, ttspec_str, num_qubits)
Get the encoding matrix
# Arguments
kind - kind of fermion to qubit transformation (jordan-wigner/parity/bravyi-kitaev)
ttspec_str - ternary tree generator (string)
- yaf2q.yaf2q_encoding_matrix_inv(kind, ttspec_str, num_qubits)
Get the inverse of encoding matrix
# Arguments
kind - kind of fermion to qubit transformation (jordan-wigner/parity/bravyi-kitaev)
ttspec_str - ternary tree generator (string)
- yaf2q.yaf2q_operator(kind, ttspec_str, fh_str)
Transform the fermion operator (string) to qubit operator
# Arguments
kind - kind of fermion to qubit transformation (jordan-wigner/parity/bravyi-kitaev)
ttspec_str - ternary tree generator (string)
fh_str - fermion operator (string)