練習 - 開始使用 Azure Quantum Resource Estimator
讓我們使用 Azure Quantum Resource Estimator 來進行一些練習。 在下列範例中,您會估計 Shor 演算法範例的實體資源。
安裝 qsharp 和 qsharp-widgets
首先,安裝最新的 Azure Quantum qsharp
和 qsharp-widgets
套件。
python -m pip install --upgrade qsharp qsharp-widgets
建立量子演算法
在 Visual Studio Code 中,選取 [檢視]>[命令選擇區],然後選取 [建立:新增 Jupyter Notebook]。
在筆記本的第一個儲存格中,匯入
qsharp
套件:import qsharp from qsharp_widgets import EstimateDetails
新增儲存格並複製下列程式碼:
%%qsharp /// # Sample /// Random Bit /// /// # Description /// This Q# program generates a random bit by setting a qubit in a superposition /// of the computational basis states |0〉 and |1〉, and returning the measurement /// result. operation RandomBit() : Result { // Qubits are only accesible for the duration of the scope where they // are allocated and are automatically released at the end of the scope. use qubit = Qubit(); // Set the qubit in superposition by applying a Hadamard transformation. H(qubit); // Measure the qubit. There is a 50% probability of measuring either // `Zero` or `One`. let result = M(qubit); // Reset the qubit so it can be safely released. Reset(qubit); return result; }
估計量子演算法
現在,使用預設假設來估計
RandomBit
作業的實體資源。 新增儲存格並複製下列程式碼:result = qsharp.estimate("RandomBit()") result
qsharp.estimate
函式會建立結果物件,可用來顯示具有整體實體資源計數的資料表。 第一個資料表會顯示主要實體資源估計值。 此RandomBit
作業需要 300 個量子位元,並在量子計算機上執行 2 微秒。實體資源估計值 值 執行階段 2 微秒 rQOPS 3.00M 實際量子位元 300 您可以藉由折迭群組來檢查成本詳細資料,這些群組具有詳細資訊。 例如,摺疊 [邏輯量子位元參數] 群組,以查看程式碼距離為 5,而每邏輯量子位元的實體量子位元的數目為 50。
邏輯量子位元參數 值 QEC 配置 surface_code 程式碼距離 5 實際量子位元 50 邏輯週期時間 2 微秒 邏輯量子位元錯誤率 3.00E-5 交叉前置要素 0.03 錯誤修正臨界值 0.01 邏輯週期時間公式 (4 * twoQubitGateTime
+ 2 *oneQubitMeasurementTime
) *codeDistance
實體量子位元公式 2 * codeDistance
*codeDistance
您可以使用
jobParams
欄位來存取可傳遞至作業執行的所有目標參數,並查看假設的預設值:result['jobParams']
{'errorBudget': 0.001, 'qecScheme': {'crossingPrefactor': 0.03, 'errorCorrectionThreshold': 0.01, 'logicalCycleTime': '(4 * twoQubitGateTime + 2 * oneQubitMeasurementTime) * codeDistance', 'name': 'surface_code', 'physicalQubitsPerLogicalQubit': '2 * codeDistance * codeDistance'}, 'qubitParams': {'instructionSet': 'GateBased', 'name': 'qubit_gate_ns_e3', 'oneQubitGateErrorRate': 0.001, 'oneQubitGateTime': '50 ns', 'oneQubitMeasurementErrorRate': 0.001, 'oneQubitMeasurementTime': '100 ns', 'tGateErrorRate': 0.001, 'tGateTime': '50 ns', 'twoQubitGateErrorRate': 0.001, 'twoQubitGateTime': '50 ns'}}
您可以看到資源估算器會採用
qubit_gate_ns_e3
量子位模型、surface_code
錯誤更正碼和 0.001 錯誤預算作為估計的預設值。
變更預設值並估計演算法
提交計劃的資源估計要求時,您可以指定一些選擇性參數。 以下是您可以自訂的目標參數:
errorBudget
:演算法的整體允許錯誤預算qecScheme
:量子誤差修正 (QEC) 配置qubitParams
:實體量子位元參數constraints
:元件層級的條件約束distillationUnitSpecifications
:T Factory 擷取演算法的規格estimateType
:單一或前沿
變更量子位元模型
您可以使用以 Majorana 為基礎的量子位元參數,qubitParams
,qubit_maj_ns_e6
來估計相同演算法的成本。
result_maj = qsharp.estimate("RandomBit()", params={
"qubitParams": {
"name": "qubit_maj_ns_e6"
}})
EstimateDetails(result_maj)
變更量子誤差修正配置
您可以在 Majorana 型的量子位元參數上,使用浮點 QEC 配置,qecScheme
,重新執行相同範例的資源估計作業。
result_maj = qsharp.estimate("RandomBit()", params={
"qubitParams": {
"name": "qubit_maj_ns_e6"
},
"qecScheme": {
"name": "floquet_code"
}})
EstimateDetails(result_maj)
變更錯誤預算
接下來,使用 10% 的 errorBudget
,重新執行相同的量子線路。
result_maj = qsharp.estimate("RandomBit()", params={
"qubitParams": {
"name": "qubit_maj_ns_e6"
},
"qecScheme": {
"name": "floquet_code"
},
"errorBudget": 0.1})
EstimateDetails(result_maj)