ffsim_integration
¶
ffsim Integration Module for QSCI
This module provides integration between ffsim's UCJ/LUCJ ansatz and the QSCI framework. It requires ffsim to be installed: pip install quri-qsci[ffsim]
Key Components: - molecular_systems: Molecular system creation utilities - integration: ffsim UCJ/LUCJ ansatz integration - state_conversion: State format conversion between ffsim and QURI Parts - qsci_interface: High-level QSCI-ffsim integration interface
Modules:
Name | Description |
---|---|
integration |
ffsim integration module for UCJ and LUCJ ansatz generation. |
molecular_systems |
Molecular system setup utilities for ffsim/UCJ ansatz integration. |
qsci_interface |
Main interface for ffsim/UCJ ansatz integration with QSCI framework. |
state_conversion |
State conversion bridge between ffsim and QURI Parts. |
Classes:
Name | Description |
---|---|
MolecularSystem |
Container for molecular system data. |
UCJResult |
Container for UCJ ansatz optimization results. |
ConversionMetrics |
Metrics for state conversion quality. |
LUCJQSCIResult |
Result from LUCJ/UCJ + QSCI workflow. |
Functions:
Name | Description |
---|---|
create_h2_molecule |
Create H2 molecule system for testing and validation. |
create_n2_molecule |
Create N2 molecule system for benchmark studies. |
get_reference_energies |
Get reference energies for common molecules and basis sets. |
validate_molecular_system |
Validate that a molecular system is properly constructed. |
create_ucj_ansatz |
Create and optimize UCJ (Unitary Coupled Cluster Jastrow) ansatz. |
create_lucj_ansatz |
Create and optimize LUCJ (Linear UCJ) ansatz. |
ffsim_to_quri_state |
Convert ffsim state vector to QURI Parts CircuitQuantumState. |
ucj_result_to_quri_state |
Convert UCJ/LUCJ result to QURI Parts state with validation. |
run_lucj_qsci |
Run complete LUCJ/UCJ + QSCI workflow. |
print_result_summary |
Print a comprehensive summary of LUCJ/UCJ + QSCI results. |
run_convergence_study |
Run a convergence study with increasing subspace sizes. |
benchmark_against_reference |
Benchmark LUCJ/UCJ + QSCI results against reference energy. |
Attributes:
Name | Type | Description |
---|---|---|
FFSIM_AVAILABLE |
|
MolecularSystem
dataclass
¶
MolecularSystem(
name,
geometry,
basis,
charge,
spin,
bond_length,
mole,
scf_result,
active_space,
mo_integrals,
hartree_fock_energy,
fci_energy,
quri_hamiltonian,
ffsim_mol_data,
jw_mapping,
)
Container for molecular system data.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
|
geometry |
str
|
|
basis |
str
|
|
charge |
int
|
|
spin |
int
|
|
bond_length |
float
|
|
mole |
Any
|
|
scf_result |
Any
|
|
active_space |
Any
|
|
mo_integrals |
Any
|
|
hartree_fock_energy |
float
|
|
fci_energy |
float
|
|
quri_hamiltonian |
Operator
|
|
ffsim_mol_data |
Any
|
|
jw_mapping |
Any
|
|
UCJResult
dataclass
¶
UCJResult(
ansatz_type,
optimized_parameters,
final_energy,
n_reps,
state_vector,
optimization_success,
n_iterations,
)
Container for UCJ ansatz optimization results.
Attributes:
Name | Type | Description |
---|---|---|
ansatz_type |
str
|
|
optimized_parameters |
ndarray
|
|
final_energy |
float
|
|
n_reps |
int
|
|
state_vector |
ndarray
|
|
optimization_success |
bool
|
|
n_iterations |
int
|
|
ConversionMetrics
dataclass
¶
ConversionMetrics(
fidelity,
probability_overlap,
state_vector_norm,
max_probability_diff,
conversion_method,
)
Metrics for state conversion quality.
Attributes:
Name | Type | Description |
---|---|---|
fidelity |
float
|
|
probability_overlap |
float
|
|
state_vector_norm |
float
|
|
max_probability_diff |
float
|
|
conversion_method |
str
|
|
LUCJQSCIResult
dataclass
¶
LUCJQSCIResult(
molecule_name,
ansatz_type,
ansatz_energy,
ansatz_optimization_success,
qsci_results,
conversion_metrics,
hartree_fock_energy,
fci_energy,
target_energy,
total_time,
ansatz_time,
conversion_time,
qsci_time,
)
Result from LUCJ/UCJ + QSCI workflow.
Attributes:
Name | Type | Description |
---|---|---|
molecule_name |
str
|
|
ansatz_type |
str
|
|
ansatz_energy |
float
|
|
ansatz_optimization_success |
bool
|
|
qsci_results |
Dict[int, QSCIResult]
|
|
conversion_metrics |
ConversionMetrics
|
|
hartree_fock_energy |
float
|
|
fci_energy |
float
|
|
target_energy |
Optional[float]
|
|
total_time |
float
|
|
ansatz_time |
float
|
|
conversion_time |
float
|
|
qsci_time |
float
|
|
best_qsci_energy |
float
|
Best (lowest) energy from QSCI calculations. |
best_subspace_size |
int
|
Subspace size that gave the best energy. |
energy_improvement_vs_ansatz |
float
|
Energy improvement of best QSCI result vs ansatz. |
energy_error_vs_fci |
float
|
Energy error of best QSCI result vs FCI reference. |
create_h2_molecule
¶
create_h2_molecule(
basis="6-31g", bond_length=0.74, charge=0, spin=0
)
Create H2 molecule system for testing and validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Basis set (default: 6-31g) |
'6-31g'
|
|
float
|
H-H bond length in Angstrom (default: 0.74) |
0.74
|
|
int
|
Molecular charge (default: 0) |
0
|
|
int
|
Spin multiplicity (default: 0 for singlet) |
0
|
Returns:
Type | Description |
---|---|
MolecularSystem
|
MolecularSystem object with all necessary data |
Raises:
Type | Description |
---|---|
ImportError
|
If ffsim is not installed |
Source code in ffsim_integration/molecular_systems.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
create_n2_molecule
¶
create_n2_molecule(
basis="6-31g",
bond_length=1.0,
charge=0,
spin=0,
active_space=None,
)
Create N2 molecule system for benchmark studies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Basis set (default: 6-31g) |
'6-31g'
|
|
float
|
N-N bond length in Angstrom (default: 1.0) |
1.0
|
|
int
|
Molecular charge (default: 0) |
0
|
|
int
|
Spin multiplicity (default: 0 for singlet) |
0
|
|
Optional[Tuple[int, int]]
|
(n_electrons, n_orbitals) for active space (None for full space) |
None
|
Returns:
Type | Description |
---|---|
MolecularSystem
|
MolecularSystem object with all necessary data |
Raises:
Type | Description |
---|---|
ImportError
|
If ffsim is not installed |
Source code in ffsim_integration/molecular_systems.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
get_reference_energies
¶
Get reference energies for common molecules and basis sets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Molecule name ("H2" or "N2") |
required |
|
str
|
Basis set name |
'6-31g'
|
Returns:
Type | Description |
---|---|
Dict[str, float]
|
Dictionary with reference energies in Hartree |
Source code in ffsim_integration/molecular_systems.py
validate_molecular_system
¶
validate_molecular_system(system)
Validate that a molecular system is properly constructed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
MolecularSystem
|
MolecularSystem to validate |
required |
Returns:
Type | Description |
---|---|
bool
|
True if system is valid, False otherwise |
Source code in ffsim_integration/molecular_systems.py
create_ucj_ansatz
¶
create_ucj_ansatz(
mol_system,
n_reps=1,
optimization_method="BFGS",
max_iterations=100,
)
Create and optimize UCJ (Unitary Coupled Cluster Jastrow) ansatz.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
MolecularSystem
|
MolecularSystem containing molecular data |
required |
|
int
|
Number of repetitions in the ansatz circuit |
1
|
|
str
|
Optimization method for parameter optimization |
'BFGS'
|
|
int
|
Maximum optimization iterations |
100
|
Returns:
Type | Description |
---|---|
UCJResult
|
UCJResult with optimized parameters and state vector |
Raises:
Type | Description |
---|---|
ImportError
|
If ffsim is not installed |
Source code in ffsim_integration/integration.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
create_lucj_ansatz
¶
create_lucj_ansatz(
mol_system,
n_reps=1,
optimization_method="BFGS",
max_iterations=100,
)
Create and optimize LUCJ (Linear UCJ) ansatz.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
MolecularSystem
|
MolecularSystem containing molecular data |
required |
|
int
|
Number of repetitions in the ansatz circuit |
1
|
|
str
|
Optimization method for parameter optimization |
'BFGS'
|
|
int
|
Maximum optimization iterations |
100
|
Returns:
Type | Description |
---|---|
UCJResult
|
UCJResult with optimized parameters and state vector |
Raises:
Type | Description |
---|---|
ImportError
|
If ffsim is not installed |
Source code in ffsim_integration/integration.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
ffsim_to_quri_state
¶
ffsim_to_quri_state(
state_vector,
n_qubits,
threshold=1e-10,
method="sampling_circuit",
)
Convert ffsim state vector to QURI Parts CircuitQuantumState.
This is a key function that bridges ffsim output with QSCI input requirements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ndarray
|
State vector from ffsim (normalized) |
required |
|
int
|
Number of qubits in the system |
required |
|
float
|
Threshold for significant amplitudes |
1e-10
|
|
str
|
Conversion method ("sampling_circuit" or "superposition") |
'sampling_circuit'
|
Returns:
Type | Description |
---|---|
CircuitQuantumState
|
CircuitQuantumState compatible with QSCI algorithms |
Source code in ffsim_integration/state_conversion.py
ucj_result_to_quri_state
¶
ucj_result_to_quri_state(
ucj_result,
n_qubits,
conversion_method="sampling_circuit",
)
Convert UCJ/LUCJ result to QURI Parts state with validation.
This is a convenience function that combines conversion and validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
UCJResult
|
Result from UCJ/LUCJ optimization |
required |
|
int
|
Number of qubits in the system |
required |
|
str
|
Method for state conversion |
'sampling_circuit'
|
Returns:
Type | Description |
---|---|
Tuple[CircuitQuantumState, ConversionMetrics]
|
Tuple of (converted_state, conversion_metrics) |
Source code in ffsim_integration/state_conversion.py
run_lucj_qsci
¶
run_lucj_qsci(
molecule,
ansatz_type="LUCJ",
subspace_sizes=[50, 100, 150],
basis="sto-3g",
bond_length=None,
n_reps=1,
max_optimization_iterations=50,
total_shots=5000,
conversion_method="sampling_circuit",
active_space=None,
use_homo_lumo=True,
)
Run complete LUCJ/UCJ + QSCI workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Molecule name ("H2" or "N2") |
required |
|
str
|
"UCJ" or "LUCJ" |
'LUCJ'
|
|
List[int]
|
List of subspace dimensions to test |
[50, 100, 150]
|
|
str
|
Basis set for quantum chemistry |
'sto-3g'
|
|
Optional[float]
|
Bond length (None for default) |
None
|
|
int
|
Number of ansatz repetitions |
1
|
|
int
|
Max iterations for ansatz optimization |
50
|
|
int
|
Total measurement shots for QSCI |
5000
|
|
str
|
State conversion method |
'sampling_circuit'
|
|
Optional[Tuple[int, int]]
|
(n_electrons, n_orbitals) for N2 active space (None for full space) |
None
|
|
bool
|
If True, use HOMO-LUMO focused active space for N2 (more efficient) |
True
|
Returns:
Type | Description |
---|---|
LUCJQSCIResult
|
LUCJQSCIResult with complete workflow results |
Source code in ffsim_integration/qsci_interface.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
print_result_summary
¶
Print a comprehensive summary of LUCJ/UCJ + QSCI results.
Source code in ffsim_integration/qsci_interface.py
run_convergence_study
¶
run_convergence_study(
molecule,
ansatz_type="LUCJ",
max_subspace=200,
step_size=25,
**kwargs
)
Run a convergence study with increasing subspace sizes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Molecule name |
required |
|
str
|
Ansatz type |
'LUCJ'
|
|
int
|
Maximum subspace size to test |
200
|
|
int
|
Step size for subspace sizes |
25
|
|
Additional arguments for run_lucj_qsci |
{}
|
Returns:
Type | Description |
---|---|
LUCJQSCIResult
|
LUCJQSCIResult with convergence data |
Source code in ffsim_integration/qsci_interface.py
benchmark_against_reference
¶
benchmark_against_reference(
result, reference_energy, tolerance=0.001
)
Benchmark LUCJ/UCJ + QSCI results against reference energy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
LUCJQSCIResult
|
LUCJQSCIResult to benchmark |
required |
|
float
|
Reference energy in Hartree |
required |
|
float
|
Energy tolerance in Hartree |
0.001
|
Returns:
Type | Description |
---|---|
Dict[str, bool]
|
Dictionary with benchmark results |