-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceEstimatorModel.js
More file actions
133 lines (117 loc) · 3.62 KB
/
Copy pathResourceEstimatorModel.js
File metadata and controls
133 lines (117 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
// ResourceEstimatorModel.js
// Quantum resource estimation model based on statistical analysis
/**
* Device model configuration
* Contains parameters and calculation model for different quantum devices
*
* VTT Q50: Analytical model, R² = 0.9715
* Aalto Q20: Qubit-scaled analytical model, CV R² = 0.9798
*/
const DEVICE_PARAMS = {
'vtt-q50': {
name: "VTT Q50",
max_qubits: 54,
model_type: "analytical",
T_init: 0.8837048192083147,
efficiency_base: 0.9859309839575585,
throughput_coef: 0.0006252263363799867,
batch_cap: 19.29350870051621
},
'aalto-q20': {
name: "Aalto Q20",
max_qubits: 20,
model_type: "analytical",
T_init: 1.2252838370600004e-07,
efficiency_base: 0.9989999903706621,
throughput_coef: 0.0002954914740018577,
throughput_qubit_coef: 1.3699793861798854e-05,
batch_cap: 3.0000119840851145
}
};
/**
* Calculate a single polynomial term value.
*
* @param {string} termName - Term name (e.g., 'qubits^2', 'batches kshots')
* @param {Object} values - Dictionary with 'qubits', 'batches', 'kshots'
* @returns {number} Term value
*/
function calculateTerm(termName, values) {
let result = 1.0;
// Parse term (e.g., 'qubits^2 batches', 'kshots^3')
const parts = termName.split(' ');
for (const part of parts) {
if (part.includes('^')) {
// Power term: variable^exponent
const [variable, exponent] = part.split('^');
const power = parseInt(exponent, 10);
result *= Math.pow(values[variable], power);
} else {
// Simple variable
result *= values[part];
}
}
return result;
}
/**
* Calculate QPU seconds for a given device and parameters.
*
* @param {string} device - Device identifier ('vtt-q50', 'aalto-q20')
* @param {Object} params - Dictionary with keys 'batches', 'shots', and 'qubits'
* @returns {number} Estimated QPU seconds (always positive)
*/
function calculateQPUSeconds(device, params) {
if (!DEVICE_PARAMS[device]) {
console.error(`Unknown device: ${device}`);
return 0;
}
const deviceConfig = DEVICE_PARAMS[device];
const batches = parseInt(params.batches, 10) || 1;
const shots = parseInt(params.shots, 10) || 1000;
const qubits = parseInt(params.qubits, 10) || 2;
const depth = parseInt(params.depth, 10) || 1;
const kshots = shots / 1000.0;
const featureValues = {
qubits: qubits,
batches: batches,
kshots: kshots,
depth: depth
};
let prediction;
if (deviceConfig.model_type === 'analytical') {
const efficiency = Math.pow(
deviceConfig.efficiency_base,
Math.min(batches, deviceConfig.batch_cap)
);
// throughput_qubit_coef is optional; defaults to 0 for devices without qubit scaling
const throughput = deviceConfig.throughput_coef +
(deviceConfig.throughput_qubit_coef || 0) * qubits;
prediction = deviceConfig.T_init +
efficiency * batches * shots * throughput;
} else {
// Polynomial model
prediction = deviceConfig.intercept;
for (const term of deviceConfig.terms) {
let termValue;
// Handle old format with type/variable/variables
if (term.type) {
if (term.type === 'single') {
termValue = featureValues[term.variable];
} else if (term.type === 'power') {
termValue = Math.pow(featureValues[term.variable], term.exponent);
} else if (term.type === 'interaction') {
termValue = 1.0;
for (const variable of term.variables) {
termValue *= featureValues[variable];
}
}
} else {
termValue = calculateTerm(term.name, featureValues);
}
prediction += term.coefficient * termValue;
}
}
prediction = Math.max(0.0, prediction);
return parseFloat(prediction.toFixed(2));
}
// Export model functions and configurations
export { DEVICE_PARAMS, calculateQPUSeconds };