[{"data":1,"prerenderedAt":406},["ShallowReactive",2],{"content-query-wxiO17nR8e":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":400,"_id":401,"_source":402,"_file":403,"_stem":404,"_extension":405},"\u002Ftechnology-blogs\u002Fzh\u002F2026-5-15","zh",false,"","新手必看！2026 CCF昇思杯热身赛保姆级通关教程","这份答题攻略针对每道题给出了从思路到解题步骤的完整指引，助力参赛者快速上手MindSpore Quantum框架，高效通关。","2026-5-15","https:\u002F\u002Fobs-mindspore-file.obs.cn-north-4.myhuaweicloud.com\u002Ffile\u002F2024\u002F11\u002F28\u002F8e0e0150508a4c5ba4287fa3bec8ea3f.png","technology-blogs","技术解读",{"type":15,"children":16,"toc":394},"root",[17,25,31,36,47,54,59,64,76,81,86,95,106,113,122,128,133,153,160,165,170,183,188,197,202,211,216,225,230,235,242,246,251,256,261,266,275,280,303,308,315,320,325,330,335,340,345,350,359,364,371,382,387],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"新手必看2026-ccf昇思杯热身赛保姆级通关教程",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":24,"value":30},"热身赛主要围绕 MindSpore Quantum 的基础接口展开，覆盖量子线路搭建、控制门、参数化线路、哈密顿量期望值、自动微分、测量采样、Trotter 展开和噪声模型等内容。这份答题攻略针对每道题给出了从思路到解题步骤的完整指引，助力参赛者快速上手MindSpore Quantum框架，高效通关。",{"type":18,"tag":26,"props":32,"children":33},{},[34],{"type":24,"value":35},"大赛报名：",{"type":18,"tag":26,"props":37,"children":38},{},[39],{"type":18,"tag":40,"props":41,"children":45},"a",{"href":42,"rel":43},"https:\u002F\u002Fdeveloper.huaweicloud.com\u002Fcontest\u002Fquantum-computing2026.html",[44],"nofollow",[46],{"type":24,"value":42},{"type":18,"tag":48,"props":49,"children":51},"h2",{"id":50},"_01-答题准备",[52],{"type":24,"value":53},"01 答题准备",{"type":18,"tag":26,"props":55,"children":56},{},[57],{"type":24,"value":58},"热身赛为量子计算基础学习和编程演练，完成热身赛的前50名选手将有机会获得定制礼品和电子证书，数量有限，不容错过。",{"type":18,"tag":26,"props":60,"children":61},{},[62],{"type":24,"value":63},"第一步：注册并完成华为云账号实名认证；",{"type":18,"tag":26,"props":65,"children":66},{},[67,69],{"type":24,"value":68},"第二步：准备开发环境，详见本地安装使用MindSpore Quantum操作指导；（",{"type":18,"tag":40,"props":70,"children":73},{"href":71,"rel":72},"https:\u002F\u002Fwww.hiascend.com\u002Fforum\u002Fthread-0207195718388320048-1-1.html%EF%BC%89",[44],[74],{"type":24,"value":75},"https:\u002F\u002Fwww.hiascend.com\u002Fforum\u002Fthread-0207195718388320048-1-1.html）",{"type":18,"tag":26,"props":77,"children":78},{},[79],{"type":24,"value":80},"第三步：了解热身赛答题指南；",{"type":18,"tag":26,"props":82,"children":83},{},[84],{"type":24,"value":85},"📖 热身赛题目文档下载：",{"type":18,"tag":26,"props":87,"children":88},{},[89],{"type":18,"tag":40,"props":90,"children":93},{"href":91,"rel":92},"https:\u002F\u002Fftp.cngb.org\u002Fpub\u002Fcourse\u002Fmicos\u002Fmindspore\u002F",[44],[94],{"type":24,"value":91},{"type":18,"tag":96,"props":97,"children":99},"div",{"style":98},"text-align: center;",[100],{"type":18,"tag":101,"props":102,"children":105},"img",{"src":103,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F1.jpg","display: block;margin: 0 auto;max-width:60%",[],{"type":18,"tag":96,"props":107,"children":108},{"style":98},[109],{"type":18,"tag":101,"props":110,"children":112},{"src":111,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F2.jpg",[],{"type":18,"tag":26,"props":114,"children":115},{},[116],{"type":18,"tag":40,"props":117,"children":120},{"href":118,"rel":119},"https:\u002F\u002Fwww.koushare.com\u002Flive\u002Fdetails\u002F52148",[44],[121],{"type":24,"value":118},{"type":18,"tag":48,"props":123,"children":125},{"id":124},"_02-答题指导",[126],{"type":24,"value":127},"02 答题指导",{"type":18,"tag":26,"props":129,"children":130},{},[131],{"type":24,"value":132},"题目1：制备一个量子线路\n制备一个三比特量子线路，该线路包含三个量子比特（q0, q1, q2）。线路由以下三个门组成：",{"type":18,"tag":134,"props":135,"children":136},"ol",{},[137,143,148],{"type":18,"tag":138,"props":139,"children":140},"li",{},[141],{"type":24,"value":142},"一个作用在 q1 比特上的 X 门。",{"type":18,"tag":138,"props":144,"children":145},{},[146],{"type":24,"value":147},"一个 H 门，作用在 q2 比特上，受 q1 比特控制。",{"type":18,"tag":138,"props":149,"children":150},{},[151],{"type":24,"value":152},"一个 X 门，作用在 q0 比特上，受 q1 和 q2 比特共同控制。",{"type":18,"tag":96,"props":154,"children":155},{"style":98},[156],{"type":18,"tag":101,"props":157,"children":159},{"src":158,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F3.jpg",[],{"type":18,"tag":26,"props":161,"children":162},{},[163],{"type":24,"value":164},"1、解题思路：",{"type":18,"tag":26,"props":166,"children":167},{},[168],{"type":24,"value":169},"这道题考查的是如何在 MindSpore Quantum 中构建基础量子线路，特别是如何使用量子门的on方法来指定目标比特和控制比特。\non 方法：\nMindSpore Quantum 中几乎所有的量子门都继承自 BasicGate类，并拥有 on()方法。这个方法的第一个参数是目标比特的索引（一个整数），第二个可选参数是控制比特的索引（可以是一个整数，或者一个包含多个整数的列表）。\n本题中，第一步没有控制位，第二步有一个控制位，第三步有两个控制位，因此正好覆盖了on()方法最常见的三种写法。\n2、解题步骤：",{"type":18,"tag":26,"props":171,"children":172},{},[173,175,181],{"type":24,"value":174},"1）对于作用在 q1 上的 X 门，目标比特是 1，没有控制比特，所以使用 X.on(1)。\n2）对于作用在 q2 上、受 q1 控制的 H 门，目标比特是 2，控制比特是 1，所以使用 H.on(2, 1)。\n3）对于作用在 q0 上、受 q1 和 q2 共同控制的 X 门，目标比特是 0，控制比特是 1 和 2。当有多个控制比特时，需要将它们的索引放在一个列表里作为on方法的第二个参数，所以使用 X.on(0, ",{"type":18,"tag":176,"props":177,"children":178},"span",{},[179],{"type":24,"value":180},"1, 2",{"type":24,"value":182},")。\n将这三步依次添加到 Circuit 对象中即可完成线路构建。\n3、相关API文档：",{"type":18,"tag":26,"props":184,"children":185},{},[186],{"type":24,"value":187},"👉 Circuit类:",{"type":18,"tag":26,"props":189,"children":190},{},[191],{"type":18,"tag":40,"props":192,"children":195},{"href":193,"rel":194},"https:\u002F\u002Fwww.mindspore.cn\u002Fmindquantum\u002Fdocs\u002Fzh-CN\u002Fr0.12\u002Fcore\u002Fcircuit\u002Fmindquantum.core.circuit.Circuit.html",[44],[196],{"type":24,"value":193},{"type":18,"tag":26,"props":198,"children":199},{},[200],{"type":24,"value":201},"👉 量子门模块(mindquantum.core.gates):",{"type":18,"tag":26,"props":203,"children":204},{},[205],{"type":18,"tag":40,"props":206,"children":209},{"href":207,"rel":208},"https:\u002F\u002Fwww.mindspore.cn\u002Fmindquantum\u002Fdocs\u002Fzh-CN\u002Fr0.12\u002Fcore\u002Fmindquantum.core.gates.html#module-mindquantum.core.gates",[44],[210],{"type":24,"value":207},{"type":18,"tag":26,"props":212,"children":213},{},[214],{"type":24,"value":215},"👉 BasicGate.on方法:",{"type":18,"tag":26,"props":217,"children":218},{},[219],{"type":18,"tag":40,"props":220,"children":223},{"href":221,"rel":222},"https:\u002F\u002Fwww.mindspore.cn\u002Fmindquantum\u002Fdocs\u002Fzh-CN\u002Fr0.12\u002Fcore\u002Fgates\u002Fmindquantum.core.gates.BasicGate.html#mindquantum.core.gates.BasicGate.on",[44],[224],{"type":24,"value":221},{"type":18,"tag":26,"props":226,"children":227},{},[228],{"type":24,"value":229},"题目2：为量子线路添加控制比特\n给定一个已有的量子线路 u1，在此例中是作用在 q0、q1、q2 上的三比特量子傅里叶变换线路 u1 = qft(range(3))，要求使用 q3 作为控制比特，将其转换为一个受控量子线路 u2。",{"type":18,"tag":26,"props":231,"children":232},{},[233],{"type":24,"value":234},"也就是说，u1中的每一个量子门操作，在u2中都将受到q3的控制。只有当 q3 为 1 时，u1才会在 q0、q1、q2 上生效。",{"type":18,"tag":96,"props":236,"children":237},{"style":98},[238],{"type":18,"tag":101,"props":239,"children":241},{"src":240,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F4.jpg",[],{"type":18,"tag":26,"props":243,"children":244},{},[245],{"type":24,"value":164},{"type":18,"tag":26,"props":247,"children":248},{},[249],{"type":24,"value":250},"这道题主要考查 mindquantum.core.circuit.controlled() 函数的使用。这个函数非常方便，它可以将一个完整的量子线路（或者单个算符）整体添加上控制位。",{"type":18,"tag":26,"props":252,"children":253},{},[254],{"type":24,"value":255},"controlled() 函数：\n它接受一个参数 circuit_fn，表示需要被控制的对象，可以是一个 Circuit 实例，也可以是一个能够生成量子线路的函数。\n该函数返回一个新的函数。这个新函数需要继续传入控制比特的索引，然后才会返回添加控制比特后的电路。\n2、解题步骤：",{"type":18,"tag":26,"props":257,"children":258},{},[259],{"type":24,"value":260},"1）题目已经给出了原始线路 u1 = qft(range(3))。\n2）题目要求将 q3 添加为控制位。由于 u1作用在 q0、q1、q2（索引为 0、1、2），新添加的控制位 q3 的索引就是3。\n3）先调用 controlled(u1)获取一个可以添加控制位的函数，再传入控制位索引 3 生成目标线路 u2。该函数会自动处理 u1中的所有门，为它们添加上索引为 3 的控制位。\n3、相关API文档：",{"type":18,"tag":26,"props":262,"children":263},{},[264],{"type":24,"value":265},"👉 controlled数:",{"type":18,"tag":26,"props":267,"children":268},{},[269],{"type":18,"tag":40,"props":270,"children":273},{"href":271,"rel":272},"https:\u002F\u002Fwww.mindspore.cn\u002Fmindquantum\u002Fdocs\u002Fzh-CN\u002Fr0.12\u002Fcore\u002Fcircuit\u002Fmindquantum.core.circuit.controlled.html",[44],[274],{"type":24,"value":271},{"type":18,"tag":26,"props":276,"children":277},{},[278],{"type":24,"value":279},"题目3：量子线路的厄米共轭\n给定一个量子线路，要求计算其厄米共轭（Hermitian Conjugate）线路。厄米共轭操作通常用匕首符号表示。对于一个量子线路\nU = U_n ··· U_2 U_1，其厄米共轭线路为 U† = U_1† U_2† ··· U_n†。也就是说，线路中所有门的操作顺序会颠倒，并且每个门都被替换为其自身的厄米共轭门。\n本题要求先按如下顺序构造原始线路：",{"type":18,"tag":134,"props":281,"children":282},{},[283,288,293,298],{"type":18,"tag":138,"props":284,"children":285},{},[286],{"type":24,"value":287},"在 q1 上作用 H 门。",{"type":18,"tag":138,"props":289,"children":290},{},[291],{"type":24,"value":292},"在 q0 上作用 T 门。",{"type":18,"tag":138,"props":294,"children":295},{},[296],{"type":24,"value":297},"构造一个被 q1 控制、作用在 q2 上的 X 门。",{"type":18,"tag":138,"props":299,"children":300},{},[301],{"type":24,"value":302},"在 q2 上作用 S 门。",{"type":18,"tag":26,"props":304,"children":305},{},[306],{"type":24,"value":307},"然后使用 dagger 求这条线路的厄米共轭。",{"type":18,"tag":96,"props":309,"children":310},{"style":98},[311],{"type":18,"tag":101,"props":312,"children":314},{"src":313,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F5.jpg",[],{"type":18,"tag":26,"props":316,"children":317},{},[318],{"type":24,"value":319},"1、解题思路\n这道题考查的是如何获取一个量子线路的厄米共轭形式。MindSpore Quantum 提供了便捷的 mindquantum.core.circuit.dagger() 函数来完成这个任务。",{"type":18,"tag":26,"props":321,"children":322},{},[323],{"type":24,"value":324},"dagger() 函数：",{"type":18,"tag":26,"props":326,"children":327},{},[328],{"type":24,"value":329},"该函数接受一个 Circuit对象（或其他支持厄米共轭操作的对象，如算符）作为输入，并返回一个新的 Circuit对象，该对象即为输入线路的厄米共轭线路。它会自动处理门顺序的反转和每个门自身的厄米共轭替换。",{"type":18,"tag":26,"props":331,"children":332},{},[333],{"type":24,"value":334},"需要注意的是，H 门和 CNOT 门是自身厄米共轭的；S门和 T 门的厄米共轭分别是它们的逆门。使用 dagger(circ)时，这些细节不需要手动处理。",{"type":18,"tag":26,"props":336,"children":337},{},[338],{"type":24,"value":339},"2、解题步骤\n1）首先，根据原始线路图示构建出 circ对象。这需要依次添加 H 门、T 门、受控 X 门和 S 门。",{"type":18,"tag":26,"props":341,"children":342},{},[343],{"type":24,"value":344},"2）然后，直接调用 dagger(circ) 函数，将返回的厄米共轭线路赋值给 dag_circ。",{"type":18,"tag":26,"props":346,"children":347},{},[348],{"type":24,"value":349},"3、相关API文档\n👉 dagger 函数：",{"type":18,"tag":26,"props":351,"children":352},{},[353],{"type":18,"tag":40,"props":354,"children":357},{"href":355,"rel":356},"https:\u002F\u002Fwww.mindspore.cn\u002Fmindquantum\u002Fdocs\u002Fzh-CN\u002Fr0.12\u002Fcore\u002Fcircuit\u002Fmindquantum.core.circuit.dagger.html",[44],[358],{"type":24,"value":355},{"type":18,"tag":26,"props":360,"children":361},{},[362],{"type":24,"value":363},"后续题目详解，请下载PDF文件查看",{"type":18,"tag":96,"props":365,"children":366},{"style":98},[367],{"type":18,"tag":101,"props":368,"children":370},{"src":369,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F6.jpg",[],{"type":18,"tag":26,"props":372,"children":373},{},[374,376],{"type":24,"value":375},"文档链接：",{"type":18,"tag":40,"props":377,"children":380},{"href":378,"rel":379},"https:\u002F\u002Fqr61.cn\u002FoxlATu\u002FqTNtNxS",[44],[381],{"type":24,"value":378},{"type":18,"tag":26,"props":383,"children":384},{},[385],{"type":24,"value":386},"有任何疑问，请联系小助手",{"type":18,"tag":96,"props":388,"children":389},{"style":98},[390],{"type":18,"tag":101,"props":391,"children":393},{"src":392,"style":104,"alt":7},"\u002Fcategory\u002Finformation\u002Ftechnology-blogs\u002Fbanner\u002F2026-5-15\u002F7.jpg",[],{"title":7,"searchDepth":395,"depth":395,"links":396},4,[397,399],{"id":50,"depth":398,"text":53},2,{"id":124,"depth":398,"text":127},"markdown","content:technology-blogs:zh:2026-5-15.md","content","technology-blogs\u002Fzh\u002F2026-5-15.md","technology-blogs\u002Fzh\u002F2026-5-15","md",1779709260583]