├── .clang-format ├── .github ├── CODEOWNERS └── workflows │ └── ci.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CODING_STYLE.md ├── LICENSE ├── LICENSING_INFO.md ├── Makefile.build.gcc ├── Makefile.build.llvm ├── README.md ├── cmake ├── apple-clang.cmake ├── linux-gcc.cmake ├── llvm-clang.cmake └── modules │ ├── Findgmp.cmake │ ├── Findmpc.cmake │ └── Findmpfr.cmake ├── conandata.yml ├── conanfile.py ├── examples ├── CMakeLists.txt ├── QDem │ └── QDem.cpp └── QasmParser │ └── QasmParser.cpp ├── include ├── CMakeLists.txt └── qasm │ ├── AST │ ├── AST.h │ ├── ASTAngleContextControl.h │ ├── ASTAngleNodeBuilder.h │ ├── ASTAngleNodeList.h │ ├── ASTAnnotation.h │ ├── ASTAnnotationContextBuilder.h │ ├── ASTAnyType.h │ ├── ASTAnyTypeBuilder.h │ ├── ASTAnyTypeList.h │ ├── ASTArgument.h │ ├── ASTArgumentNodeBuilder.h │ ├── ASTArray.h │ ├── ASTArraySubscript.h │ ├── ASTBarrier.h │ ├── ASTBase.h │ ├── ASTBinaryOpAssignBuilder.h │ ├── ASTBinaryOpAssignList.h │ ├── ASTBlock.h │ ├── ASTBox.h │ ├── ASTBoxStatementBuilder.h │ ├── ASTBraceMatcher.h │ ├── ASTBuilder.h │ ├── ASTBuiltinFunctionsBuilder.h │ ├── ASTCBit.h │ ├── ASTCBitNodeMap.h │ ├── ASTCalContextBuilder.h │ ├── ASTCallExpr.h │ ├── ASTCastExpr.h │ ├── ASTCtrlAssocBuilder.h │ ├── ASTDeclaration.h │ ├── ASTDeclarationBuilder.h │ ├── ASTDeclarationContext.h │ ├── ASTDeclarationList.h │ ├── ASTDeclarationMap.h │ ├── ASTDefcal.h │ ├── ASTDefcalBuilder.h │ ├── ASTDefcalContextBuilder.h │ ├── ASTDefcalGrammarBuilder.h │ ├── ASTDefcalParameterBuilder.h │ ├── ASTDefcalStatementBuilder.h │ ├── ASTDelay.h │ ├── ASTDirectiveStatementNode.h │ ├── ASTDoWhileStatementBuilder.h │ ├── ASTDuration.h │ ├── ASTDynamicTypeCast.cpp │ ├── ASTDynamicTypeCast.h │ ├── ASTDynamicTypeCast.inc │ ├── ASTElseIfStatementBuilder.h │ ├── ASTElseStatementBuilder.h │ ├── ASTExpression.h │ ├── ASTExpressionBuilder.h │ ├── ASTExpressionEvaluator.h │ ├── ASTExpressionNodeBuilder.h │ ├── ASTExpressionNodeList.h │ ├── ASTExpressionValidator.h │ ├── ASTFlowControl.h │ ├── ASTForRangeInitBuilder.h │ ├── ASTForStatementBuilder.h │ ├── ASTFunction.h │ ├── ASTFunctionCallArgument.h │ ├── ASTFunctionCallExpr.h │ ├── ASTFunctionContextBuilder.h │ ├── ASTFunctionDefinitionBuilder.h │ ├── ASTFunctionParameterBuilder.h │ ├── ASTFunctionStatementBuilder.h │ ├── ASTFunctions.h │ ├── ASTGPhase.h │ ├── ASTGateContextBuilder.h │ ├── ASTGateControl.h │ ├── ASTGateNodeBuilder.h │ ├── ASTGateNodeList.h │ ├── ASTGateOpBuilder.h │ ├── ASTGateOpList.h │ ├── ASTGateQubitParamBuilder.h │ ├── ASTGateQubitTracker.h │ ├── ASTGates.h │ ├── ASTHeapSizeController.h │ ├── ASTIdentifier.h │ ├── ASTIdentifierBuilder.h │ ├── ASTIdentifierIndexResolver.h │ ├── ASTIdentifierTypeController.h │ ├── ASTIfConditionals.h │ ├── ASTIfConditionalsGraphController.h │ ├── ASTIfStatementBuilder.h │ ├── ASTIfStatementTracker.h │ ├── ASTImplicitConversionExpr.h │ ├── ASTInitializerListBuilder.h │ ├── ASTInitializerNode.h │ ├── ASTIntegerList.h │ ├── ASTIntegerListBuilder.h │ ├── ASTIntegerSequence.h │ ├── ASTIntegerSequenceBuilder.h │ ├── ASTInverseAssocBuilder.h │ ├── ASTKernel.h │ ├── ASTKernelBuilder.h │ ├── ASTKernelContextBuilder.h │ ├── ASTKernelStatementBuilder.h │ ├── ASTLength.h │ ├── ASTLiveRangeChecker.h │ ├── ASTLoops.h │ ├── ASTMPComplexList.h │ ├── ASTMangler.h │ ├── ASTMathUtils.h │ ├── ASTMeasure.h │ ├── ASTMissingConstants.h │ ├── ASTNamedTypeDeclarationBuilder.h │ ├── ASTObjectTracker.h │ ├── ASTOpenQASMVersionTracker.h │ ├── ASTOperatorPrecedenceController.h │ ├── ASTParameterBuilder.h │ ├── ASTParameterList.h │ ├── ASTPopcount.h │ ├── ASTPragma.h │ ├── ASTPragmaContextBuilder.h │ ├── ASTPrimitives.h │ ├── ASTProductionFactory.h │ ├── ASTProductionFactory.inc │ ├── ASTProgramBlock.h │ ├── ASTQualifiers.h │ ├── ASTQubit.h │ ├── ASTQubitConcatBuilder.h │ ├── ASTQubitList.h │ ├── ASTQubitNodeBuilder.h │ ├── ASTQubitNodeMap.h │ ├── ASTRedeclarationController.h │ ├── ASTRegisters.h │ ├── ASTReset.h │ ├── ASTResult.h │ ├── ASTReturn.h │ ├── ASTRoot.h │ ├── ASTRotate.h │ ├── ASTScannerLineContext.h │ ├── ASTScopeController.h │ ├── ASTStatement.h │ ├── ASTStatementBuilder.h │ ├── ASTStretch.h │ ├── ASTStringList.h │ ├── ASTStringUtils.h │ ├── ASTSwitchStatement.h │ ├── ASTSwitchStatementBuilder.h │ ├── ASTSymbolTable.h │ ├── ASTTypeCastController.h │ ├── ASTTypeDiscovery.h │ ├── ASTTypeEnums.h │ ├── ASTTypeSpecifier.h │ ├── ASTTypeSystemBuilder.h │ ├── ASTTypes.h │ ├── ASTUtils.h │ ├── ASTValue.h │ ├── ASTWhileStatementBuilder.h │ ├── OpenPulse │ │ ├── ASTOpenPulseCalibration.h │ │ ├── ASTOpenPulseController.h │ │ ├── ASTOpenPulseFrame.h │ │ ├── ASTOpenPulsePlay.h │ │ ├── ASTOpenPulsePort.h │ │ └── ASTOpenPulseWaveform.h │ └── README.ASTProductionFactory.txt │ ├── CMakeLists.txt │ ├── Diagnostic │ ├── DIAGLineBuffer.h │ └── DIAGLineCounter.h │ ├── Frontend │ ├── QasmDiagnosticEmitter.h │ ├── QasmDriver.h │ ├── QasmFeatureTester.h │ ├── QasmParser.h │ └── QasmScanner.h │ └── QPP │ ├── QasmPP.h │ ├── QasmPPFileCleaner.h │ └── QasmPathsResolver.h ├── lib ├── AST │ ├── ASTAngleNodeBuilder.cpp │ ├── ASTAnnotation.cpp │ ├── ASTAnyTypeBuilder.cpp │ ├── ASTArgumentNodeBuilder.cpp │ ├── ASTArray.cpp │ ├── ASTArraySubscript.cpp │ ├── ASTBase.cpp │ ├── ASTBinaryOp.cpp │ ├── ASTBinaryOpNode.cpp │ ├── ASTBox.cpp │ ├── ASTBoxStatementBuilder.cpp │ ├── ASTBraceMatcher.cpp │ ├── ASTBuilder.cpp │ ├── ASTBuiltinFunctionsBuilder.cpp │ ├── ASTCBit.cpp │ ├── ASTCBitNodeMap.cpp │ ├── ASTCallExpr.cpp │ ├── ASTCastExpr.cpp │ ├── ASTCtrlAssocBuilder.cpp │ ├── ASTDeclarationBuilder.cpp │ ├── ASTDeclarationContext.cpp │ ├── ASTDefcal.cpp │ ├── ASTDelay.cpp │ ├── ASTDuration.cpp │ ├── ASTExpressionBuilder.cpp │ ├── ASTExpressionEvaluator.cpp │ ├── ASTExpressionNodeList.cpp │ ├── ASTExpressionValidator.cpp │ ├── ASTForRangeInitBuilder.cpp │ ├── ASTFunctionCallArgument.cpp │ ├── ASTFunctionCallExpr.cpp │ ├── ASTFunctionDefinitionBuilder.cpp │ ├── ASTFunctions.cpp │ ├── ASTGateNodeBuilder.cpp │ ├── ASTGateOpBuilder.cpp │ ├── ASTGateOps.cpp │ ├── ASTGateQubitParamBuilder.cpp │ ├── ASTGateQubitTracker.cpp │ ├── ASTGates.cpp │ ├── ASTHeapSizeController.cpp │ ├── ASTIdentifier.cpp │ ├── ASTIdentifierBuilder.cpp │ ├── ASTIdentifierIndexResolver.cpp │ ├── ASTIdentifierTypeController.cpp │ ├── ASTIfConditionals.cpp │ ├── ASTIfConditionalsGraphController.cpp │ ├── ASTIfStatementBuilder.cpp │ ├── ASTIfStatementTracker.cpp │ ├── ASTImplicitConversionExpr.cpp │ ├── ASTInitializerNode.cpp │ ├── ASTIntegerConstantExpression.cpp │ ├── ASTIntegerSequenceBuilder.cpp │ ├── ASTInverseAssocBuilder.cpp │ ├── ASTKernel.cpp │ ├── ASTLength.cpp │ ├── ASTLiveRangeChecker.cpp │ ├── ASTLoopStatementBuilder.cpp │ ├── ASTLoops.cpp │ ├── ASTMPComplex.cpp │ ├── ASTMPComplexList.cpp │ ├── ASTMPDecimal.cpp │ ├── ASTMPInteger.cpp │ ├── ASTMangler.cpp │ ├── ASTNamedTypeDeclarationBuilder.cpp │ ├── ASTObjectTracker.cpp │ ├── ASTOpenPulseCalibration.cpp │ ├── ASTOpenPulseController.cpp │ ├── ASTOpenPulseFrame.cpp │ ├── ASTOpenPulsePlay.cpp │ ├── ASTOpenPulseWaveform.cpp │ ├── ASTOpenQASMVersionTracker.cpp │ ├── ASTOperatorPrecedenceController.cpp │ ├── ASTParameterBuilder.cpp │ ├── ASTPragma.cpp │ ├── ASTProductionFactory.cpp │ ├── ASTQubit.cpp │ ├── ASTQubitConcatBuilder.cpp │ ├── ASTQubitList.cpp │ ├── ASTQubitNodeBuilder.cpp │ ├── ASTResult.cpp │ ├── ASTScannerLineContext.cpp │ ├── ASTScopeController.cpp │ ├── ASTStatementBuilder.cpp │ ├── ASTStretch.cpp │ ├── ASTStringList.cpp │ ├── ASTSwitchStatement.cpp │ ├── ASTSwitchStatementBuilder.cpp │ ├── ASTSymbolTable.cpp │ ├── ASTTypeCastController.cpp │ ├── ASTTypeDiscovery.cpp │ ├── ASTTypeEnums.cpp │ ├── ASTTypeSpecifier.cpp │ ├── ASTTypeSystemBuilder.cpp │ ├── ASTTypes.cpp │ ├── ASTUtils.cpp │ ├── CMakeLists.txt │ └── DIAGLineBuffer.cpp ├── CMakeLists.txt ├── Diagnostic │ ├── CMakeLists.txt │ ├── DIAGLineBuffer.cpp │ └── DIAGLineCounter.cpp ├── Frontend │ ├── CMakeLists.txt │ ├── QasmDiagnosticEmitter.cpp │ ├── QasmDriver.cpp │ ├── QasmFeatureTester.cpp │ ├── QasmPP.cpp │ ├── QasmPPFileCleaner.cpp │ ├── QasmParser.cpp │ └── QasmPathsResolver.cpp └── Parser │ ├── CMakeLists.txt │ ├── QasmParser.y │ ├── QasmScanner.cpp │ └── QasmScanner.l ├── licenses ├── bison-dual-license.txt └── flex-dual-license.txt ├── releasenotes └── config.yaml ├── requirements-dev.txt ├── tests ├── CMakeLists.txt ├── check-test-results.sh ├── cleanup-test-results.sh ├── include │ ├── qelib1.benchmark.inc │ ├── qelib1.inc │ ├── stdgates.inc │ └── stdopenpulse.inc ├── iqpe-tests.sh ├── run-tests.sh ├── short-run-tests.sh ├── src │ ├── adder_8.qasm │ ├── adder_n4.qasm │ ├── angle-theta.qasm │ ├── b1.qasm │ ├── barenco_tof_10.qasm │ ├── barenco_tof_3.qasm │ ├── barenco_tof_4.qasm │ ├── barenco_tof_5.qasm │ ├── barrier.qasm │ ├── bell_v0.qasm │ ├── bell_v1.qasm │ ├── bit.qasm │ ├── bits.qasm │ ├── ccx-v2.qasm │ ├── cherry.qasm │ ├── cphase.qasm │ ├── csla_mux_3.qasm │ ├── csum_mux_9.qasm │ ├── cycle_17_3.qasm │ ├── defcal-v2.qasm │ ├── f1.qasm │ ├── gf2^10_mult.qasm │ ├── gf2^128_mult.qasm │ ├── gf2^16_mult.qasm │ ├── gf2^256_mult.qasm │ ├── gf2^32_mult.qasm │ ├── gf2^4_mult.qasm │ ├── gf2^5_mult.qasm │ ├── gf2^64_mult.qasm │ ├── gf2^6_mult.qasm │ ├── gf2^7_mult.qasm │ ├── gf2^8_mult.qasm │ ├── gf2^9_mult.qasm │ ├── greeks.qasm │ ├── grover_5.qasm │ ├── hadamard.qasm │ ├── ham15-high.qasm │ ├── ham15-low.qasm │ ├── ham15-med.qasm │ ├── hwb10.qasm │ ├── hwb11.qasm │ ├── hwb12.qasm │ ├── hwb6.qasm │ ├── hwb8.qasm │ ├── i1.qasm │ ├── ifelse.qasm │ ├── iqpe-1.qasm │ ├── iqpe-10.qasm │ ├── iqpe-11.qasm │ ├── iqpe-2-3.qasm │ ├── iqpe-4.qasm │ ├── iqpe-5.qasm │ ├── iqpe-6.qasm │ ├── iqpe-7.qasm │ ├── iqpe-8.qasm │ ├── iqpe-9.qasm │ ├── mod5_4.qasm │ ├── mod_adder_1024.qasm │ ├── mod_adder_1048576.qasm │ ├── mod_mult_55.qasm │ ├── mod_red_21.qasm │ ├── newlineifelse.qasm │ ├── nospace-ifelse.qasm │ ├── q1.qasm │ ├── q2.qasm │ ├── qcla_adder_10.qasm │ ├── qcla_com_7.qasm │ ├── qcla_mod_7.qasm │ ├── qft.qasm │ ├── qft1.qasm │ ├── qft2.qasm │ ├── qft4.qasm │ ├── qft_4.qasm │ ├── qss-teleport.qasm │ ├── rc_adder_6.qasm │ ├── reset.qasm │ ├── reset_v0.qasm │ ├── reset_v1.qasm │ ├── rz.qasm │ ├── ta-5.qasm │ ├── ta3.qasm │ ├── teleportation-1.qasm │ ├── teleportation-2.qasm │ ├── teleportation-3.qasm │ ├── test-add-assign.qasm │ ├── test-all-int.qasm │ ├── test-angle-2.qasm │ ├── test-angle-array.qasm │ ├── test-angle-cast.qasm │ ├── test-angle.qasm │ ├── test-annotation-1.qasm │ ├── test-annotation-2.qasm │ ├── test-arith-negate.qasm │ ├── test-array-1.qasm │ ├── test-array-10.qasm │ ├── test-array-11.qasm │ ├── test-array-12.qasm │ ├── test-array-13.qasm │ ├── test-array-14.qasm │ ├── test-array-15.qasm │ ├── test-array-16.qasm │ ├── test-array-17.qasm │ ├── test-array-18.qasm │ ├── test-array-2.qasm │ ├── test-array-3.qasm │ ├── test-array-4.qasm │ ├── test-array-5.qasm │ ├── test-array-6.qasm │ ├── test-array-7.qasm │ ├── test-array-8.qasm │ ├── test-array-9.qasm │ ├── test-array-subscript.qasm │ ├── test-assign-pi.qasm │ ├── test-assign.qasm │ ├── test-bad-cal.qasm │ ├── test-bad-version.qasm │ ├── test-big-int.qasm │ ├── test-bit-1.qasm │ ├── test-bit-2.qasm │ ├── test-bit-3.qasm │ ├── test-bit-4.qasm │ ├── test-bit-5.qasm │ ├── test-bit-6.qasm │ ├── test-bit-7.qasm │ ├── test-bit-array-1.qasm │ ├── test-bit-gate-1.qasm │ ├── test-bit-gate-2.qasm │ ├── test-bit-gate-3.qasm │ ├── test-bit-gate-4.qasm │ ├── test-bit-gate-5.qasm │ ├── test-bit-measure.qasm │ ├── test-bit.qasm │ ├── test-bitnot.qasm │ ├── test-bitset-bitops.qasm │ ├── test-bitset-cast.qasm │ ├── test-bitset-int-cast.qasm │ ├── test-bitset.qasm │ ├── test-bool-2.qasm │ ├── test-bool-3.qasm │ ├── test-bool-cast.qasm │ ├── test-bool.qasm │ ├── test-box-1.qasm │ ├── test-box-2.qasm │ ├── test-box-3.qasm │ ├── test-box-4.qasm │ ├── test-builtins-1.qasm │ ├── test-c-comment.qasm │ ├── test-cal-1.qasm │ ├── test-cal-2.qasm │ ├── test-cal-complex.qasm │ ├── test-cast-bool.qasm │ ├── test-cbit-rref.qasm │ ├── test-chinese-simplified-utf8.qasm │ ├── test-chinese-traditional-utf8.qasm │ ├── test-complex-1.qasm │ ├── test-complex-10.qasm │ ├── test-complex-11.qasm │ ├── test-complex-12.qasm │ ├── test-complex-2.qasm │ ├── test-complex-3.qasm │ ├── test-complex-4.qasm │ ├── test-complex-5.qasm │ ├── test-complex-6.qasm │ ├── test-complex-7.qasm │ ├── test-complex-8.qasm │ ├── test-complex-9.qasm │ ├── test-complex-array-1.qasm │ ├── test-complex-array-2.qasm │ ├── test-complex-array-3.qasm │ ├── test-consecutive-gates-1.qasm │ ├── test-consecutive-gates-2.qasm │ ├── test-const-float.qasm │ ├── test-const-scalars.qasm │ ├── test-const.qasm │ ├── test-control-chain-1.qasm │ ├── test-cos.qasm │ ├── test-creg.qasm │ ├── test-ctrl.qasm │ ├── test-cx.qasm │ ├── test-defcal-binop.qasm │ ├── test-defcal-conversion.qasm │ ├── test-defcal-delay-1.qasm │ ├── test-defcal-delay-2.qasm │ ├── test-defcal-measure.qasm │ ├── test-defcal-reset.qasm │ ├── test-defcal-unop.qasm │ ├── test-defcal.qasm │ ├── test-delay-2.qasm │ ├── test-delay-3.qasm │ ├── test-delay-4.qasm │ ├── test-delay.qasm │ ├── test-do-while-1.qasm │ ├── test-do-while-2.qasm │ ├── test-do-while-3.qasm │ ├── test-do-while-4.qasm │ ├── test-do-while-5.qasm │ ├── test-dollar-qubit.qasm │ ├── test-dot-1.qasm │ ├── test-dot-2.qasm │ ├── test-duration-1.qasm │ ├── test-duration-2.qasm │ ├── test-duration-3.qasm │ ├── test-duration-array-1.qasm │ ├── test-duration-array-2.qasm │ ├── test-durationof-defcal.qasm │ ├── test-durationof-unaryop.qasm │ ├── test-eq.qasm │ ├── test-euler.qasm │ ├── test-extern-1.qasm │ ├── test-extern-2.qasm │ ├── test-extern-3.qasm │ ├── test-extern-4.qasm │ ├── test-fixed-scalars.qasm │ ├── test-fixed.qasm │ ├── test-for-1.qasm │ ├── test-for-2.qasm │ ├── test-for-3.qasm │ ├── test-for-4.qasm │ ├── test-for-5.qasm │ ├── test-for-6.qasm │ ├── test-for-7.qasm │ ├── test-frame-1.qasm │ ├── test-frame-2.qasm │ ├── test-frame-3.qasm │ ├── test-frame-array-1.qasm │ ├── test-func-1.qasm │ ├── test-func-10.qasm │ ├── test-func-2.qasm │ ├── test-func-3.qasm │ ├── test-func-4.qasm │ ├── test-func-5.qasm │ ├── test-func-55.qasm │ ├── test-func-6.qasm │ ├── test-func-7.qasm │ ├── test-func-8.qasm │ ├── test-func-9.qasm │ ├── test-func-call-1.qasm │ ├── test-func-call-10.qasm │ ├── test-func-call-2.qasm │ ├── test-func-call-3.qasm │ ├── test-func-call-4.qasm │ ├── test-func-call-5.qasm │ ├── test-func-call-6.qasm │ ├── test-func-call-7.qasm │ ├── test-func-call-8.qasm │ ├── test-func-call-9.qasm │ ├── test-func-call.qasm │ ├── test-function-gate-1.qasm │ ├── test-function-param-names.qasm │ ├── test-gate-1.qasm │ ├── test-gate-2.qasm │ ├── test-gate-3.qasm │ ├── test-gate-4.qasm │ ├── test-gate-control-1.qasm │ ├── test-gate-control-2.qasm │ ├── test-gate-cx.qasm │ ├── test-gate-gphase.qasm │ ├── test-gate-noangle.qasm │ ├── test-gate-pi.qasm │ ├── test-gate-qops.qasm │ ├── test-gate-qubit.qasm │ ├── test-gate-switch.qasm │ ├── test-gate.qasm │ ├── test-german-utf8.qasm │ ├── test-gphase-1.qasm │ ├── test-greek-1.qasm │ ├── test-hadamard-2.qasm │ ├── test-hadamard.qasm │ ├── test-hiragana-utf8.qasm │ ├── test-identifier-overloading.qasm │ ├── test-identifier.qasm │ ├── test-idref-scope.qasm │ ├── test-ifelse-1.qasm │ ├── test-ifelse-10.qasm │ ├── test-ifelse-11.qasm │ ├── test-ifelse-12.qasm │ ├── test-ifelse-13.qasm │ ├── test-ifelse-2.qasm │ ├── test-ifelse-3.qasm │ ├── test-ifelse-4.qasm │ ├── test-ifelse-5.qasm │ ├── test-ifelse-6.qasm │ ├── test-ifelse-7.qasm │ ├── test-ifelse-8.qasm │ ├── test-ifelse-9.qasm │ ├── test-include-1.qasm │ ├── test-include-2.qasm │ ├── test-include-3.qasm │ ├── test-include-4.qasm │ ├── test-include-5.qasm │ ├── test-include-c++-comment-1.qasm │ ├── test-include-c++-comment-2.qasm │ ├── test-include-c++-comment-3.qasm │ ├── test-include-c-comment-1.qasm │ ├── test-include-c-comment-2.qasm │ ├── test-include-c-comment-3.qasm │ ├── test-include-c-comment-4.qasm │ ├── test-induction-var-1.qasm │ ├── test-induction-var-2.qasm │ ├── test-induction-var-3.qasm │ ├── test-input.qasm │ ├── test-int-array.qasm │ ├── test-int-cast.qasm │ ├── test-int-int.qasm │ ├── test-inverse-trig-1.qasm │ ├── test-inverse-trig-2.qasm │ ├── test-isexc-1.qasm │ ├── test-isexc-2.qasm │ ├── test-isexc-3.qasm │ ├── test-isexc-4.qasm │ ├── test-katakana-utf8.qasm │ ├── test-kernel-1.qasm │ ├── test-kernel-2.qasm │ ├── test-kernel-3.qasm │ ├── test-kernel-4.qasm │ ├── test-korean-utf8.qasm │ ├── test-length-1.qasm │ ├── test-length-2.qasm │ ├── test-length.qasm │ ├── test-let-1.qasm │ ├── test-let-2.qasm │ ├── test-let-3.qasm │ ├── test-let-4.qasm │ ├── test-let-5.qasm │ ├── test-let-6.qasm │ ├── test-let.qasm │ ├── test-logical-bang.qasm │ ├── test-logical-or.qasm │ ├── test-mangled-complex.qasm │ ├── test-mangled-defcal.qasm │ ├── test-mangled-gates.qasm │ ├── test-measure-2.qasm │ ├── test-measure.qasm │ ├── test-modulo.qasm │ ├── test-mpd-binaryop.qasm │ ├── test-mpdecimal-array.qasm │ ├── test-mpdecimal.qasm │ ├── test-mpfloat.qasm │ ├── test-mpinteger-array.qasm │ ├── test-mpinteger.qasm │ ├── test-multi-else.qasm │ ├── test-multi-elseif-no-braces.qasm │ ├── test-multi-if-else.qasm │ ├── test-multi-if.qasm │ ├── test-multi-nested-elseif.qasm │ ├── test-neg-trig.qasm │ ├── test-negative-angle.qasm │ ├── test-negative-expression.qasm │ ├── test-negative-pi.qasm │ ├── test-nested-elseif.qasm │ ├── test-nested-for-loop-1.qasm │ ├── test-nested-if.qasm │ ├── test-nested-loop.qasm │ ├── test-nested-redeclarations.qasm │ ├── test-nested-while-loop-1.qasm │ ├── test-no-openqasm-line-1.qasm │ ├── test-no-openqasm-line-2.qasm │ ├── test-no-openqasm-line-3.qasm │ ├── test-not-logical.qasm │ ├── test-not.qasm │ ├── test-opaque.qasm │ ├── test-operators-2.qasm │ ├── test-operators.qasm │ ├── test-output.qasm │ ├── test-parity.qasm │ ├── test-phase.qasm │ ├── test-pi.qasm │ ├── test-play-1.qasm │ ├── test-play-2.qasm │ ├── test-popcount-2.qasm │ ├── test-popcount.qasm │ ├── test-port-array-1.qasm │ ├── test-pow-1.qasm │ ├── test-pow-2.qasm │ ├── test-pow-3.qasm │ ├── test-pow-int.qasm │ ├── test-pragma-1.qasm │ ├── test-pragma-2.qasm │ ├── test-pragma-3.qasm │ ├── test-qreg-v2.qasm │ ├── test-qreg-v3.qasm │ ├── test-qregs.qasm │ ├── test-qubit-2.qasm │ ├── test-qubit-array-1.qasm │ ├── test-qubit-concat.qasm │ ├── test-qubit.qasm │ ├── test-reset-defcal.qasm │ ├── test-reset-gate.qasm │ ├── test-reset.qasm │ ├── test-return-2.qasm │ ├── test-return-3.qasm │ ├── test-return-xor.qasm │ ├── test-return.qasm │ ├── test-rotl.qasm │ ├── test-rotr.qasm │ ├── test-run-defcal-1.qasm │ ├── test-run-defcal-2.qasm │ ├── test-russian-utf8.qasm │ ├── test-rz-1.qasm │ ├── test-rz-2.qasm │ ├── test-scalars.qasm │ ├── test-sci-gate.qasm │ ├── test-scope-1.qasm │ ├── test-scope-2.qasm │ ├── test-sequence-elseif.qasm │ ├── test-shadow.qasm │ ├── test-shift-1.qasm │ ├── test-shift-2.qasm │ ├── test-shift-3.qasm │ ├── test-sign-1.qasm │ ├── test-sign-2.qasm │ ├── test-sin.qasm │ ├── test-stretch.qasm │ ├── test-sub.qasm │ ├── test-subscript-1.qasm │ ├── test-swedish-utf8.qasm │ ├── test-switch-1.qasm │ ├── test-switch-2.qasm │ ├── test-switch-3.qasm │ ├── test-switch-4.qasm │ ├── test-tau.qasm │ ├── test-u-1.qasm │ ├── test-ugate-1.qasm │ ├── test-ugate-2.qasm │ ├── test-ugate-3.qasm │ ├── test-uint.qasm │ ├── test-umlaut-utf8.qasm │ ├── test-unary-ops.qasm │ ├── test-unary-pi.qasm │ ├── test-underscore-1-utf8.qasm │ ├── test-underscore-2-utf8.qasm │ ├── test-underscore-3-utf8.qasm │ ├── test-unicode-epislon-gate.qasm │ ├── test-unicode.qasm │ ├── test-void-measure.qasm │ ├── test-waveform-1.qasm │ ├── test-waveform-2.qasm │ ├── test-waveform-3.qasm │ ├── test-waveform-4.qasm │ ├── test-waveform-5.qasm │ ├── test-while-1.qasm │ ├── test-while-2.qasm │ ├── test-while-3.qasm │ ├── test-xcheck.qasm │ ├── test-xor-1.qasm │ ├── test.qasm │ ├── tf5.qasm │ ├── tof_10.qasm │ ├── tof_3.qasm │ ├── tof_4.qasm │ ├── tof_5.qasm │ └── vbe_adder_3.qasm └── teleport-tests.sh └── utils ├── sed-bison-output.sh ├── sed-flex-output.sh └── update-license.sh /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | --- 4 | Language: Cpp 5 | AlwaysBreakTemplateDeclarations: Yes 6 | RemoveBracesLLVM: Yes 7 | --- 8 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This file defines the set of people responsible for different sections of the 2 | # codebase 3 | # 4 | # Being listed as a code owner on a section here means that user is empowered 5 | # to approve and merge pull requests for that section of code. It also comes 6 | # with an expected responsibility to review and maintain those subsections of 7 | # the repository. 8 | # 9 | # A PR can be merged when approved by at least one codeowner. For PRs that touch 10 | # more than one section with non-overlapping codeowners more than one codeowner 11 | # may be required to approve a PR. 12 | # 13 | # However, every contributor to the project can (and should!) review open PRs. This 14 | # file is just about outlining responsibility for maintainership and final 15 | # review/merging of PRs in different subsections of the repository. 16 | 17 | # Global rule, unless specialized by a later one 18 | * @openqasm/qe-maintainers 19 | 20 | # folders (also their corresponding tests) 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # 35 | VERSION.txt 36 | build/ 37 | CMakeUserPresets.json 38 | -------------------------------------------------------------------------------- /LICENSING_INFO.md: -------------------------------------------------------------------------------- 1 | Licensing Information for qss-qasm dependencies 2 | =============================================== 3 | 4 | `qss-qasm` imports interfaces from the GNU Multiple Precision Arithmetic Library: 5 | 6 | https://gmplib.org/ 7 | 8 | For the avoidance of doubt and/or ambiguity, `qss-qasm` elects the GNU Lesser 9 | General Public License Version 3 (LGPLv3) for the GNU Multiple Precision Arithmetic 10 | Library. 11 | -------------------------------------------------------------------------------- /cmake/modules/Findgmp.cmake: -------------------------------------------------------------------------------- 1 | # Try to find the GNU Multiple Precision Arithmetic Library (GMP) 2 | # See http://gmplib.org/ 3 | 4 | if (gmp_INCLUDES AND gmp_LIBRARIES) 5 | set(gmp_FIND_QUIETLY TRUE) 6 | endif (gmp_INCLUDES AND gmp_LIBRARIES) 7 | 8 | find_path(gmp_INCLUDES 9 | NAMES 10 | gmp.h 11 | PATHS 12 | $ENV{GMPDIR} 13 | ${INCLUDE_INSTALL_DIR} 14 | ) 15 | 16 | find_library(gmp_LIBRARIES gmp PATHS $ENV{GMPDIR} ${LIB_INSTALL_DIR}) 17 | 18 | include(FindPackageHandleStandardArgs) 19 | find_package_handle_standard_args(gmp DEFAULT_MSG 20 | gmp_INCLUDES gmp_LIBRARIES) 21 | mark_as_advanced(gmp_INCLUDES gmp_LIBRARIES) 22 | 23 | if(NOT ${CMAKE_VERSION} VERSION_LESS "3.0") 24 | # Target approach 25 | if(NOT TARGET gmp::gmp) 26 | add_library(gmp::gmp INTERFACE IMPORTED) 27 | set_target_properties(gmp::gmp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 28 | "${gmp_INCLUDES}") 29 | set_target_properties(gmp::gmp PROPERTIES INTERFACE_LINK_LIBRARIES 30 | "${gmp_LIBRARIES}") 31 | endif() 32 | endif() 33 | -------------------------------------------------------------------------------- /conandata.yml: -------------------------------------------------------------------------------- 1 | requirements: 2 | - "gmp/6.3.0" 3 | - "mpfr/4.2.1" 4 | - "mpc/1.3.1" 5 | - "bison/3.8.2" 6 | - "flex/2.6.4" 7 | build_requirements: 8 | - "bison/3.8.2" 9 | - "flex/2.6.4" 10 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OPENQASM_EXAMPLES QasmParser QDem) 2 | 3 | if(OPENQASM_BUILD_EXAMPLES) 4 | foreach(program ${OPENQASM_EXAMPLES}) 5 | add_executable(${program} ${program}/${program}.cpp) 6 | message(STATUS "Building ${program} ...") 7 | target_include_directories(${program} PRIVATE ${OPENQASM_INCLUDE_DIR}) 8 | target_include_directories(${program} PUBLIC 9 | $ 10 | $ 11 | $ 12 | $) 13 | target_link_libraries(${program} PUBLIC ${OPENQASM_LIBRARIES} mpc::mpc mpfr::mpfr gmp::gmp) 14 | endforeach() 15 | 16 | add_custom_target(examples ALL DEPENDS 17 | ${OPENQASM_LIBRARIES} 18 | ${OPENQASM_EXAMPLES} 19 | ) 20 | endif() 21 | 22 | if (OPENQASM_BUILD_EXAMPLES) 23 | install(TARGETS ${OPENQASM_EXAMPLES} ${INSTALL_EXPORT} 24 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 25 | ) 26 | endif() 27 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(qasm) 2 | -------------------------------------------------------------------------------- /include/qasm/AST/ASTAnyType.h: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #ifndef __QASM_AST_ANY_TYPE_H 20 | #define __QASM_AST_ANY_TYPE_H 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | namespace QASM { 28 | 29 | typedef std::pair ASTAnyType; 30 | 31 | } // namespace QASM 32 | 33 | #endif // __QASM_AST_ANY_TYPE_H 34 | -------------------------------------------------------------------------------- /include/qasm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(GNUInstallDirs) 2 | 3 | set(OPENQASM_INCLUDE_DIRS "AST" "Frontend" "QPP" "Diagnostic") 4 | 5 | install(DIRECTORY ${OPENQASM_INCLUDE_DIRS} 6 | FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ 7 | DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE 8 | GROUP_READ GROUP_EXECUTE 9 | WORLD_READ WORLD_EXECUTE 10 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qasm) 11 | -------------------------------------------------------------------------------- /lib/AST/ASTAnyTypeBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2022 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTAnyTypeBuilder ASTAnyTypeBuilder::ATB; 24 | ASTAnyTypeList ASTAnyTypeBuilder::ATL; 25 | ASTAnyTypeList *ASTAnyTypeBuilder::ATP; 26 | std::vector ASTAnyTypeBuilder::ALV; 27 | 28 | } // namespace QASM 29 | -------------------------------------------------------------------------------- /lib/AST/ASTBoxStatementBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTBoxStatementBuilder ASTBoxStatementBuilder::BSB; 24 | ASTStatementList ASTBoxStatementBuilder::VS; 25 | 26 | } // namespace QASM 27 | -------------------------------------------------------------------------------- /lib/AST/ASTCBitNodeMap.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTCBitNodeMap ASTCBitNodeMap::MI; 24 | std::map ASTCBitNodeMap::MM; 25 | 26 | } // namespace QASM 27 | -------------------------------------------------------------------------------- /lib/AST/ASTCtrlAssocBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTCtrlAssocList ASTCtrlAssocListBuilder::CAL; 24 | ASTCtrlAssocListBuilder ASTCtrlAssocListBuilder::CAB; 25 | 26 | } // namespace QASM 27 | -------------------------------------------------------------------------------- /lib/AST/ASTExpressionBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTExpressionList *ASTExpressionBuilder::EL; 24 | ASTExpressionBuilder ASTExpressionBuilder::B; 25 | 26 | } // namespace QASM 27 | -------------------------------------------------------------------------------- /lib/AST/ASTForRangeInitBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTForRangeInitList ASTForRangeInitListBuilder::RIL; 24 | ASTForRangeInitListBuilder ASTForRangeInitListBuilder::RIB; 25 | 26 | } // namespace QASM 27 | -------------------------------------------------------------------------------- /lib/AST/ASTGateNodeBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | namespace QASM { 24 | 25 | ASTGateNodeList ASTGateNodeBuilder::NL; 26 | ASTGateNodeBuilder ASTGateNodeBuilder::B; 27 | 28 | } // namespace QASM 29 | -------------------------------------------------------------------------------- /lib/AST/ASTIntegerSequenceBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTIntegerSequenceBuilder ASTIntegerSequenceBuilder::ISB; 24 | 25 | } // namespace QASM 26 | -------------------------------------------------------------------------------- /lib/AST/ASTInverseAssocBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTInverseAssocList ASTInverseAssocListBuilder::IAL; 24 | ASTInverseAssocListBuilder ASTInverseAssocListBuilder::IAB; 25 | 26 | } // namespace QASM 27 | -------------------------------------------------------------------------------- /lib/AST/ASTLoops.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2022 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | namespace QASM { 23 | 24 | void ASTForLoopRangeExpressionNode::Mangle() { 25 | ASTMangler M; 26 | M.Start(); 27 | M.Type(ASTTypeForLoopRange); 28 | M.EndExpression(); 29 | M.End(); 30 | } 31 | 32 | } // namespace QASM 33 | -------------------------------------------------------------------------------- /lib/AST/ASTNamedTypeDeclarationBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTDeclarationList ASTNamedTypeDeclarationBuilder::DL; 24 | ASTDeclarationMap ASTNamedTypeDeclarationBuilder::DM; 25 | ASTNamedTypeDeclarationBuilder ASTNamedTypeDeclarationBuilder::DB; 26 | 27 | } // namespace QASM 28 | -------------------------------------------------------------------------------- /lib/AST/ASTQubitConcatBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2022 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTQubitConcatList *ASTQubitConcatListBuilder::IL; 24 | ASTQubitConcatListBuilder ASTQubitConcatListBuilder::QCB; 25 | std::vector ASTQubitConcatListBuilder::ILV; 26 | 27 | } // namespace QASM 28 | -------------------------------------------------------------------------------- /lib/AST/ASTQubitNodeBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | namespace QASM { 24 | 25 | ASTQubitNodeMap ASTQubitNodeBuilder::QM; 26 | ASTQubitNodeBuilder ASTQubitNodeBuilder::B; 27 | 28 | } // namespace QASM 29 | -------------------------------------------------------------------------------- /lib/AST/ASTStringList.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2022 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | ASTStringList ASTStringListBuilder::SL; 24 | ASTStringListBuilder ASTStringListBuilder::SLB; 25 | ASTStringList *ASTStringListBuilder::SLP; 26 | std::vector ASTStringListBuilder::SLV; 27 | 28 | } // namespace QASM 29 | -------------------------------------------------------------------------------- /lib/AST/DIAGLineBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | DIAGLineBuffer DIAGLineBuffer::DLB; 24 | 25 | } // namespace QASM 26 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckCXXSourceCompiles) 2 | include(CheckIncludeFileCXX) 3 | include(CheckTypeSize) 4 | include(CheckStructHasMember) 5 | include(CheckCXXSymbolExists) 6 | 7 | list(APPEND REQUIRED_FEATURES 8 | cxx_std_17 9 | cxx_auto_type 10 | cxx_decltype 11 | cxx_default_function_template_args 12 | cxx_defaulted_functions 13 | cxx_delegating_constructors 14 | cxx_enum_forward_declarations 15 | cxx_explicit_conversions 16 | cxx_extended_friend_declarations 17 | cxx_extern_templates 18 | cxx_final 19 | cxx_lambdas 20 | cxx_long_long_type 21 | cxx_nullptr 22 | cxx_override 23 | cxx_range_for 24 | cxx_raw_string_literals 25 | cxx_right_angle_brackets 26 | cxx_rvalue_references 27 | cxx_static_assert 28 | cxx_strong_enums 29 | cxx_trailing_return_types 30 | cxx_uniform_initialization 31 | cxx_variadic_macros 32 | cxx_variadic_templates 33 | ) 34 | 35 | add_subdirectory(Parser) 36 | add_subdirectory(AST) 37 | add_subdirectory(Frontend) 38 | add_subdirectory(Diagnostic) 39 | -------------------------------------------------------------------------------- /lib/Diagnostic/DIAGLineBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | DIAGLineBuffer DIAGLineBuffer::DLB; 24 | 25 | } // namespace QASM 26 | -------------------------------------------------------------------------------- /lib/Frontend/QasmParser.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2020 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | void ASTParser::ParseCommandLineArguments(int argc, char *const argv[]) { 24 | QasmPreprocessor::Instance().ParseCommandLineArguments(argc, argv); 25 | } 26 | 27 | } // namespace QASM 28 | -------------------------------------------------------------------------------- /lib/Parser/QasmScanner.cpp: -------------------------------------------------------------------------------- 1 | /* -*- coding: utf-8 -*- 2 | * 3 | * Copyright 2021 IBM RESEARCH. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ============================================================================= 17 | */ 18 | 19 | #include 20 | 21 | namespace QASM { 22 | 23 | std::vector ASTScanner::SV; 24 | 25 | using token = QASM::Parser::token; 26 | int ASTScanner::start_openqasm = token::TOK_START_OPENQASM; 27 | int ASTScanner::start_openpulse = token::TOK_START_OPENPULSE; 28 | 29 | } // namespace QASM 30 | -------------------------------------------------------------------------------- /releasenotes/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | encoding: utf8 3 | default_branch: main 4 | collapse_pre_releases: true 5 | branch_name_prefix: release/ 6 | branch_name_re: release/.+ 7 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | cmake 2 | conan<2.0 3 | pre-commit 4 | setuptools_scm>=6.0,<8.0 5 | -------------------------------------------------------------------------------- /tests/check-test-results.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export HERE="`pwd`" 4 | export TESTFILE="${HERE}/tests.run.out" 5 | 6 | NT="`cat ${TESTFILE} | wc -l`" 7 | echo "There are ${NT} tests." 8 | 9 | while read -r file 10 | do 11 | echo "--------------------------------------" 12 | TESTNAME="`echo ${file} | sed 's#.out##g'`" 13 | echo "Test Program: ${TESTNAME}" 14 | echo "Test Output : ${file}" 15 | echo -n "Status: " 16 | egrep '^OK.|fail|Fail|error|Error' ${file} 17 | echo "--------------------------------------" 18 | done < ${TESTFILE} 19 | -------------------------------------------------------------------------------- /tests/cleanup-test-results.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -f *.qasm.out 4 | -------------------------------------------------------------------------------- /tests/include/stdopenpulse.inc: -------------------------------------------------------------------------------- 1 | // stdopenpulse.inc - Standard OpenPulse header file 2 | // Defines standard operations on Frames. 3 | 4 | defcalgrammar "openpulse"; 5 | 6 | def set_phase(frame f, angle ph) { 7 | f.phase = ph; 8 | } 9 | 10 | def get_phase(frame f) -> angle { 11 | return f.phase; 12 | } 13 | 14 | def shift_phase(frame f, angle ph) { 15 | f.phase = ph; 16 | } 17 | 18 | def set_frequency(frame f, float freq) { 19 | f.frequency = freq; 20 | } 21 | 22 | def get_frequency(frame f) -> float { 23 | return f.frequency; 24 | } 25 | 26 | def shift_frequency(frame f, float freq) { 27 | f.frequency = freq; 28 | } 29 | -------------------------------------------------------------------------------- /tests/iqpe-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export HERE="`pwd`" 4 | export RED='\033[0;31m' 5 | export GREEN='\033[0;32m' 6 | export NC='\033[0m' 7 | 8 | # Set the following two paths to the ${TOP_SRCDIR}/tests directory: 9 | export TESTDIR="${HERE}/../../qasm/tests/src" 10 | export TESTINC="${HERE}/../../qasm/tests/include" 11 | export TESTLOG="${HERE}/tests.run.out" 12 | cat /dev/null > ${TESTLOG} 13 | 14 | # Set this path to the QasmParser example program: 15 | export QASMPARSER="${HERE}/QasmParser" 16 | export TESTLIST="/tmp/qasm-tests.$$" 17 | ls -1 iqpe-*.qasm > ${TESTLIST} 18 | 19 | cd ${HERE} 20 | 21 | while read -r file 22 | do 23 | printf "Testing ${file} ... " 24 | echo "${file}.out" >> ${TESTLOG} 2>&1 25 | ${QASMPARSER} -I${TESTINC} ${TESTDIR}/${file} > "${file}.out" 2>&1 26 | 27 | if [ $? -ne 0 ] ; then 28 | printf "${RED}FAILED!${NC}\n" 29 | else 30 | printf "${GREEN}OK.${NC}\n" 31 | fi 32 | done < ${TESTLIST} 33 | 34 | rm -f ${TESTLIST} 35 | -------------------------------------------------------------------------------- /tests/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export HERE="`pwd`" 4 | export RED='\033[0;31m' 5 | export GREEN='\033[0;32m' 6 | export NC='\033[0m' 7 | 8 | # Set the following two paths to the ${TOP_SRCDIR}/tests directory: 9 | export TESTDIR="${HERE}/../../qasm/tests/src" 10 | export TESTINC="${HERE}/../../qasm/tests/include" 11 | export TESTLOG="${HERE}/tests.run.out" 12 | cat /dev/null > ${TESTLOG} 13 | 14 | # Set this path to the QasmParser example program: 15 | export QASMPARSER="${HERE}/QasmParser" 16 | 17 | cd ${TESTDIR} 18 | 19 | export TESTLIST="/tmp/qasm-tests.$$" 20 | ls -1 *.qasm > ${TESTLIST} 21 | 22 | cd ${HERE} 23 | 24 | while read -r file 25 | do 26 | printf "Testing ${file} ... " 27 | echo "${file}.out" >> ${TESTLOG} 2>&1 28 | ${QASMPARSER} -I${TESTINC} ${TESTDIR}/${file} > "${file}.out" 2>&1 29 | 30 | if [ $? -ne 0 ] ; then 31 | printf "${RED}FAILED!${NC}\n" 32 | else 33 | printf "${GREEN}OK.${NC}\n" 34 | fi 35 | done < ${TESTLIST} 36 | 37 | rm -f ${TESTLIST} 38 | -------------------------------------------------------------------------------- /tests/src/adder_n4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | include "qelib1.benchmark.inc"; 4 | 5 | qreg q[4]; 6 | creg c[4]; 7 | 8 | x q[0]; 9 | x q[1]; 10 | h q[3]; 11 | cx q[2],q[3]; 12 | t q[0]; 13 | t q[1]; 14 | t q[2]; 15 | tdg q[3]; 16 | cx q[0],q[1]; 17 | cx q[2],q[3]; 18 | cx q[3],q[0]; 19 | cx q[1],q[2]; 20 | cx q[0],q[1]; 21 | cx q[2],q[3]; 22 | tdg q[0]; 23 | tdg q[1]; 24 | tdg q[2]; 25 | t q[3]; 26 | cx q[0],q[1]; 27 | cx q[2],q[3]; 28 | s q[3]; 29 | cx q[3],q[0]; 30 | h q[3]; 31 | measure q[0] -> c[0]; 32 | measure q[1] -> c[1]; 33 | measure q[2] -> c[2]; 34 | measure q[3] -> c[3]; 35 | -------------------------------------------------------------------------------- /tests/src/angle-theta.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x a { 4 | U(π, 0, π) a; 5 | } 6 | 7 | gate cx a, b { 8 | ctrl @ x a, b; 9 | } 10 | 11 | gate rx(theta) a { 12 | U(theta, -pi / 2, pi / 2) a; 13 | } 14 | 15 | gate phase(λ) q { 16 | U(0, 0, λ) q; 17 | } 18 | 19 | gate cu(theta, phi, lambda) c, t { 20 | phase((lambda - phi) / 2) t; 21 | cx c, t; 22 | U(-theta / 2, 0, -(phi + lambda) / 2) t; 23 | cx c, t; 24 | U(theta / 2, phi, 0) t; 25 | } 26 | -------------------------------------------------------------------------------- /tests/src/b1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bool a; 4 | 5 | bool b = false; 6 | 7 | bool c = 3; 8 | 9 | bool d = 4; 10 | 11 | bool e, f, g = true; 12 | 13 | bool i, j, k = 0; 14 | -------------------------------------------------------------------------------- /tests/src/barenco_tof_3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[5]; 5 | ccx qubits[2],qubits[3],qubits[4]; 6 | ccx qubits[0],qubits[1],qubits[3]; 7 | ccx qubits[2],qubits[3],qubits[4]; 8 | ccx qubits[0],qubits[1],qubits[3]; 9 | -------------------------------------------------------------------------------- /tests/src/barenco_tof_4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[7]; 5 | ccx qubits[3],qubits[5],qubits[6]; 6 | ccx qubits[2],qubits[4],qubits[5]; 7 | ccx qubits[0],qubits[1],qubits[4]; 8 | ccx qubits[2],qubits[4],qubits[5]; 9 | ccx qubits[3],qubits[5],qubits[6]; 10 | ccx qubits[2],qubits[4],qubits[5]; 11 | ccx qubits[0],qubits[1],qubits[4]; 12 | ccx qubits[2],qubits[4],qubits[5]; 13 | -------------------------------------------------------------------------------- /tests/src/barenco_tof_5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[9]; 5 | ccx qubits[4],qubits[7],qubits[8]; 6 | ccx qubits[3],qubits[6],qubits[7]; 7 | ccx qubits[2],qubits[5],qubits[6]; 8 | ccx qubits[0],qubits[1],qubits[5]; 9 | ccx qubits[2],qubits[5],qubits[6]; 10 | ccx qubits[3],qubits[6],qubits[7]; 11 | ccx qubits[4],qubits[7],qubits[8]; 12 | ccx qubits[3],qubits[6],qubits[7]; 13 | ccx qubits[2],qubits[5],qubits[6]; 14 | ccx qubits[0],qubits[1],qubits[5]; 15 | ccx qubits[2],qubits[5],qubits[6]; 16 | ccx qubits[3],qubits[6],qubits[7]; 17 | -------------------------------------------------------------------------------- /tests/src/barrier.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[8] qq; 6 | qubit[8] rr; 7 | qubit[8] ss; 8 | 9 | // Block 1 10 | cx rr[0], rr[1]; 11 | h qq[0]; 12 | 13 | // Block 2 14 | h ss[0]; 15 | barrier rr, qq[0]; 16 | h ss[0]; 17 | 18 | // Block 3 19 | cx rr[1], rr[0]; 20 | cx rr[0], rr[1]; 21 | -------------------------------------------------------------------------------- /tests/src/bell_v0.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // Qiskit will provide physical qubits 6 | qubit $0; 7 | qubit $1; 8 | 9 | // Array of classical bits is fine 10 | bit c0; 11 | bit c1; 12 | 13 | U(pi / 2, 0.0, pi) $0; 14 | cx $0, $1; 15 | 16 | measure $0 -> c0; 17 | measure $1 -> c1; 18 | -------------------------------------------------------------------------------- /tests/src/bell_v1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // Qiskit will provide physical qubits 6 | qubit $0; 7 | qubit $1; 8 | 9 | // Array of classical bits is fine 10 | bit[2] k; 11 | 12 | h $0; 13 | cx $0, $1; 14 | 15 | measure $0 -> k[0]; 16 | measure $1 -> k[1]; 17 | -------------------------------------------------------------------------------- /tests/src/bit.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] k; 4 | 5 | array[bit[16], 8] ka; 6 | -------------------------------------------------------------------------------- /tests/src/bits.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 32; 4 | 5 | bit[n] cb; 6 | -------------------------------------------------------------------------------- /tests/src/ccx-v2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | gate h a 4 | { 5 | u2(0,pi) a; 6 | } 7 | 8 | gate ccx a,b,c 9 | { 10 | h c; 11 | cx b,c; tdg c; 12 | cx a,c; t c; 13 | cx b,c; tdg c; 14 | cx a,c; t b; t c; h c; 15 | cx a,b; t a; tdg b; 16 | cx a,b; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/cherry.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate u4(cherry, peach, apricot) q { 4 | U(cherry, peach, apricot) q; 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/cphase.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[16] q; 6 | 7 | cphase(pi / 2) q[0], q[1]; 8 | 9 | // Two-argument 10 | gate cv(theta, lambda) c, w { 11 | // implements controlled-U(theta, lambda) with target w and control c 12 | phase((lambda - theta) / 2) t; 13 | cx c, w; 14 | U(-theta / 2, 0, -lambda / 2) w; 15 | cx c, w; 16 | U(theta / 2, lambda, 0) w; 17 | } 18 | 19 | cv(pi / 2) q[2], q[3], q[4]; 20 | 21 | cu(pi / 2) q[5], q[6], q[7], q[8]; 22 | -------------------------------------------------------------------------------- /tests/src/csla_mux_3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[15]; 5 | ccx qubits[1],qubits[2],qubits[3]; 6 | ccx qubits[5],qubits[6],qubits[7]; 7 | ccx qubits[10],qubits[11],qubits[12]; 8 | cx qubits[1],qubits[2]; 9 | cx qubits[3],qubits[4]; 10 | cx qubits[5],qubits[6]; 11 | cx qubits[7],qubits[9]; 12 | cx qubits[10],qubits[11]; 13 | cx qubits[12],qubits[14]; 14 | cx qubits[2],qubits[3]; 15 | cx qubits[11],qubits[13]; 16 | ccx qubits[4],qubits[6],qubits[9]; 17 | ccx qubits[3],qubits[6],qubits[7]; 18 | ccx qubits[9],qubits[11],qubits[14]; 19 | ccx qubits[7],qubits[11],qubits[12]; 20 | cx qubits[6],qubits[8]; 21 | cx qubits[3],qubits[6]; 22 | cx qubits[7],qubits[11]; 23 | cx qubits[4],qubits[8]; 24 | cx qubits[9],qubits[13]; 25 | cx qubits[14],qubits[12]; 26 | cx qubits[13],qubits[11]; 27 | cx qubits[8],qubits[6]; 28 | ccx qubits[0],qubits[12],qubits[14]; 29 | ccx qubits[0],qubits[11],qubits[13]; 30 | ccx qubits[0],qubits[6],qubits[8]; 31 | cx qubits[14],qubits[12]; 32 | cx qubits[13],qubits[11]; 33 | cx qubits[8],qubits[6]; 34 | cx qubits[0],qubits[2]; 35 | -------------------------------------------------------------------------------- /tests/src/defcal-v2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | include "qelib1.inc"; 4 | 5 | qreg qubits[32]; 6 | 7 | // 1. Defcal declaration with parameter and qubit argument.. 8 | defcal rz(angle[20]:theta) %q { } 9 | 10 | // 2. Defcal declaration with parameter and qubit argument. 11 | defcal rx(angle[20]:theta) %0 { } 12 | 13 | // 3. Defcal declaration with measure. 14 | defcal measure %q -> bit { } 15 | 16 | // 4. Defcal measure declaration with implicit grammar declaration. 17 | defcal "openpulse" measure %q -> bit { } 18 | 19 | // 5. Defcal declaration with no parameters. 20 | defcal d %0 { } 21 | 22 | // 6. Defcal declaration with no parameters. 23 | defcal d %1 { } 24 | 25 | // 7. Defcal declaration with implicit (pi) parameter. 26 | defcal rx(pi) %0 { } 27 | 28 | // 8. Defcal declaration with expression parameter based on pi. 29 | defcal rx(pi / 2) %0 { } 30 | 31 | // 9. Defcalgrammar declaration for "openpulse". 32 | defcalgrammar "openpulse"; 33 | -------------------------------------------------------------------------------- /tests/src/f1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float f; 4 | 5 | float e = 11.9; 6 | 7 | float a, b, c; 8 | 9 | float f, g, j = 31.8; 10 | 11 | float[128] xa, xb, xc; 12 | 13 | float[128] xf, xg, xj = 39.7; 14 | -------------------------------------------------------------------------------- /tests/src/gf2^4_mult.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[12]; 5 | ccx qubits[3],qubits[5],qubits[8]; 6 | ccx qubits[2],qubits[6],qubits[8]; 7 | ccx qubits[1],qubits[7],qubits[8]; 8 | ccx qubits[3],qubits[6],qubits[9]; 9 | ccx qubits[2],qubits[7],qubits[9]; 10 | ccx qubits[3],qubits[7],qubits[10]; 11 | cx qubits[10],qubits[11]; 12 | cx qubits[9],qubits[10]; 13 | cx qubits[8],qubits[9]; 14 | ccx qubits[3],qubits[4],qubits[11]; 15 | ccx qubits[2],qubits[5],qubits[11]; 16 | ccx qubits[1],qubits[6],qubits[11]; 17 | ccx qubits[0],qubits[7],qubits[11]; 18 | ccx qubits[2],qubits[4],qubits[10]; 19 | ccx qubits[1],qubits[5],qubits[10]; 20 | ccx qubits[0],qubits[6],qubits[10]; 21 | ccx qubits[1],qubits[4],qubits[9]; 22 | ccx qubits[0],qubits[5],qubits[9]; 23 | ccx qubits[0],qubits[4],qubits[8]; 24 | -------------------------------------------------------------------------------- /tests/src/greeks.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | // --- QE Hardware primitives --- 4 | 5 | // 3-parameter 2-pulse single qubit gate 6 | gate u3(θ,φ,λ) q { U(θ,φ,λ) q; } 7 | 8 | // 2-parameter 1-pulse single qubit gate 9 | gate u2(φ,λ) q { U(π/2,φ,λ) q; } 10 | 11 | // 1-parameter 0-pulse single qubit gate 12 | gate u1(λ) q { U(0,0,λ) q; } 13 | 14 | // Pauli gate: bit-flip 15 | gate x a { u3(π,0,π) a; } 16 | 17 | // Pauli gate: bit and phase flip 18 | gate y a { u3(π,π/2,π/2) a; } 19 | 20 | // Pauli gate: phase flip 21 | gate z a { u1(π) a; } 22 | 23 | // Clifford gate: Hadamard 24 | gate h a { u2(0,π) a; } 25 | 26 | // Clifford gate: sqrt(Z) phase gate 27 | gate s a { u1(π/2) a; } 28 | 29 | // Clifford gate: conjugate of sqrt(Z) 30 | gate sdg a { u1(-π/2) a; } 31 | 32 | // C3 gate: sqrt(S) phase gate 33 | gate t a { u1(π/4) a; } 34 | 35 | // C3 gate: conjugate of sqrt(S) 36 | gate tdg a { u1(-π/4) a; } 37 | 38 | if (tdg == a) { 39 | u1(-π / 4) a; 40 | } else { 41 | u1(-π / 2) a; 42 | } 43 | 44 | if (tdg == a) { 45 | u1(-π / 4) a; 46 | CX c,t; 47 | u3(π,0,π) a; 48 | } else { 49 | u1(-π / 2) a; 50 | u3(π,0,π) a; 51 | } 52 | -------------------------------------------------------------------------------- /tests/src/hadamard.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate h a { 4 | U(pi / 2, 0, pi) a; 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/i1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int m; 4 | 5 | int n = 3; 6 | 7 | int a, b, c; 8 | 9 | int d, e = 1; 10 | 11 | uint g, k, i; 12 | 13 | uint j, o = 2; 14 | 15 | int[64] xa, xb, xc; 16 | 17 | int[64] xj, xo = 5; 18 | -------------------------------------------------------------------------------- /tests/src/iqpe-2-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // 2 & 3. simplify gate modifiers and substitute constants 6 | 7 | qubit q; 8 | qubit r; 9 | angle[3] c = 0; 10 | reset q; 11 | reset r; 12 | h r; 13 | uint[3] power = 1; 14 | 15 | for i in [0: 2] { 16 | reset q; 17 | h q; 18 | cphase(power*3*pi/8) q, r; 19 | phase(-c) q; 20 | h q; 21 | measure q -> c[0]; 22 | c <<= 1; 23 | power <<= 1; 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/iqpe-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // 4. loop unrolling 6 | 7 | qubit q; 8 | qubit r; 9 | angle[3] c = 0; 10 | reset q; 11 | reset r; 12 | h r; 13 | uint[3] power = 1; 14 | reset q; 15 | h q; 16 | cphase(power * 3 * pi / 8) q, r; 17 | phase(-c) q; 18 | h q; 19 | measure q -> c[0]; 20 | c <<= 1; 21 | power <<= 1; 22 | reset q; 23 | h q; 24 | cphase(power * 3 * pi / 8) q, r; 25 | phase(-c) q; 26 | h q; 27 | measure q -> c[0]; 28 | c <<= 1; 29 | power <<= 1; 30 | reset q; 31 | h q; 32 | cphase(power * 3 * pi / 8) q, r; 33 | phase(-c) q; 34 | h q; 35 | measure q -> c[0]; 36 | c <<= 1; 37 | power <<= 1; 38 | -------------------------------------------------------------------------------- /tests/src/iqpe-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | angle[3] c = 0; 8 | reset q; 9 | reset r; 10 | h r; 11 | reset q; // <-- another pass could optimize and remove this line 12 | h q; 13 | cphase(3 * pi / 8) q, r; 14 | phase(0 * pi) q; // <-- another pass could optimize and remove this line 15 | h q; 16 | measure q -> c[0]; 17 | c <<= 1; 18 | reset q; 19 | h q; 20 | cphase(6 *pi / 8) q, r; 21 | phase(-c) q; 22 | h q; 23 | measure q -> c[0]; 24 | c <<= 1; 25 | reset q; 26 | h q; 27 | cphase(12 * pi / 8) q, r; 28 | phase(-c) q; 29 | h q; 30 | measure q -> c[0]; 31 | c <<= 1; 32 | -------------------------------------------------------------------------------- /tests/src/iqpe-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // 6. basis translation 6 | 7 | // gate phase(lambda) q { U(0, 0, lambda) q; } 8 | // gate cx c, t { CX c, t; } 9 | // gate h a { U(pi / 2, 0, pi) a; } 10 | 11 | qubit q; 12 | qubit r; 13 | angle[3] c = 0; 14 | reset q; 15 | reset r; 16 | h r; 17 | h q; 18 | phase(3 * pi / 16) q; 19 | cx q, r; 20 | phase(-3 * pi / 16) r; 21 | cx q, r; 22 | phase(3 * pi / 16) r; 23 | h q; 24 | measure q -> c[0]; 25 | c <<= 1; 26 | reset q; 27 | h q; 28 | phase(3 * pi / 8) q; 29 | cx q, r; 30 | phase(-3 * pi / 8) r; 31 | cx q, r; 32 | phase(3 * pi / 8) r; 33 | phase(-c) q; 34 | h q; 35 | measure q -> c[0]; 36 | c <<= 1; 37 | reset q; 38 | h q; 39 | phase(6 * pi / 8) q; 40 | cx q, r; 41 | phase(-6 * pi / 8) r; 42 | cx q, r; 43 | phase(6 * pi / 8) r; 44 | phase(-c) q; 45 | h q; 46 | measure q -> c[0]; 47 | c <<= 1; 48 | -------------------------------------------------------------------------------- /tests/src/iqpe-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // 7. gate commutation and merging 6 | 7 | qubit q; 8 | qubit r; 9 | angle[3] c = 0; 10 | reset q; 11 | reset r; 12 | h r; 13 | h q; 14 | cx q, r; 15 | phase(-3*pi/16) r; 16 | cx q, r; 17 | phase(3*pi/16) r; 18 | phase(3*pi/16) q; 19 | h q; 20 | measure q -> c[0]; 21 | c <<= 1; 22 | reset q; 23 | h q; 24 | cx q, r; 25 | phase(-3*pi/8) r; 26 | cx q, r; 27 | phase(3*pi/8) r; 28 | phase(3*pi/8-c) q; 29 | h q; 30 | measure q -> c[0]; 31 | c <<= 1; 32 | reset q; 33 | h q; 34 | cx q, r; 35 | phase(-6*pi/8) r; 36 | cx q, r; 37 | phase(6*pi/8) r; 38 | phase(6*pi/8-c) q; 39 | h q; 40 | measure q -> c[0]; 41 | c <<= 1; 42 | -------------------------------------------------------------------------------- /tests/src/iqpe-8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // 8. convert angles to 32-bit fixed point mod 2*pi 6 | 7 | qubit q; 8 | qubit r; 9 | angle[3] c = 0; 10 | reset q; 11 | reset r; 12 | h r; 13 | h q; 14 | cx q, r; 15 | phase(1.8125*pi) r; // mod 2*pi 16 | cx q, r; 17 | phase(0.1875*pi) r; 18 | phase(0.1875*pi) q; 19 | h q; 20 | measure q -> c[0]; 21 | c <<= 1; 22 | reset q; 23 | h q; 24 | cx q, r; 25 | phase(1.625*pi) r; // mod 2*pi 26 | cx q, r; 27 | phase(0.375*pi) r; 28 | phase(0.375*pi-c) q; 29 | h q; 30 | measure q -> c[0]; 31 | c <<= 1; 32 | reset q; 33 | h q; 34 | cx q, r; 35 | phase(1.25*pi) r; // mod 2*pi 36 | cx q, r; 37 | phase(0.75*pi) r; 38 | phase(0.75*pi-c) q; 39 | h q; 40 | measure q -> c[0]; 41 | c <<= 1; 42 | -------------------------------------------------------------------------------- /tests/src/mod5_4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[5]; 5 | x qubits[4]; 6 | ccx qubits[0],qubits[3],qubits[4]; 7 | ccx qubits[2],qubits[3],qubits[4]; 8 | cx qubits[3],qubits[4]; 9 | ccx qubits[1],qubits[2],qubits[4]; 10 | cx qubits[2],qubits[4]; 11 | ccx qubits[0],qubits[1],qubits[4]; 12 | cx qubits[1],qubits[4]; 13 | cx qubits[0],qubits[4]; 14 | -------------------------------------------------------------------------------- /tests/src/mod_mult_55.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[9]; 5 | x qubits[2]; 6 | ccx qubits[0],qubits[2],qubits[7]; 7 | x qubits[2]; 8 | x qubits[0]; 9 | ccx qubits[1],qubits[7],qubits[6]; 10 | ccx qubits[0],qubits[2],qubits[8]; 11 | cx qubits[6],qubits[5]; 12 | cx qubits[6],qubits[3]; 13 | cx qubits[8],qubits[7]; 14 | x qubits[1]; 15 | x qubits[7]; 16 | ccx qubits[1],qubits[8],qubits[6]; 17 | ccx qubits[1],qubits[7],qubits[3]; 18 | x qubits[1]; 19 | cx qubits[6],qubits[4]; 20 | cx qubits[5],qubits[8]; 21 | ccx qubits[1],qubits[7],qubits[5]; 22 | ccx qubits[0],qubits[2],qubits[8]; 23 | x qubits[0]; 24 | x qubits[7]; 25 | cx qubits[5],qubits[8]; 26 | -------------------------------------------------------------------------------- /tests/src/mod_red_21.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[11]; 5 | ccx qubits[1],qubits[3],qubits[4]; 6 | x qubits[4]; 7 | x qubits[5]; 8 | ccx qubits[4],qubits[5],qubits[6]; 9 | x qubits[6]; 10 | ccx qubits[6],qubits[7],qubits[9]; 11 | x qubits[6]; 12 | ccx qubits[4],qubits[5],qubits[6]; 13 | ccx qubits[10],qubits[9],qubits[8]; 14 | x qubits[5]; 15 | x qubits[4]; 16 | ccx qubits[1],qubits[3],qubits[4]; 17 | cx qubits[8],qubits[0]; 18 | cx qubits[8],qubits[1]; 19 | cx qubits[8],qubits[5]; 20 | ccx qubits[0],qubits[1],qubits[2]; 21 | x qubits[2]; 22 | ccx qubits[2],qubits[3],qubits[4]; 23 | x qubits[4]; 24 | ccx qubits[4],qubits[5],qubits[6]; 25 | x qubits[6]; 26 | ccx qubits[6],qubits[8],qubits[7]; 27 | x qubits[6]; 28 | ccx qubits[4],qubits[5],qubits[6]; 29 | x qubits[4]; 30 | ccx qubits[4],qubits[8],qubits[5]; 31 | ccx qubits[2],qubits[3],qubits[4]; 32 | ccx qubits[2],qubits[8],qubits[3]; 33 | x qubits[2]; 34 | ccx qubits[0],qubits[1],qubits[2]; 35 | x qubits[0]; 36 | ccx qubits[0],qubits[8],qubits[1]; 37 | x qubits[0]; 38 | ccx qubits[10],qubits[9],qubits[8]; 39 | -------------------------------------------------------------------------------- /tests/src/newlineifelse.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | uint k = 3; 6 | uint l = 5; 7 | uint m = 7; 8 | 9 | float[128] f0; 10 | float[128] f1; 11 | 12 | // Testing if / else. 13 | if (m == k) { 14 | f0 = pi / 2; 15 | } else { 16 | f0 = -pi / 2; 17 | } 18 | 19 | // Testing if / else if / else. 20 | if (l == k) { 21 | f1 = sin(f0); 22 | } else if (k != m) { 23 | f1 = sin(f0) / cos(f0); 24 | } else { 25 | f1 = atan(f0) / asin(f0); 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/nospace-ifelse.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | uint k = 3; 6 | uint l = 5; 7 | uint m = 7; 8 | 9 | float[128] f0; 10 | float[128] f1; 11 | 12 | // Testing conditionals without space. 13 | if(m == k) { 14 | f0 = pi / 2; 15 | } else { 16 | f0 = -pi / 2; 17 | } 18 | 19 | // Testing conditionals with spurious newlines. 20 | if(l == k) { 21 | f1 = sin(f0); 22 | } else 23 | if(k != m) { 24 | f1 = sin(f0) / cos(f0); 25 | } else { 26 | f1 = atan(f0) / asin(f0); 27 | } 28 | -------------------------------------------------------------------------------- /tests/src/q1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit a, b, c, d; 4 | 5 | reset a; 6 | 7 | reset c; 8 | -------------------------------------------------------------------------------- /tests/src/q2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | include "qelib1.inc"; 4 | 5 | qreg qubits[9]; 6 | 7 | ccx qubits[0],qubits[1],qubits[5]; 8 | -------------------------------------------------------------------------------- /tests/src/qft.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // Quantum Fourier transform 6 | 7 | qubit q[4]; 8 | bit c[4]; 9 | reset q; 10 | x q[0]; 11 | x q[2]; 12 | barrier q; 13 | h q[0]; 14 | cphase(pi / 2) q[1], q[0]; 15 | h q[1]; 16 | cphase(pi / 4) q[2], q[0]; 17 | cphase(pi / 2) q[2], q[1]; 18 | h q[2]; 19 | cphase(pi / 8) q[3], q[0]; 20 | cphase(pi / 4) q[3], q[1]; 21 | cphase(pi / 2) q[3], q[2]; 22 | h q[3]; 23 | c = measure q; 24 | 25 | measure q -> c; 26 | -------------------------------------------------------------------------------- /tests/src/qft1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // Quantum Fourier transform 6 | 7 | qubit[4] q; 8 | bit[4] cb; 9 | 10 | reset q; 11 | 12 | x q[0]; 13 | x q[2]; 14 | 15 | barrier q; 16 | 17 | h q[0]; 18 | cphase(pi / 2) q[1], q[0]; 19 | h q[1]; 20 | cphase(pi / 4) q[2], q[0]; 21 | cphase(pi / 2) q[2], q[1]; 22 | h q[2]; 23 | cphase(pi / 8) q[3], q[0]; 24 | cphase(pi / 4) q[3], q[1]; 25 | cphase(pi / 2) q[3], q[2]; 26 | h q[3]; 27 | cb = measure q; 28 | -------------------------------------------------------------------------------- /tests/src/qft2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | // Quantum Fourier transform 6 | 7 | qubit[4] q; 8 | bit[4] cb; 9 | 10 | reset q; 11 | 12 | x q[0]; 13 | x q[2]; 14 | barrier q; 15 | h q[0]; 16 | cphase(pi / 2) q[1], q[0]; 17 | h q[1]; 18 | cphase(pi / 4) q[2], q[0]; 19 | cphase(pi / 2) q[2], q[1]; 20 | h q[2]; 21 | cphase(pi / 8) q[3], q[0]; 22 | cphase(pi / 4) q[3], q[1]; 23 | cphase(pi / 2) q[3], q[2]; 24 | h q[3]; 25 | 26 | measure q -> cb; 27 | -------------------------------------------------------------------------------- /tests/src/qss-teleport.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit $0; 6 | qubit $1; 7 | qubit $2; 8 | 9 | bit c0; 10 | bit c1; 11 | bit c2; 12 | 13 | reset $0; 14 | reset $1; 15 | reset $2; 16 | 17 | U(0.3, 0.2, 0.1) $0; 18 | 19 | h $0; 20 | cx $1, $2; 21 | 22 | duration for0 = 100ns; 23 | duration for1 = 300ns; 24 | duration for2 = 200ns; 25 | 26 | // Need to define these 27 | delay[for1] $0; 28 | delay[for0] $1; 29 | delay[for2] $2; 30 | 31 | barrier $0, $1, $2; 32 | cx $0, $1; 33 | h $0; 34 | 35 | c0 = measure $0; 36 | c1 = measure $1; 37 | 38 | if (c0 == 1) { 39 | z $2; 40 | } 41 | 42 | if (c1 == 1) { 43 | x $2; 44 | } 45 | 46 | c2 = measure $2; 47 | -------------------------------------------------------------------------------- /tests/src/reset.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def test(qubit[2] anc) -> bit[2] { 4 | bit[2] r; 5 | reset anc; 6 | return r; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/reset_v0.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | reset $0; 6 | -------------------------------------------------------------------------------- /tests/src/reset_v1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | bit result; 6 | 7 | result = measure $0; 8 | 9 | if (result==1) { 10 | U(pi, 0, pi) $0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/rz.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit xq[4]; 6 | 7 | gate rz(tau) xq { 8 | gphase(-tau / 2); 9 | U(0, 0, tau) xq; 10 | } 11 | 12 | rz(pi / 2) xq[1], xq[0]; 13 | -------------------------------------------------------------------------------- /tests/src/ta-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint k = 32; 4 | uint j = 16; 5 | uint y = 8; 6 | 7 | array[qubit[k], j] qb; 8 | 9 | qubit[k] qbb = qb[y]; 10 | -------------------------------------------------------------------------------- /tests/src/ta3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[qubit, 16] aa; 4 | 5 | array[qubit[24], 16] ab; 6 | 7 | qubit aaa = aa[12]; 8 | 9 | qubit[24] aab = ab[14]; 10 | -------------------------------------------------------------------------------- /tests/src/teleportation-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[3] q; 6 | bit c0; 7 | bit c1; 8 | bit c2; 9 | 10 | // optional post-rotation for state tomography 11 | // empty gate body => identity gate 12 | gate post k { } 13 | reset q; 14 | 15 | u3(0.3, 0.2, 0.1) q[0]; 16 | h q[1]; 17 | cx q[1], q[2]; 18 | barrier q; 19 | cx q[0], q[1]; 20 | h q[0]; 21 | c0 = measure q[0]; 22 | c1 = measure q[1]; 23 | if(c0==1) z q[2]; 24 | if(c1==1) { x q[2]; } // braces optional in this case 25 | post q[2]; 26 | c2 = measure q[2]; 27 | -------------------------------------------------------------------------------- /tests/src/teleportation-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[3] q; 6 | bit c0; 7 | bit c1; 8 | bit c2; 9 | 10 | // optional post-rotation for state tomography 11 | // empty gate body => identity gate 12 | gate post k { } 13 | reset q; 14 | 15 | u3(0.3, 0.2, 0.1) q[0]; 16 | h q[1]; 17 | cx q[1], q[2]; 18 | barrier q; 19 | cx q[0], q[1]; 20 | h q[0]; 21 | c0 = measure q[0]; 22 | c1 = measure q[1]; 23 | if (c0 == 1) z q[2]; 24 | if (c1 == 1) { x q[2]; } // braces optional in this case 25 | post q[2]; 26 | c2 = measure q[2]; 27 | -------------------------------------------------------------------------------- /tests/src/teleportation-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[3] q; 6 | bit c0; 7 | bit c1; 8 | bit c2; 9 | 10 | // optional post-rotation for state tomography 11 | // empty gate body => identity gate 12 | gate post k { } 13 | reset q; 14 | 15 | u3(0.3, 0.2, 0.1) q[0]; 16 | h q[1]; 17 | cx q[1], q[2]; 18 | barrier q; 19 | cx q[0], q[1]; 20 | h q[0]; 21 | 22 | measure q[0] -> c0; 23 | measure q[1] -> c1; 24 | 25 | if (c0 == 1) z q[2]; 26 | 27 | if (c1 == 1) { 28 | x q[2]; 29 | } // braces are optional in this case 30 | 31 | post q[2]; 32 | measure q[2] -> c2; 33 | -------------------------------------------------------------------------------- /tests/src/test-add-assign.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // UInt. 4 | uint a = 15; 5 | uint b = 10; 6 | 7 | // Declaration + initialization from assignment. 8 | uint c = a + b; 9 | 10 | // Int. 11 | int ax = 15; 12 | int ay = 10; 13 | 14 | // Declaration + initialization from assignment. 15 | int az = ax + ay; 16 | -------------------------------------------------------------------------------- /tests/src/test-all-int.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int a = -3; 4 | 5 | uint b = 5U; 6 | 7 | int c = -0b0101; 8 | 9 | uint d = 0b10101010; 10 | 11 | int e = -0xbadcafe; 12 | 13 | uint f = 0xdeadbeef; 14 | 15 | int g = -0o12345; 16 | 17 | uint h = 0o54321; 18 | -------------------------------------------------------------------------------- /tests/src/test-angle-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle[256] a = "1234567890987654321.1234567890987654321"; 4 | -------------------------------------------------------------------------------- /tests/src/test-angle-array.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[angle, 16] xxa; 4 | 5 | array[angle[128], 16] xxb; 6 | -------------------------------------------------------------------------------- /tests/src/test-angle-cast.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle[64] a = pi; 4 | 5 | bit[64] ba = bit[64](a); 6 | 7 | float[64] fa = float[64](a); 8 | 9 | bit[128] bb = "0"; 10 | 11 | angle[64] b = angle[64](bb); 12 | 13 | int[128] i = 15; 14 | 15 | b = angle[64](i); 16 | 17 | i = int[128](ba); 18 | 19 | int[64] k = int[64](a); 20 | -------------------------------------------------------------------------------- /tests/src/test-angle.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 1. Single Angle declaration. Default-initialized to 0. 4 | angle[64] a; 5 | 6 | // 2. Single Angle declaration with initialization - integer. 7 | angle[64] b = 1; 8 | 9 | // 3. Single Angle declaration with initialization - integer. 10 | angle[128] bneg = -11; 11 | 12 | // 4. Single Angle declaration with initialization - floating-point. 13 | angle[64] fb = 5.197158; 14 | 15 | // 5. Multiple Angle declarations. Default-initialized to 0. 16 | angle[64] bw; 17 | angle[64] by; 18 | 19 | // 6. Multiple Angle declarations with initialization - integer. 20 | angle[64] aw = 1; 21 | angle[64] ay = 1; 22 | 23 | // 7. Multiple Angle declarations with initialization - floating-point. 24 | angle[64] fw = 3.14159; 25 | angle[128] fy = 3.14159; 26 | 27 | uint ug = 13; 28 | 29 | // 8. Single Angle declaration with initialization - binary expression. 30 | angle[64] ugf = ug << 2; 31 | -------------------------------------------------------------------------------- /tests/src/test-annotation-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | @one 4 | gate p(λ) a { ctrl @ gphase(λ) a; } 5 | 6 | @foo this is an annotation 7 | gate z a { p(π) a; } 8 | 9 | @bind ioport 10 | gate s a { pow(1/2) @ z a; } 11 | 12 | @reversible 13 | gate tdg a { inv @ pow(1/2) @ s a; } 14 | -------------------------------------------------------------------------------- /tests/src/test-annotation-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | @one 4 | gate p(λ) a { ctrl @ gphase(λ) a; } 5 | 6 | @foo this is an annotation 7 | gate z a { p(π) a; } 8 | 9 | @bind ioport [0:3] 10 | gate s a { pow(1/2) @ z a; } 11 | 12 | @reversible 13 | gate tdg a { inv @ pow(1/2) @ s a; } 14 | -------------------------------------------------------------------------------- /tests/src/test-arith-negate.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint a = 3; 4 | 5 | uint b = 5; 6 | 7 | uint c = 7; 8 | 9 | uint d = a + b + c; 10 | 11 | uint e = !a || sin(b); 12 | -------------------------------------------------------------------------------- /tests/src/test-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[qubit, 16] qa; 4 | 5 | array[qubit[32], 16] qb; 6 | 7 | array[angle, 16] aa; 8 | 9 | array[angle[24], 16] ab; 10 | 11 | array[bool, 32] ba; 12 | 13 | array[bit, 32] cba; 14 | 15 | array[bit[64], 32] cbb; 16 | 17 | array[int, 8] ia; 18 | 19 | array[int[128], 16] ib; 20 | 21 | array[uint, 16] ua; 22 | 23 | array[uint[128], 8] ub; 24 | 25 | array[float, 8] fa; 26 | 27 | array[float[128], 8] fb; 28 | 29 | array[duration[100ns], 12] la; 30 | 31 | qubit[32] qbb = qb[0]; 32 | -------------------------------------------------------------------------------- /tests/src/test-array-10.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint k = 128; 4 | uint y = 16; 5 | 6 | array[bool, k] xa; 7 | 8 | array[bool, 96] xb; 9 | 10 | bool xaa = xa[2]; 11 | 12 | bool xbb = xb[y]; 13 | -------------------------------------------------------------------------------- /tests/src/test-array-11.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[qubit, 16] qa; 4 | 5 | array[qubit[32], 16] qb; 6 | 7 | array[angle, 16] aa; 8 | 9 | array[angle[24], 16] ab; 10 | 11 | array[bool, 32] ba; 12 | 13 | array[bit, 32] cba; 14 | 15 | array[bit[64], 32] cbb; 16 | 17 | array[int, 8] ia; 18 | 19 | array[int[128], 16] ib; 20 | 21 | array[uint, 16] ua; 22 | 23 | array[uint[128], 8] ub; 24 | 25 | array[float, 8] fa; 26 | 27 | array[float[128], 8] fb; 28 | 29 | array[duration[100ns], 12] da; 30 | 31 | int[128] ii = ib[8]; 32 | 33 | uint[128] uu = ub[4]; 34 | 35 | int i = ia[4]; 36 | 37 | uint u = ua[8]; 38 | -------------------------------------------------------------------------------- /tests/src/test-array-12.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint k = 128; 4 | uint y = 16; 5 | 6 | array[bool, k] xa; 7 | 8 | array[bool, 96] xb; 9 | 10 | array[int, 32] xi; 11 | 12 | array[bit, 64] xc; 13 | 14 | bool xaa = xa[2]; 15 | 16 | bool xbb = xb[y]; 17 | 18 | bool xii = xi[8]; 19 | 20 | bool xcb = xc[y]; 21 | -------------------------------------------------------------------------------- /tests/src/test-array-13.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 32; 4 | uint k = 128; 5 | uint y = 16; 6 | 7 | array[duration[100ns], j] xa; 8 | 9 | duration[100ns] xaa = xa[2]; 10 | 11 | duration[100ns] xbb = xa[y]; 12 | 13 | array[duration[250ms], j] xb; 14 | 15 | duration[250ms] ybb = xb[y]; 16 | 17 | duration[250ms] zbb = xb[8]; 18 | 19 | duration[100ns] tbb = xa[16]; 20 | -------------------------------------------------------------------------------- /tests/src/test-array-14.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 32; 4 | uint k = 128; 5 | uint y = 16; 6 | 7 | array[duration[100ns], j] xa; 8 | 9 | duration[100ns] xaa = xa[2]; 10 | 11 | duration[100ns] xbb = xa[y]; 12 | 13 | array[duration[250ms], j] xb; 14 | 15 | duration[250ms] ybb = xb[y]; 16 | 17 | duration[250ms] zbb = xb[8]; 18 | 19 | duration[100ns] tbb = xa[16]; 20 | -------------------------------------------------------------------------------- /tests/src/test-array-15.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[128] fl = 53.35; 4 | 5 | int[128] ii = 41; 6 | 7 | uint[128] ui = 51; 8 | 9 | array[complex[float[128]], 64] acf; 10 | 11 | array[complex[float[128]], 64] aci; 12 | 13 | array[complex[float[128]], 64] acu; 14 | 15 | acf[0] = fl; 16 | 17 | aci[0] = ii; 18 | 19 | acu[0] = ui; 20 | 21 | complex[float[128]] cf0 = acf[8]; 22 | 23 | complex[float[64]] cf1 = acf[16]; 24 | -------------------------------------------------------------------------------- /tests/src/test-array-16.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[qubit, 16, 8] qa; 4 | 5 | array[qubit[32], 16, 32] qb; 6 | 7 | array[angle, 16, 8] aa; 8 | 9 | array[angle[24], 16, 32] ab; 10 | 11 | array[bool, 32, 16] ba; 12 | 13 | array[bit, 32, 8] cba; 14 | 15 | array[bit[64], 32, 16] cbb; 16 | 17 | array[int, 8, 16] ia; 18 | 19 | array[int[128], 16, 8] ib; 20 | 21 | array[uint, 16, 8] ua; 22 | 23 | array[uint[128], 8, 16] ub; 24 | 25 | array[float, 8, 32] fa; 26 | 27 | array[float[128], 8, 16] fb; 28 | 29 | array[complex[float[64]], 16, 32] cxb; 30 | 31 | array[duration[100ns], 12, 24] la; 32 | 33 | array[frame, 8, 8] far; 34 | 35 | array[port, 16, 8] par; 36 | 37 | array[waveform, 32, 32] war; 38 | -------------------------------------------------------------------------------- /tests/src/test-array-17.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | 4 | gate phase(lambda) q { 5 | U(0, 0, lambda) q; 6 | } 7 | 8 | qubit a; 9 | 10 | array[qubit, 16] aarray; 11 | 12 | input array[angle, 16] aa; 13 | 14 | 15 | phase(aa[0]) a; 16 | 17 | phase(aa[0]) aarray; 18 | 19 | angle assign = aa[0]; 20 | 21 | phase(assign) a; 22 | -------------------------------------------------------------------------------- /tests/src/test-array-18.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3; 2 | 3 | gate rz(theta) q {} 4 | 5 | qubit $0; 6 | 7 | input angle angle_p; 8 | input float[64] float_p; 9 | 10 | input array[angle, 10] array_angle_p; 11 | input array[float[64], 10] array_float_p; 12 | 13 | // Access value directly 14 | rz(angle_p) $0; 15 | rz(float_p) $0; 16 | 17 | // Access value through array reference 18 | rz(array_angle_p[0]) $0; 19 | rz(array_angle_p[1]) $0; 20 | rz(array_float_p[0]) $0; 21 | rz(array_float_p[1]) $0; 22 | 23 | // Access value through intermediate assignment 24 | float[64] intermediate_angle = array_angle_p[0]; 25 | float[64] intermediate_float = array_float_p[0]; 26 | rz(intermediate_angle) $0; 27 | rz(intermediate_float) $0; 28 | -------------------------------------------------------------------------------- /tests/src/test-array-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[qubit, 16] qa; 4 | 5 | qubit qaa = qa[2]; 6 | 7 | array[qubit[32], 16] qb; 8 | 9 | qubit[32] qbb = qb[8]; 10 | -------------------------------------------------------------------------------- /tests/src/test-array-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[angle, 16] aa; 4 | 5 | array[angle[24], 16] ab; 6 | 7 | angle[32] aaa = aa[12]; 8 | 9 | angle[24] aab = ab[14]; 10 | -------------------------------------------------------------------------------- /tests/src/test-array-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 16; 4 | uint k = 32; 5 | uint y = 8; 6 | 7 | array[qubit, j] qa; 8 | 9 | qubit qaa = qa[2]; 10 | 11 | array[qubit[k], j] qb; 12 | 13 | qubit[k] qbb = qb[y]; 14 | -------------------------------------------------------------------------------- /tests/src/test-array-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 16; 4 | uint k = 32; 5 | uint y = 8; 6 | 7 | array[angle, j] qa; 8 | 9 | angle qaa = qa[2]; 10 | 11 | array[angle[k], j] qb; 12 | 13 | angle[k] qbb = qb[y]; 14 | -------------------------------------------------------------------------------- /tests/src/test-array-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 32; 4 | uint k = 128; 5 | uint y = 16; 6 | 7 | array[int, j] xa; 8 | 9 | int xaa = xa[2]; 10 | 11 | int xbb = xa[y]; 12 | 13 | array[int[k], j] xb; 14 | 15 | int[k] ybb = xb[y]; 16 | 17 | int[128] zbb = xb[8]; 18 | -------------------------------------------------------------------------------- /tests/src/test-array-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 32; 4 | uint k = 128; 5 | uint y = 16; 6 | 7 | array[float, j] fa; 8 | 9 | float faa = fa[2]; 10 | 11 | float fab = fa[y]; 12 | 13 | array[float[k], j] fb; 14 | 15 | float[k] fbb = fb[y]; 16 | 17 | float[128] fcb = fb[10]; 18 | -------------------------------------------------------------------------------- /tests/src/test-array-8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 32; 4 | uint k = 128; 5 | uint y = 16; 6 | 7 | array[bit, j] ba; 8 | 9 | bit baa = ba[2]; 10 | 11 | bit bab = ba[y]; 12 | 13 | array[bit[k], j] bb; 14 | 15 | bit[k] bbb = bb[y]; 16 | 17 | bit[128] bcb = bb[10]; 18 | -------------------------------------------------------------------------------- /tests/src/test-array-9.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 32; 4 | uint k = 128; 5 | uint y = 16; 6 | 7 | array[angle, j] xa; 8 | 9 | angle xaa = xa[2]; 10 | 11 | angle xbb = xa[y]; 12 | 13 | array[angle[k], j] xb; 14 | 15 | angle[k] ybb = xb[y]; 16 | 17 | angle[128] zbb = xb[8]; 18 | 19 | angle[96] tbb = xb[16]; 20 | -------------------------------------------------------------------------------- /tests/src/test-array-subscript.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint k = 64; 4 | uint j = 32; 5 | uint y = 16; 6 | 7 | array[angle[k], j] qb; 8 | 9 | angle[k] qbb = qb[y]; 10 | -------------------------------------------------------------------------------- /tests/src/test-assign-pi.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle[64] api = pi; 4 | 5 | angle[64] atau = tau; 6 | 7 | angle[64] aeu = euler; 8 | -------------------------------------------------------------------------------- /tests/src/test-assign.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle[3] c = 0; 4 | 5 | // Assign. 6 | c = 1; 7 | 8 | // Another Assign. 9 | uint j = 14; 10 | 11 | // Transitive Assign 12 | uint k = c = j; 13 | 14 | // Transitive Self-Assign 15 | uint m = c *= j; 16 | 17 | // Assign from Pre/Post. 18 | uint n = m + j++; 19 | 20 | // Assign from Add + Self-Assign 21 | uint p = n + m << j; 22 | -------------------------------------------------------------------------------- /tests/src/test-bad-cal.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 3; 4 | int j = 4; 5 | 6 | if (i == j) { 7 | cal { 8 | extern port p0; 9 | frame driveframe1 = newframe(p0, 5.1e9, 0.0); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-bad-version.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | angle[32] foo = pi / 2; 4 | -------------------------------------------------------------------------------- /tests/src/test-big-int.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 18446744073709551615184467440737095516152147483647; 4 | -------------------------------------------------------------------------------- /tests/src/test-bit-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // bit array declaration with no initialization. Bits will be set to 0. 4 | bit[24] bit_array_1; 5 | 6 | // bit array declaration + initialization. All bits will be set to 1. 7 | bit[24] bit_array_2 = 1; 8 | 9 | // bit array declaration + initialization. Bits will be set to the bitmask 10 | // provided in RHS. 11 | bit[8] bit_byte = "00001111"; 12 | 13 | // bit array declaration with no initialization. Bits will be set to 0. 14 | cbit[24] cbit_array_1; 15 | 16 | // bit array declaration + initialization. All bits will be set to 1. 17 | cbit[24] cbit_array_2 = 1; 18 | 19 | // bit array declaration + initialization. Bits will be set to the bitmask 20 | // provided in RHS. 21 | cbit[8] cbit_byte = "00001111"; 22 | -------------------------------------------------------------------------------- /tests/src/test-bit-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 16; 4 | 5 | def testbit(bit[n] cin, bit[32] cout, float f, qubit[4] d, qubit a) -> bit { 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test-bit-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit b = 0; 4 | 5 | bit c = 1; 6 | -------------------------------------------------------------------------------- /tests/src/test-bit-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit b; 4 | 5 | bit c = 1; 6 | 7 | bit d; 8 | 9 | b = c; 10 | 11 | d = 1; 12 | -------------------------------------------------------------------------------- /tests/src/test-bit-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] a = 0; 4 | 5 | bit[32] b = "00000001000000010000000100000001"; 6 | 7 | bit[32] c = 1; 8 | -------------------------------------------------------------------------------- /tests/src/test-bit-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] b = "00000001000000010000000100000001"; 4 | 5 | bit c = b[7]; 6 | 7 | bit d = b[0]; 8 | -------------------------------------------------------------------------------- /tests/src/test-bit-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] b = "00000001000000010000000100000001"; 4 | 5 | bit[16] c = b; 6 | 7 | bit[16] d = b[7]; 8 | -------------------------------------------------------------------------------- /tests/src/test-bit-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[bit, 16] xba; 4 | 5 | array[bit[32], 16] xbb; 6 | -------------------------------------------------------------------------------- /tests/src/test-bit-gate-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] c; 4 | 5 | gate cx c, t { } 6 | 7 | qubit $0; 8 | qubit $1; 9 | 10 | cx $0, $1; 11 | 12 | c[0] = measure $0; 13 | -------------------------------------------------------------------------------- /tests/src/test-bit-gate-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] c; 4 | 5 | int i; 6 | 7 | float[128] f; 8 | 9 | gate zx c, f, i, t { } 10 | 11 | qubit $0; 12 | qubit $1; 13 | qubit $2; 14 | qubit $3; 15 | 16 | zx $0, $1, $2, $3; 17 | 18 | c[0] = measure $0; 19 | c[1] = measure $3; 20 | -------------------------------------------------------------------------------- /tests/src/test-bit-gate-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] c; 4 | 5 | int i; 6 | 7 | float[128] f; 8 | 9 | gate zx c, f, t, i { } 10 | 11 | qubit $0; 12 | qubit $1; 13 | qubit $2; 14 | qubit $3; 15 | 16 | zx $0, $1, $2, $3; 17 | 18 | c[0] = measure $0; 19 | c[1] = measure $3; 20 | -------------------------------------------------------------------------------- /tests/src/test-bit-gate-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] c; 4 | 5 | int i; 6 | 7 | float[128] f; 8 | 9 | float[64] lambda; 10 | 11 | float[64] theta; 12 | 13 | float[64] phi; 14 | 15 | gate zx (lambda, theta, phi) c, f, i, t { } 16 | 17 | qubit $0; 18 | qubit $1; 19 | qubit $2; 20 | qubit $3; 21 | 22 | zx $0, $1, $2, $3; 23 | 24 | c[0] = measure $0; 25 | c[1] = measure $3; 26 | -------------------------------------------------------------------------------- /tests/src/test-bit-gate-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] c; 4 | 5 | int i; 6 | 7 | float[128] f; 8 | 9 | float[64] lambda; 10 | 11 | float[64] theta; 12 | 13 | float[64] sigma; 14 | 15 | gate zx (lambda, theta, phi) c, f, t, i { } 16 | 17 | qubit $0; 18 | qubit $1; 19 | qubit $2; 20 | qubit $3; 21 | 22 | zx $0, $1, $2, $3; 23 | 24 | c[0] = measure $0; 25 | c[1] = measure $3; 26 | -------------------------------------------------------------------------------- /tests/src/test-bit-measure.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | bit a = measure $0; 6 | -------------------------------------------------------------------------------- /tests/src/test-bit.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" 4 | 5 | // bit array declaration with no initialization. Bits will be set to 0. 6 | bit bit_array_1[24]; 7 | 8 | // bit array declaration + initialization. All bits will be set to 1. 9 | bit bit_array_2[24] = 1; 10 | 11 | // bit array declaration + initialization. Bits will be set to the bitmask 12 | // provided in RHS. 13 | bit bit_byte[8] = "00001111"; 14 | 15 | // bit array declaration with no initialization. Bits will be set to 0. 16 | cbit cbit_array_1[24]; 17 | 18 | // bit array declaration + initialization. All bits will be set to 1. 19 | cbit cbit_array_2[24] = 1; 20 | 21 | // bit array declaration + initialization. Bits will be set to the bitmask 22 | // provided in RHS. 23 | cbit cbit_byte[8] = "00001111"; 24 | -------------------------------------------------------------------------------- /tests/src/test-bitnot.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | gate x q {} 6 | 7 | bit[4] c; 8 | 9 | c[0] = 1; 10 | 11 | // 1. BitNot assign 12 | c[1] = ~c[0]; 13 | 14 | c[2] = measure $0; 15 | 16 | // 2. BitNot condition 17 | if (~c[2]) { 18 | x $0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/src/test-bitset-bitops.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] a = 1; 4 | bit[2] b = 0; 5 | bit[2] c; 6 | 7 | c = a << 1; 8 | c = rotl(a, 2); 9 | c = popcount(a); 10 | c = a & b; 11 | c = a | b; 12 | c = a ^ b; 13 | 14 | c = a + b; 15 | c = a - b; 16 | c = a * b; 17 | c = a / b; 18 | -------------------------------------------------------------------------------- /tests/src/test-bitset-cast.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 21; 4 | 5 | bit[8] ba = bit(i); 6 | 7 | bit[3] bb = 1; 8 | 9 | int j = int(bb); 10 | 11 | bit[128] bc = 0; 12 | 13 | int[64] k = int[64](bc); 14 | 15 | float f = 12.15; 16 | 17 | float[64] df = float[64](f); 18 | 19 | j = int(f); 20 | 21 | k = int[64](df); 22 | -------------------------------------------------------------------------------- /tests/src/test-bitset-int-cast.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | bit[2] a; 7 | 8 | a[0] = measure $0; 9 | a[1] = measure $1; 10 | 11 | int i = a; 12 | -------------------------------------------------------------------------------- /tests/src/test-bitset.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[8] c; 4 | 5 | bit d = c[1]; 6 | -------------------------------------------------------------------------------- /tests/src/test-bool-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bool a = true; 4 | 5 | bool b = false; 6 | 7 | bool c = a || b; 8 | 9 | bool d = b && c; 10 | 11 | bool e = b && c || a; 12 | -------------------------------------------------------------------------------- /tests/src/test-bool-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bool test_bool; 4 | 5 | test_bool = true; 6 | -------------------------------------------------------------------------------- /tests/src/test-bool-cast.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit foo = 0; 4 | 5 | if (bool(foo)) { } 6 | 7 | foo = 0; 8 | -------------------------------------------------------------------------------- /tests/src/test-bool.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bool a; 4 | 5 | bool b = true; 6 | 7 | bool c = 13; 8 | 9 | bool d = a && b; 10 | 11 | bool e = d || a << 1; 12 | -------------------------------------------------------------------------------- /tests/src/test-box-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[8] q; 6 | 7 | box test_box_1 { 8 | cx q[0], q[1]; 9 | reset q; 10 | } 11 | -------------------------------------------------------------------------------- /tests/src/test-box-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[8] q; 6 | 7 | boxas test_box_2 { 8 | cx q[0], q[1]; 9 | delay[200ns] q[0]; 10 | } 11 | 12 | delay[durationof(test_box_2)] q[2], q[3]; 13 | cx q[2], q[3]; 14 | -------------------------------------------------------------------------------- /tests/src/test-box-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit[8] q; 6 | 7 | boxto 1ms { 8 | stretch a; 9 | delay[a] q; 10 | 11 | cx q[0], q[1]; 12 | delay[a] q[0]; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-box-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x a { 4 | U(π, 0, π) a; 5 | } 6 | 7 | gate phase(lambda) q { 8 | U(0, 0, lambda) q; 9 | } 10 | 11 | gate rz(phi) a { 12 | phase(phi) a; 13 | } 14 | 15 | gate rx(theta) a { 16 | U(theta, -pi / 2, pi / 2) a; 17 | } 18 | 19 | qubit q; 20 | 21 | rx(2 * π / 12) q; 22 | 23 | box box_1 { 24 | delay[dt] q; 25 | x q; 26 | delay[dt] q; 27 | x q; 28 | delay[dt] q; 29 | } 30 | 31 | rx(3 * π / 12) q; 32 | 33 | rx(5 * π / 12) q; 34 | 35 | box box_2 { 36 | delay[dt] q; 37 | x q; 38 | delay[dt] q; 39 | x q; 40 | delay[dt] q; 41 | } 42 | -------------------------------------------------------------------------------- /tests/src/test-builtins-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 64; 4 | 5 | cal { 6 | waveform wf0 = [1 + j im, j + 3 im, 1 / sqrt(2) + 1 / sqrt(2) * j im]; 7 | 8 | complex[float[128]] a = 5.25 * 1 im; 9 | complex[float[128]] b = 15.25 * 1 im; 10 | complex[float[128]] c = 25.25 * 1 im; 11 | 12 | waveform wf1 = [a, b, c]; 13 | waveform wfm = mix(wf0, wf1); 14 | waveform wfs = sum(wfm, wf1); 15 | } 16 | 17 | angle[64] an = pi / 2; 18 | 19 | cal { 20 | waveform wfp = phase_shift(wfs, an); 21 | float[64] fct = 0.9137815; 22 | } 23 | 24 | cal { 25 | waveform wfc = scale(wfp, fct); 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-c-comment.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | /* 4 | * This is a multi-line C style comment line. 5 | * It has three lines. 6 | * This is the third line. 7 | */ 8 | 9 | /* 10 | 11 | This is a C comment. It has a whitespace line above. 12 | */ 13 | 14 | /* 15 | This is a multi-line C Comment 16 | 17 | The line above was blank 18 | This is the third line 19 | */ 20 | 21 | /* This is another multi-line C comment 22 | * It is better formatted than the previous one 23 | * This is the third line 24 | * This is the fourth line 25 | */ 26 | 27 | /* This is a single-line C comment */ 28 | -------------------------------------------------------------------------------- /tests/src/test-cal-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | cal { 4 | extern port p0; 5 | frame test_frame = newframe(p0, 5e9, 0.0); 6 | } 7 | 8 | cal { 9 | extern port e0; 10 | frame inner_frame = newframe(e0, 5e10, pi); 11 | 12 | inner_frame.freq = 35e10; 13 | inner_frame.time = 100μs; 14 | inner_frame.phase = tau / 4; 15 | } 16 | -------------------------------------------------------------------------------- /tests/src/test-cal-complex.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | cal { 4 | extern port p0; 5 | frame test_frame = newframe(p0, 5e9, 0.0); 6 | 7 | complex[float[64]] c; 8 | c.creal = 75.25; 9 | c.cimag = 31.231; 10 | } 11 | 12 | complex[float[64]] c; 13 | c.creal = 75.25; 14 | c.cimag = 31.231; 15 | -------------------------------------------------------------------------------- /tests/src/test-cast-bool.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bool b = false; 4 | 5 | bit e = 1; 6 | 7 | if (bool(e)) { 8 | b = true; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-cbit-rref.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] b = "00000001000000010000000100000001"; 4 | 5 | uint i = 3; 6 | 7 | if (b[7] == 1) { 8 | i = 9; 9 | } else { 10 | i = 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-chinese-simplified-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint integer = 15; 8 | uint 整数 = 15; 9 | 10 | // int A = 1; 11 | int 一种 = 1; 12 | 13 | // int E = 2; 14 | int 乙 = 2; 15 | 16 | // int I = 3; 17 | int 一世 = 3; 18 | 19 | // int U = 4; 20 | int 你 = 4; 21 | 22 | // int O (oh) = 5; 23 | int 哦 = 5; 24 | 25 | // Using Chinese Simplified characters: 26 | // gate katakana(lambda, theta, phi) mo { 27 | // U(phi, theta, lambda) mo; 28 | // } 29 | gate 片假名(λ, φ, θ) 莫 { 30 | U(θ, φ, λ) 莫; 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/test-chinese-traditional-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint integer = 15; 8 | uint 整數 = 15; 9 | 10 | // int A = 1; 11 | int 一種 = 1; 12 | 13 | // int E = 2; 14 | int 乙 = 2; 15 | 16 | // int I = 3; 17 | int 一世 = 3; 18 | 19 | // int U = 4; 20 | int 你 = 4; 21 | 22 | // int O (oh) = 5; 23 | int 哦 = 5; 24 | 25 | // Using Chinese Traditional characters: 26 | // gate katakana(lambda, theta, phi) mo { 27 | // U(phi, theta, lambda) mo; 28 | // } 29 | gate 片假名(λ, φ, θ) 莫 { 30 | U(θ, φ, λ) 莫; 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/test-complex-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[64] c = 2.1 + 5.1im; 4 | 5 | complex[64] d = 3 + 7.35 im; 6 | -------------------------------------------------------------------------------- /tests/src/test-complex-10.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[64]] C = 29.0 + 31.0 im; 4 | 5 | complex[float[64]] D = 87.0 + 51.0 im; 6 | 7 | complex[float[64]] F = 23.91 + 313.795 im; 8 | -------------------------------------------------------------------------------- /tests/src/test-complex-11.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[128]] C; 4 | 5 | C.creal = 29; 6 | C.cimag = 31; 7 | 8 | complex[float[128]] D; 9 | 10 | D.creal = 87.339; 11 | D.cimag = 31.741; 12 | -------------------------------------------------------------------------------- /tests/src/test-complex-12.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[128]] C; 4 | 5 | C = 29 + 31 im; 6 | 7 | complex[float[128]] D; 8 | 9 | D = 87.339 + 31.741 im; 10 | -------------------------------------------------------------------------------- /tests/src/test-complex-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] R = 87.395; 4 | 5 | float[64] I = 29.443; 6 | 7 | complex[64] C = R + I im; 8 | -------------------------------------------------------------------------------- /tests/src/test-complex-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] R = 87.395; 4 | 5 | complex[64] C = R + 29.443 im; 6 | -------------------------------------------------------------------------------- /tests/src/test-complex-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] I = 87.395; 4 | 5 | complex[64] C = 147 + I im; 6 | -------------------------------------------------------------------------------- /tests/src/test-complex-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[64] A = 1399 + 31 im; 4 | 5 | complex[64] B = 1399 - 31 im; 6 | 7 | complex[64] C = 1399 * 31 im; 8 | 9 | complex[64] D = 1399 / 31 im; 10 | 11 | complex[64] E = 1399 % 31 im; 12 | -------------------------------------------------------------------------------- /tests/src/test-complex-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[64] A = 787.91 + 29.8266937 im; 4 | 5 | complex[64] B = 787.91 - 29.8266937 im; 6 | 7 | complex[64] C = 787.91 * 29.8266937 im; 8 | 9 | complex[64] D = 787.91 / 29.8266937 im; 10 | 11 | complex[64] E = 787.91 % 29.8266937 im; 12 | -------------------------------------------------------------------------------- /tests/src/test-complex-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] R = 87.395; 4 | 5 | float[128] S = 71.873; 6 | 7 | complex[float[64]] C = R + 29.443 im; 8 | 9 | complex[float[128]] D = S + 31.995 im; 10 | -------------------------------------------------------------------------------- /tests/src/test-complex-8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int[64] R = 87; 4 | 5 | int[128] S = 71; 6 | 7 | complex[float[64]] C = R + 29 im; 8 | 9 | complex[float[128]] D = S + 31 im; 10 | -------------------------------------------------------------------------------- /tests/src/test-complex-9.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[128]] C = 29 + 31 im; 4 | 5 | complex[float[128]] D = 87 + 51 im; 6 | -------------------------------------------------------------------------------- /tests/src/test-complex-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[complex[float[64]], 16] cxai; 4 | 5 | array[complex[float[64]], 16] cxau; 6 | 7 | array[complex[float[128]], 16] cxaf; 8 | -------------------------------------------------------------------------------- /tests/src/test-complex-array-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[complex[float[32]], 16] cxai; 4 | 5 | array[complex[float[64]], 16] cxau; 6 | 7 | array[complex[float[128]], 16] cxaf; 8 | -------------------------------------------------------------------------------- /tests/src/test-complex-array-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint k = 16; 4 | uint x = 128; 5 | 6 | array[complex[float[64]], 16] cxac; 7 | 8 | array[complex[float[x]], 16] cxax; 9 | 10 | array[complex[float[128]], k] cxak; 11 | 12 | array[complex[float[x]], k] ckax; 13 | -------------------------------------------------------------------------------- /tests/src/test-consecutive-gates-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | angle[64] a = 3.14159; 6 | 7 | U(a, 0.0, 0.0) $0; 8 | U(a, 0.0, 0.0) $0; 9 | U(a, 0.0, 0.0) $0; 10 | -------------------------------------------------------------------------------- /tests/src/test-consecutive-gates-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | gate test(lambda) q, r, s { 6 | U(lambda, 0.0, 3.14159265359) q; 7 | U(lambda, 0.0, 3.14159265359) r; 8 | U(lambda, 0.0, 3.14159265359) s; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-const-float.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | const int i = 5 * 35; 4 | 5 | const float theta = 5 * pi / 2; 6 | -------------------------------------------------------------------------------- /tests/src/test-const-scalars.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | const int j = 3; 4 | 5 | const float[128] mpf = 315.315315315315315315; 6 | 7 | const uint[64] mpu = 12345; 8 | -------------------------------------------------------------------------------- /tests/src/test-const.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 0. MPInteger Constant. 4 | const int ic = 201568739; 5 | 6 | // 1. MPDecimal Constant. 7 | const float dc = 234079897.30303098128; 8 | 9 | // 2. Bit-Indexed MPInteger Constant. 10 | const int[256] iic = "479872340982346123098234623409876230498123879234"; 11 | 12 | // 3. Bit-Indexed MPDecimal Constant. 13 | const float[512] ddc = "2340798723415689742309832476.303030981236098809809823423454"; 14 | -------------------------------------------------------------------------------- /tests/src/test-control-chain-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This program has no meaning. 4 | // It is only a syntax / AST Generator test. 5 | 6 | gate phase(lambda) q { 7 | U(0.0, 0.0, lambda) q; 8 | } 9 | 10 | qubit q; 11 | qubit r; 12 | 13 | const uint n = 3; 14 | 15 | bit[n] cb = 0; 16 | 17 | float[n] theta = 2.0; 18 | 19 | angle a = 0.00; 20 | 21 | uint[n] power = 2; 22 | 23 | ctrl @ pow(power) @ phase(theta) q; 24 | 25 | inv @ phase(a) q; 26 | 27 | ctrl @ inv @ phase(a) q; 28 | 29 | measure q -> cb[0]; 30 | measure r -> cb[0]; 31 | -------------------------------------------------------------------------------- /tests/src/test-cos.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | double d = 3.0; 4 | double s = cos(d); 5 | -------------------------------------------------------------------------------- /tests/src/test-creg.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | creg a; 4 | 5 | creg b = 10; 6 | 7 | creg[16] c; 8 | 9 | creg[32] d = 17; 10 | -------------------------------------------------------------------------------- /tests/src/test-ctrl.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate phase(lambda) q, r { 4 | U(0, 0, lambda) q; 5 | U(0, 0, lambda) r; 6 | } 7 | 8 | const int n = 128; 9 | 10 | uint[n] power = 1; 11 | 12 | angle theta = pi / 2; 13 | 14 | ctrl @ phase(theta) q, r; 15 | 16 | pow(n) @ phase(theta) q, r; 17 | 18 | gate crz(phi) q1, q2 { 19 | ctrl @ U(phi, 0, 0) q1, q2; 20 | } 21 | -------------------------------------------------------------------------------- /tests/src/test-cx.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate cx a, b { 4 | CX a, b; 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/test-defcal-binop.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | qubit $2; 6 | 7 | defcal rx(pi / 2) $0 { } 8 | 9 | defcal ry(-pi / 2) $0 { } 10 | 11 | defcal rz(pi / 4, -pi * 2) $0, $1 { } 12 | -------------------------------------------------------------------------------- /tests/src/test-defcal-conversion.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] sigma = 3.141592; 4 | float[64] psi = 6.283184; 5 | 6 | qubit $0; 7 | qubit $1; 8 | qubit $2; 9 | 10 | defcal rx(pi / 2, psi) $0 { } 11 | 12 | defcal ry(-pi / 2, sigma) $0 { } 13 | 14 | defcal rz(pi / 4, -pi * 2, sigma, psi) $0, $1 { } 15 | -------------------------------------------------------------------------------- /tests/src/test-defcal-delay-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | defcal delay[100ms] $0 { } 7 | 8 | defcal delay[1000ns] $1 { } 9 | 10 | defcal "testgrammar" delay[100ms] $0 { } 11 | 12 | defcal "testgrammar" delay[1000ns] $1 { } 13 | -------------------------------------------------------------------------------- /tests/src/test-defcal-delay-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | duration da = 350μs; 7 | 8 | duration db = 500ms; 9 | 10 | defcal delay[da] $0 { } 11 | 12 | defcal delay[db] $1 { } 13 | 14 | defcal "testgrammar" delay[da] $0 { } 15 | 16 | defcal "testgrammar" delay[db] $1 { } 17 | -------------------------------------------------------------------------------- /tests/src/test-defcal-measure.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $1; 4 | qubit $2; 5 | qubit[8] $3; 6 | 7 | defcal measure $1 -> bit { } 8 | 9 | defcal "openpulse" measure $2 -> bit { } 10 | 11 | defcal measure $3 -> bit[8] { } 12 | -------------------------------------------------------------------------------- /tests/src/test-defcal-reset.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | defcal reset $0 { } 7 | 8 | defcal "openpulse" reset $1 { } 9 | -------------------------------------------------------------------------------- /tests/src/test-defcal-unop.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | float[64] f = 0.543212345; 7 | 8 | defcal rx(pi / 2, atan(f)) $0 { } 9 | 10 | defcal ry(cos(f), -pi / 2) $1 { } 11 | -------------------------------------------------------------------------------- /tests/src/test-delay-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $q; 4 | 5 | stretch a; 6 | 7 | delay[a] $q; 8 | 9 | duration b = 10ns; 10 | 11 | delay[b] $q; 12 | 13 | delay[15ns] $q; 14 | -------------------------------------------------------------------------------- /tests/src/test-delay-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | stretch a; 4 | 5 | delay[a]; 6 | 7 | duration b = 10ns; 8 | 9 | delay[b]; 10 | 11 | delay[15ns]; 12 | -------------------------------------------------------------------------------- /tests/src/test-delay-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[8] q; 4 | 5 | delay[150ns] q[0], q[1], q[2], q[3], q[4]; 6 | -------------------------------------------------------------------------------- /tests/src/test-delay.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[8] q; 4 | 5 | delay[200ns] q[0]; 6 | -------------------------------------------------------------------------------- /tests/src/test-do-while-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | uint n = 125; 17 | 18 | // Do/While loop. 19 | do { 20 | reset q; 21 | h q; 22 | cphase(power*3*pi/8) q, r; 23 | phase(-c) q; 24 | h q; 25 | measure q -> c[0]; 26 | c <<= 1; 27 | power <<= 1; 28 | --n; 29 | } while (n >= 0); 30 | -------------------------------------------------------------------------------- /tests/src/test-do-while-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | uint n = 125; 17 | 18 | // Do/While loop. 19 | do { 20 | reset q; 21 | h q; 22 | cphase(power*3*pi/8) q, r; 23 | phase(-c) q; 24 | h q; 25 | measure q -> c[0]; 26 | c <<= 1; 27 | 28 | if (c == 32) { 29 | break; 30 | } else { 31 | continue; 32 | } 33 | 34 | power <<= 1; 35 | --n; 36 | } while (n >= 0); 37 | -------------------------------------------------------------------------------- /tests/src/test-do-while-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int bs = 0; 4 | 5 | int i = 10; 6 | 7 | do { 8 | bs |= i--; 9 | } while (i > 3); 10 | -------------------------------------------------------------------------------- /tests/src/test-do-while-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int bs = 0; 4 | 5 | int i = 10; 6 | 7 | int j = 20; 8 | 9 | do { 10 | bs |= i--; 11 | 12 | while (j != 0) { 13 | bs = bs + 1; 14 | --j; 15 | } 16 | 17 | } while (i > 3); 18 | -------------------------------------------------------------------------------- /tests/src/test-do-while-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 10; 4 | 5 | int j = 20; 6 | 7 | int k = 30; 8 | 9 | do { 10 | k += 5; 11 | } while (--j > 0); 12 | -------------------------------------------------------------------------------- /tests/src/test-dollar-qubit.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q[8]; 6 | 7 | // Simple Qubit identifiers. 8 | // 0. $[a-zA-Z_][0-9]+ 9 | measure $0 -> q[0]; 10 | measure $1 -> q[1]; 11 | 12 | // More complex Qubit identifiers. 13 | // 1. $[a-zA-Z_][0-9]+ 14 | measure %q1 -> q[2]; 15 | 16 | // 2. $[a-zA-Z_][0-9]+ 17 | measure $q2 -> q[3]; 18 | 19 | // 3. $[0-9]+ 20 | measure %2 -> q[2]; 21 | 22 | // 4. cb[N] = measure qubit[N]. 23 | qubit qb[8]; 24 | cbit cb[8]; 25 | cb = measure qb; 26 | 27 | // 5. measure qubit[N] -> cb[N]. 28 | qubit qbc[4]; 29 | cbit cbc[4]; 30 | 31 | measure qbc[0] -> cbc[0]; 32 | measure qbc[2] -> cbc[2]; 33 | measure qbc[3] -> cbc[1]; 34 | -------------------------------------------------------------------------------- /tests/src/test-dot-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | cal { 4 | extern port p0; 5 | 6 | frame foo = newframe(p0, 5e9, 0.0); 7 | 8 | foo.frequency = 10; 9 | 10 | foo.time = 15; 11 | 12 | foo.phase = 25; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-dot-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | cal { 4 | extern port p0; 5 | 6 | frame foo = newframe(p0, 5e9, 0.0); 7 | 8 | foo.frequency = 10; 9 | 10 | foo.time = 15; 11 | 12 | foo.phase = 25; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-duration-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // controlled-NOT Gate 4 | gate cx c, t { 5 | CX c, t; 6 | } 7 | 8 | // Clifford gate: Hadamard 9 | gate h a { 10 | U(pi / 2, 0, pi) a; 11 | } 12 | 13 | // 1. Fixed duration, in standard units 14 | duration a = 300ns; 15 | 16 | // 2. Fixed duration, backend dependent 17 | duration b = 800dt; 18 | 19 | // 3. Fixed duration, referencing the duration of a calibrated gate 20 | duration c = durationof(h); 21 | 22 | // 4. Fixed duration, referencing the duration of a calibrated gate 23 | qubit $0; 24 | 25 | duration hxc = durationof( { h $0; } ); 26 | 27 | // 5. Dynamic duration, referencing a box within its context 28 | qubit[8] q; 29 | 30 | box bx { 31 | cx q[0], q[1]; 32 | reset q; 33 | } 34 | 35 | duration d = durationof(bx); 36 | 37 | duration la = 500ms; 38 | 39 | duration xa = 350μs; 40 | -------------------------------------------------------------------------------- /tests/src/test-duration-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate dgate(lambda, theta) q { 4 | U(lambda, pi, theta) q; 5 | } 6 | 7 | qubit $0; 8 | 9 | duration a = 300ns; 10 | 11 | duration b = durationof({ dgate(pi / 2, -pi / 2) $0; }); 12 | 13 | stretch c; 14 | 15 | // stretchy duration with min=300ns 16 | duration d = a + 2 * c; 17 | 18 | // stretchy duration with backtracking by up to half b 19 | duration e = -0.5 * b + c; 20 | -------------------------------------------------------------------------------- /tests/src/test-duration-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[2] q; 4 | 5 | gate cx c, t { 6 | CX c, t; 7 | } 8 | 9 | box bx { 10 | cx q[0], q[1]; 11 | reset q; 12 | } 13 | 14 | duration d = durationof(bx); 15 | -------------------------------------------------------------------------------- /tests/src/test-duration-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[duration[100ns], 16] xda; 4 | -------------------------------------------------------------------------------- /tests/src/test-duration-array-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate testgate(theta) q { 4 | U(pi, theta, -pi) q; 5 | } 6 | 7 | qubit $0; 8 | 9 | angle x = 0.50505; 10 | 11 | array[durationof({ testgate(x) $0; }), 16] xdg; 12 | -------------------------------------------------------------------------------- /tests/src/test-durationof-defcal.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | defcal dcal(lambda, theta) $0 { } 6 | 7 | float[64] x = 0.350350; 8 | 9 | duration d = durationof( { dcal(pi / 2, sin(x)) $0; } ); 10 | -------------------------------------------------------------------------------- /tests/src/test-durationof-unaryop.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate dgate(lambda, theta) q { } 4 | 5 | qubit $0; 6 | 7 | float[64] x = 0.350350; 8 | 9 | duration d = durationof( { dgate(pi / 2, sin(x)) $0; } ); 10 | -------------------------------------------------------------------------------- /tests/src/test-eq.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint c = 3; 4 | uint d = 4; 5 | 6 | uint e = c == d; 7 | -------------------------------------------------------------------------------- /tests/src/test-euler.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[32] my_euler = ε; 4 | 5 | float[32] your_euler = euler; 6 | 7 | float[32] my_neg_euler = -ε; 8 | 9 | float[32] your_neg_euler = -euler; 10 | -------------------------------------------------------------------------------- /tests/src/test-extern-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 1. Extern declaration with no statements and mixed parameter types. 4 | extern test_kernel_1(qubit[4] d, qubit a, int i, float[32] f) -> bit; 5 | -------------------------------------------------------------------------------- /tests/src/test-extern-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | extern test_kernel_2(qubit[4], qubit, int i, float[32], complex[float[64]] c) -> bit; 4 | -------------------------------------------------------------------------------- /tests/src/test-extern-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | extern test_kernel_2(int[64] mpi, qubit[4], qubit, int i, float[32], 4 | complex[float[64]] c) -> bit; 5 | -------------------------------------------------------------------------------- /tests/src/test-extern-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | extern test0() -> bit; 4 | 5 | extern test1(); 6 | 7 | extern test2(int i, double d); 8 | -------------------------------------------------------------------------------- /tests/src/test-fixed-scalars.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | const uint n = 64; 4 | 5 | uint[n] uidx = 1; 6 | 7 | int[n] iidx = 7; 8 | 9 | uint[n] u; 10 | 11 | int[n] i; 12 | 13 | uint[8] u8 = 7; 14 | 15 | int[8] i8 = 7; 16 | 17 | float[n] fn; 18 | 19 | float[n] fidx = 3.151719; 20 | 21 | float[16] f16; 22 | 23 | float[16] fv16 = 4.513759; 24 | -------------------------------------------------------------------------------- /tests/src/test-fixed.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" 4 | 5 | // fixed-point uninitialized. 6 | fixed fa[24, 16]; 7 | 8 | // fixed-point initialized to PI. 9 | fixed fb[24, 12] = pi; 10 | 11 | // fixed-point initialized to PI / 2. 12 | fixed fc[24, 12] = pi / 2; 13 | 14 | // fixed-point initialized to a constant floating-point. 15 | fixed fd[32, 12] = 0.3152347; 16 | 17 | // fixed-point initialization to TAU. 18 | fixed fe[24, 12] = tau; 19 | 20 | // fixed-point initialization to euler_gamma. 21 | fixed ff[24, 12] = euler_gamma; 22 | 23 | // fixed-point initialization to TAU * 2. 24 | fixed fg[24, 12] = tau * 2; 25 | 26 | // fixed-point initialization to euler_gamma + 3.15. 27 | fixed fh[24, 12] = euler_gamma + 3.15; 28 | -------------------------------------------------------------------------------- /tests/src/test-for-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | // For loop. 17 | for i in [0 : 2] { 18 | reset q; 19 | h q; 20 | cphase(power*3*pi/8) q, r; 21 | phase(-c) q; 22 | h q; 23 | measure q -> c[0]; 24 | c <<= 1; 25 | power <<= 1; 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-for-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | // For loop. 17 | for i in { 0, 3, 5, 7, 9, 13 } { 18 | reset q; 19 | h q; 20 | cphase(power*3*pi/8) q, r; 21 | phase(-c) q; 22 | h q; 23 | measure q -> c[0]; 24 | c <<= 1; 25 | power <<= 1; 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-for-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | // For loop. 17 | for i in [0 : 2 : 5139] { 18 | reset q; 19 | h q; 20 | cphase(power*3*pi/8) q, r; 21 | phase(-c) q; 22 | h q; 23 | measure q -> c[0]; 24 | c <<= 1; 25 | power <<= 1; 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-for-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | const uint n = 3; 4 | qubit q; 5 | angle[n] c = 0; 6 | uint[n] power = 1; 7 | 8 | for i in [0: n - 1] { 9 | measure q -> c[0]; 10 | c <<= 1; 11 | power <<= 1; 12 | } 13 | -------------------------------------------------------------------------------- /tests/src/test-for-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | const uint n = 3; 4 | qubit q; 5 | angle[n] c = 0; 6 | uint[n] power = 1; 7 | 8 | for i in [0 : n << 1] { 9 | measure q -> c[0]; 10 | c <<= 1; 11 | power <<= 1; 12 | } 13 | -------------------------------------------------------------------------------- /tests/src/test-for-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | const int n = 64; 4 | 5 | qubit $0; 6 | qubit $1; 7 | 8 | bit[16] c; 9 | 10 | angle[n] a = 3.14159265358979323846; 11 | 12 | uint[n] power = 1; 13 | 14 | for i in [0 : n - 1] { 15 | reset $0; 16 | reset $1; 17 | 18 | measure $0 -> c[0]; 19 | measure $1 -> c[1]; 20 | 21 | if (c[0] == 1) { 22 | power <<= 1; 23 | } else { 24 | power <<= 3; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-for-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | // For loop. 17 | for uint i in { 0, 3, 5, 7, 9, 13 } { 18 | reset q; 19 | h q; 20 | cphase(power*3*pi/8) q, r; 21 | phase(-c) q; 22 | h q; 23 | measure q -> c[0]; 24 | c <<= 1; 25 | power <<= 1; 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-frame-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate test_gate(theta) q, r { 4 | U(pi / 2, pi, -pi) q; 5 | U(pi / 2, pi, -pi / 4) r; 6 | } 7 | 8 | cal { 9 | extern port p0; 10 | extern frame extern_frame; 11 | 12 | frame test_frame = newframe(p0, 5e9, 0.0); 13 | 14 | test_frame.phase = pi / 4; 15 | 16 | test_frame.frequency = 35e10; 17 | 18 | test_frame.time = 100ns; 19 | } 20 | 21 | qubit $0; 22 | qubit $1; 23 | 24 | test_gate $0, $1; 25 | -------------------------------------------------------------------------------- /tests/src/test-frame-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | cal { 7 | extern port p0; 8 | extern port p1; 9 | 10 | frame driveframe1 = newframe(p0, 5.1e9, 0.0); 11 | frame driveframe2 = newframe(p1, 5.2e9, 0.0); 12 | } 13 | 14 | defcal test_defcal(theta, lambda, phi) $0, $1 { 15 | delay[15ns] driveframe1; 16 | delay[110μs] driveframe2; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/test-frame-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdopenpulse.inc"; 4 | 5 | qubit $0; 6 | qubit $1; 7 | 8 | cal { 9 | extern port p0; 10 | extern port p1; 11 | 12 | frame driveframe1 = newframe(p0, 5.1e9, 0.0); 13 | frame driveframe2 = newframe(p1, 5.2e9, 0.0); 14 | } 15 | 16 | defcal test_defcal(theta, lambda, phi) $0, $1 { 17 | delay[15ns] driveframe1; 18 | delay[110μs] driveframe2; 19 | 20 | set_phase(driveframe1, pi); 21 | set_frequency(driveframe2, 0.0210315); 22 | } 23 | -------------------------------------------------------------------------------- /tests/src/test-frame-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | cal { 4 | array[frame, 16] xfa; 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/test-func-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x a { U(π, 0, π) a; } 4 | 5 | gate cx c, t { ctrl @ x c, t; } 6 | 7 | def xcheck(qubit[4] d, qubit a) -> bit { 8 | reset a; 9 | for i in [0:3] 10 | cx d[i], a; 11 | 12 | return measure a; 13 | } 14 | 15 | uint n = 32; 16 | 17 | def parity(bit[n] cin) -> bit { 18 | bit c; 19 | for i in [0:2:32] { 20 | c ^= cin[i]; 21 | } 22 | 23 | return c; 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test-func-10.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit q; 4 | qubit r; 5 | 6 | def noargs() -> bit { 7 | return measure q; 8 | } 9 | 10 | def noargs_noparens -> bit { 11 | return measure r; 12 | } 13 | 14 | def noargs_noresult() { 15 | return; 16 | } 17 | 18 | def args_noresult(int i, int j) { 19 | int k = i + j; 20 | return; 21 | } 22 | -------------------------------------------------------------------------------- /tests/src/test-func-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 9; 4 | 5 | def parity(bit[n] cin) -> bit { 6 | bit c; 7 | for i in [0:2:64] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | -------------------------------------------------------------------------------- /tests/src/test-func-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate cx c, t { 4 | CX c, t; 5 | } 6 | 7 | def xcheck (qubit[4] d, qubit a) -> bit { 8 | reset a; 9 | for i in [0:3] 10 | cx d[i], a; 11 | 12 | return measure a; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-func-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate cx c, t { 4 | CX c, t; 5 | } 6 | 7 | def xcheck(angle[32] k, qubit[4] d, qubit a) -> bit { 8 | reset a; 9 | for i in [0:3] 10 | cx d[i], a; 11 | 12 | return measure a; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-func-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | def xcheck(qubit[4] d, qubit a) -> bit { 6 | reset a; 7 | for i in [0:3] 8 | cx d[i], a; 9 | 10 | return measure a; 11 | } 12 | 13 | uint n = 100; 14 | 15 | def parity(bit[n] cin) -> bit { 16 | bit c; 17 | for i in [0:2:100] { 18 | c ^= cin[i]; 19 | } 20 | 21 | return c; 22 | } 23 | 24 | def both(bit[n] cin, angle[24] ang, float fin, qubit[4] d, qubit a) -> bit { 25 | reset a; 26 | for i in [0:3] 27 | cx d[i], a; 28 | 29 | bit c; 30 | for i in [0:2:100] { 31 | c ^= cin[i]; 32 | } 33 | 34 | if (c == 1) 35 | return c; 36 | 37 | return measure a; 38 | } 39 | -------------------------------------------------------------------------------- /tests/src/test-func-55.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | def xcheck(qubit[4] d, qubit a) -> bit { 6 | reset a; 7 | for i in [0:3] 8 | cx d[i], a; 9 | 10 | return measure a; 11 | } 12 | 13 | uint n = 8; 14 | 15 | def parity(bit[n] cin) -> bit { 16 | bit c; 17 | for i in [0:2:100] { 18 | c ^= cin[i]; 19 | } 20 | 21 | return c; 22 | } 23 | 24 | def both(bit[n] cin, angle[24] ang, float fin, qubit[4] d, qubit a) -> bit { 25 | reset a; 26 | for i in [0:3] 27 | cx d[i], a; 28 | 29 | bit c; 30 | for i in [0:2:100] { 31 | c ^= cin[i]; 32 | } 33 | 34 | if (c == 1) 35 | return c; 36 | 37 | return measure a; 38 | } 39 | -------------------------------------------------------------------------------- /tests/src/test-func-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def quantum_params(qubit a) -> bit { 4 | return measure a; 5 | } 6 | 7 | def classical_params(int i, float f) -> float { 8 | return i * f; 9 | } 10 | 11 | def mixed_params(int i, qubit b) -> bit { 12 | return measure b; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-func-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate cx c, t { 4 | CX c, t; 5 | } 6 | 7 | uint n = 16; 8 | 9 | def funcboth(bit[n] cin, angle[24] ang, float fin, qubit[4] d, qubit a) -> bit { 10 | reset a; 11 | for i in [0:3] 12 | cx d[i], a; 13 | 14 | bit c; 15 | for i in [0:2:16] { 16 | c ^= cin[i]; 17 | } 18 | 19 | if (c == 1) 20 | return c; 21 | 22 | return measure a; 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/test-func-8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate phase(lambda) q { 4 | U(0, 0, lambda) q; 5 | } 6 | 7 | gate cx c, t { 8 | CX c, t; 9 | } 10 | 11 | gate t a { 12 | phase(pi/4) a; 13 | } 14 | 15 | gate tdg a { 16 | phase(-pi/4) a; 17 | } 18 | 19 | gate h a { 20 | U(pi / 2, 0, pi) a; 21 | } 22 | 23 | gate s a { 24 | phase(pi / 2) a; 25 | } 26 | 27 | gate z a { 28 | phase(pi) a; 29 | } 30 | 31 | gate ccx a, b, c { 32 | h c; 33 | cx b, c; 34 | tdg c; 35 | cx a, c; 36 | t c; 37 | cx b, c; 38 | tdg c; 39 | cx a, c; 40 | t b; t c; h c; 41 | cx a, b; 42 | t a; tdg b; 43 | cx a, b; 44 | } 45 | 46 | def segment (qubit[2] anc, qubit psi) -> bit[2] { 47 | bit[2] b; 48 | reset anc; 49 | h anc; 50 | ccx anc[0], anc[1], psi; 51 | s psi; 52 | ccx anc[0], anc[1], psi; 53 | z psi; 54 | h anc; 55 | measure anc -> b; 56 | return b; 57 | } 58 | -------------------------------------------------------------------------------- /tests/src/test-func-9.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 32; 4 | 5 | def parity(bit[n] cin, ...) -> bit { 6 | bit c; 7 | for i in [0:2:32] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | 14 | def trueorfalse(int i, float f, angle[64] a) -> bool { 15 | if (i < 3) 16 | return true; 17 | else 18 | return false; 19 | } 20 | -------------------------------------------------------------------------------- /tests/src/test-func-call-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def foo(int i, qubit[8] d) -> bit { 4 | return measure d[i]; 5 | } 6 | 7 | int k = 1; 8 | int l = 2; 9 | 10 | qubit[8] $0; 11 | qubit $1; 12 | 13 | bit c1; 14 | bit c2; 15 | 16 | c1 = foo(k + l - 5, $0); 17 | 18 | def bar(float[32] f, angle[32] a, qubit j) -> bit { 19 | } 20 | 21 | float m = 4.5; 22 | 23 | angle[32] phi = 7.5; 24 | 25 | c2 = bar(m / 3, phi, $1); 26 | -------------------------------------------------------------------------------- /tests/src/test-func-call-10.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | extern test5(int[32] a) -> int[64]; 4 | 5 | int[32] e = 5; 6 | int[64] f; 7 | 8 | f = test5(e); 9 | -------------------------------------------------------------------------------- /tests/src/test-func-call-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 8; 4 | 5 | def parity(bit[n] cin) -> bit { 6 | bit c; 7 | for i in [0:2:100] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | 14 | bit result; 15 | qubit q; 16 | qubit r; 17 | 18 | bit bq = measure q; 19 | bit br = measure r; 20 | 21 | result = parity(bq || br); 22 | -------------------------------------------------------------------------------- /tests/src/test-func-call-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def baz(qubit j, qubit k) -> bit { 4 | reset j; 5 | reset k; 6 | 7 | U(pi, 0, pi) j; 8 | 9 | return measure k; 10 | } 11 | 12 | qubit $0; 13 | qubit $1; 14 | 15 | bit c2 = 0; 16 | 17 | c2 = baz($0, $1); 18 | -------------------------------------------------------------------------------- /tests/src/test-func-call-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def baz(qubit j, qubit k) -> bit { 4 | bit r = 0; 5 | 6 | reset j; 7 | reset k; 8 | 9 | U(pi, 0, pi) j; 10 | 11 | r = measure j; 12 | 13 | return r; 14 | } 15 | 16 | qubit $0; 17 | qubit $1; 18 | 19 | bit c2 = 0; 20 | 21 | baz($0, $1); 22 | -------------------------------------------------------------------------------- /tests/src/test-func-call-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 2; 4 | 5 | def parity(bit[n] cin) -> bit { 6 | bit c; 7 | for i in [0:2:100] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | 14 | def func_calls_parity(float f, int k, bit b) -> int { 15 | bit[2] k; 16 | return parity(k); 17 | } 18 | 19 | bit result; 20 | qubit q; 21 | qubit r; 22 | 23 | bit bq = measure q; 24 | bit br = measure r; 25 | 26 | result = parity(bq || br); 27 | 28 | float a0 = pi; 29 | 30 | int a1 = 20; 31 | 32 | int result2; 33 | 34 | result2 = func_calls_parity(a0, a1, parity(bq || br)); 35 | -------------------------------------------------------------------------------- /tests/src/test-func-call-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint size = 32; 4 | 5 | extern gaussian(complex[float[size]] amp, duration d, duration sigma) -> int; 6 | 7 | float[size] f = 35.35; 8 | 9 | duration ds = 15ns; 10 | 11 | duration ss = 150us; 12 | 13 | int r = gaussian(f, ds, ss); 14 | -------------------------------------------------------------------------------- /tests/src/test-func-call-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def bar(qubit j, qubit k, angle[32] y) -> bit { 4 | bit r = 0; 5 | 6 | reset j; 7 | reset k; 8 | 9 | U(pi, 0, pi) j; 10 | 11 | r = measure j; 12 | 13 | return r; 14 | } 15 | 16 | qubit $0; 17 | qubit $1; 18 | 19 | bit c2 = 0; 20 | 21 | bar($0, $1, pi / 2); 22 | 23 | bar($0, $1, -pi / 2); 24 | -------------------------------------------------------------------------------- /tests/src/test-func-call-8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def bar(qubit j, qubit k, angle[32] y) -> bit { 4 | reset j; 5 | reset k; 6 | 7 | U(pi, 0, pi) j; 8 | 9 | bit r = measure j; 10 | 11 | return r; 12 | } 13 | 14 | qubit $0; 15 | qubit $1; 16 | 17 | bit c2 = 0; 18 | 19 | c2 = bar($0, $1, ((-pi / 2) + ((tau * 15) - 64))); 20 | -------------------------------------------------------------------------------- /tests/src/test-func-call-9.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def foo(int i, qubit a, qubit b, qubit c) -> bit { 4 | if (i == 0) 5 | return measure a; 6 | else if (i == 1) 7 | return measure b; 8 | else 9 | return measure c; 10 | } 11 | 12 | int k = 1; 13 | int l = 5; 14 | 15 | qubit[8] $0; 16 | 17 | bit c1; 18 | 19 | c1 = foo(k + l - 3, $0[0], $0[1], $0[2]); 20 | -------------------------------------------------------------------------------- /tests/src/test-func-call.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def foo(int[16]:a) b -> bit { 4 | } 5 | 6 | int x = 1; 7 | int y = 2; 8 | 9 | foo(x + y % 5); 10 | 11 | def bar(float[32]:a, qubit:q) j -> bit { 12 | } 13 | 14 | float j = 3.5; 15 | 16 | bar(j % 3, %0); 17 | -------------------------------------------------------------------------------- /tests/src/test-function-gate-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | def function(int i) -> float { 4 | if (i == 0) 5 | return pi; 6 | 7 | return pi / 2; 8 | } 9 | 10 | gate function_gate(lambda, theta) q { 11 | U(0.0, lambda, theta) q; 12 | } 13 | 14 | qubit $0; 15 | 16 | int n = 3; 17 | 18 | function_gate(tau, function(n)) $0; 19 | -------------------------------------------------------------------------------- /tests/src/test-function-param-names.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[8] q; 4 | 5 | def test_function(int q) -> int { 6 | return q + 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/test-gate-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate u3(theta, phi, lambda) q { 4 | U(theta, phi, lambda) q; 5 | } 6 | 7 | gate u4(cherry, peach, apricot) q { 8 | U(cherry, peach, apricot) q; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-gate-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate phase(lambda) q { 4 | U(0, 0, lambda) q; 5 | } 6 | 7 | gate extra(lambda, theta, phi) q { 8 | U(phi, theta, lambda) q; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-gate-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate phase(lambda) q { 4 | U(0, 0, lambda) q; 5 | } 6 | 7 | gate extra(lambda, theta, phi) q { 8 | U(phi, theta, lambda) q; 9 | } 10 | 11 | angle[32] X = 1.0; 12 | angle[32] Y = 2.0; 13 | angle[32] Z = 3.0; 14 | 15 | qubit $0; 16 | qubit $1; 17 | 18 | phase(X) $0; 19 | 20 | extra(X, Y, Z) $1; 21 | -------------------------------------------------------------------------------- /tests/src/test-gate-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate test(angle[48] theta, angle[48] phi, angle[48] sigma) q, r, s { 4 | U(theta, 0.0, pi) q; 5 | U(phi, 0.0, pi / 2) r; 6 | U(sigma, 0.0, -pi / 4) s; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/test-gate-control-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate p(λ) a { ctrl @ gphase(λ) a; } 4 | 5 | gate z a { p(π) a; } 6 | 7 | gate s a { pow(1/2) @ z a; } 8 | 9 | gate tdg a { inv @ pow(1/2) @ s a; } 10 | -------------------------------------------------------------------------------- /tests/src/test-gate-control-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate p(λ) a { 4 | ctrl @ gphase(λ) a; 5 | } 6 | 7 | gate z a { 8 | p(π) a; 9 | } 10 | 11 | gate s a { 12 | pow(1/2) @ z a; 13 | } 14 | 15 | gate tdg a { 16 | inv @ pow(1/2) @ s a; 17 | } 18 | 19 | gate stdg a { 20 | inv @ pow(1/2) @ tdg a; 21 | inv @ pow(1/4) @ tdg a; 22 | inv @ pow(1/8) @ tdg a; 23 | } 24 | 25 | gate ctdg a, b { 26 | ctrl @ pow(1/2) @ tdg a, b; 27 | ctrl @ pow(1/4) @ tdg a, b; 28 | ctrl @ pow(1/8) @ tdg a, b; 29 | } 30 | 31 | gate wtdg(λ) a, b { 32 | ctrl @ pow(1/2) @ p(λ) a, b; 33 | ctrl @ pow(1/2) @ p(λ) a, b; 34 | ctrl @ pow(1/2) @ p(λ) a, b; 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/test-gate-cx.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate CX a, b { ctrl @ U(π, 0, π) a, b; } 4 | -------------------------------------------------------------------------------- /tests/src/test-gate-gphase.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate u3(θ, φ, λ) q { 4 | gphase(-(φ+λ)/2); 5 | U(θ, φ, λ) q; 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test-gate-noangle.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate test q, r { 4 | U(pi, 0.0, pi / 2) q; 5 | U(pi, 0.0, pi / 2) r; 6 | } 7 | 8 | qubit q; 9 | qubit r; 10 | -------------------------------------------------------------------------------- /tests/src/test-gate-pi.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate foo(pi) q { 4 | U(pi, 0, pi) q; 5 | } 6 | 7 | gate bar(tau) q { 8 | U(tau, 0, tau) q; 9 | } 10 | 11 | gate baz(euler) q { 12 | U (euler, 0, euler) q; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-gate-qops.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate phase(lambda) q { 4 | U(0, 0, lambda) q; 5 | } 6 | 7 | gate extra(lambda, theta, phi) q { 8 | U(phi, theta, lambda) q; 9 | phase(lambda) q; 10 | U(phi, theta, lambda) q; 11 | phase(lambda) q; 12 | } 13 | 14 | angle[32] X = 1.0; 15 | angle[32] Y = 2.0; 16 | angle[32] Z = 3.0; 17 | 18 | qubit $0; 19 | qubit $1; 20 | 21 | phase(X) $0; 22 | 23 | extra(X, Y, Z) $1; 24 | -------------------------------------------------------------------------------- /tests/src/test-gate-qubit.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate test(theta, phi) q, r { 4 | U(theta, 0.0, phi) q; 5 | U(theta, 0.0, phi) r; 6 | } 7 | 8 | qubit q; 9 | qubit r; 10 | -------------------------------------------------------------------------------- /tests/src/test-gate-switch.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x q { } 4 | 5 | qubit $0; 6 | 7 | int i = 0; 8 | 9 | switch (i) { 10 | case 0: { 11 | x $0; 12 | } 13 | break; 14 | default: 15 | break; 16 | } 17 | 18 | x $0; 19 | -------------------------------------------------------------------------------- /tests/src/test-gate.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate u3(theta, phi, lambda) q { 4 | U(theta, phi, lambda) q; 5 | } 6 | 7 | gate u4(cherry, peach, apricot) q { 8 | U(cherry, peach, apricot) q; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-german-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint bear = 15; 8 | uint Bär = 15; 9 | 10 | // int one = 1; 11 | int einz = 1; 12 | 13 | // int two = 2; 14 | int zwei = 2; 15 | 16 | // int three = 3; 17 | int drei = 3; 18 | 19 | // int four = 4; 20 | int vier = 4; 21 | 22 | // int five = 5; 23 | int fünf = 5; 24 | 25 | // gate resilient(lambda, theta, phi) ø { 26 | // U(phi, theta, lambda) ø; 27 | // } 28 | gate unverwüstlich(λ, φ, θ) ø { 29 | U(θ, φ, λ) ø; 30 | } 31 | 32 | // gate ferocious(lambda, theta, phi) ö { 33 | // U(phi, theta, lambda) ö; 34 | // } 35 | gate gründlich(λ, φ, θ) ö { 36 | U(θ, φ, λ) ö; 37 | } 38 | -------------------------------------------------------------------------------- /tests/src/test-gphase-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q[4]; 6 | 7 | gate rz(tau) q { 8 | gphase(-tau / 2); 9 | U(0, 0, tau) q; 10 | } 11 | 12 | ctrl @ rz(pi / 2) q[1], q[0]; 13 | -------------------------------------------------------------------------------- /tests/src/test-greek-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate greek(λ) a { 4 | U(π, 0.0, π) a; 5 | } 6 | 7 | angle[32] λ; 8 | 9 | gate roman(λ) q { 10 | U(π, 0.0, π) q; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-hadamard-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Clifford gate: Hadamard 4 | gate h a { 5 | U(pi / 2, 0, pi) a; 6 | U(2 * pi, 0, pi) a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/test-hadamard.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Clifford gate: Hadamard 4 | gate h a { 5 | U(pi / 2, 0, pi) a; 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test-hiragana-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint integer = 15; 8 | uint 整数 = 15; 9 | 10 | // int A = 1; 11 | int あ = 1; 12 | 13 | // int E = 2; 14 | int え = 2; 15 | 16 | // int I = 3; 17 | int い = 3; 18 | 19 | // int U = 4; 20 | int う = 4; 21 | 22 | // int O (oh) = 5; 23 | int お = 5; 24 | 25 | // Using Hiragana characters: 26 | // gate hiragana(lambda, theta, phi) unit { 27 | // U(phi, theta, lambda) unit; 28 | // } 29 | gate ひらがな(λ, φ, θ) 単位 { 30 | U(θ, φ, λ) 単位; 31 | } 32 | 33 | // Using Katakana characters: 34 | // gate hiragana(lambda, theta, phi) unit { 35 | // U(phi, theta, lambda) unit; 36 | // } 37 | gate 平仮名(λ, φ, θ) ユーニット { 38 | U(θ, φ, λ) ユーニット; 39 | } 40 | -------------------------------------------------------------------------------- /tests/src/test-identifier-overloading.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate test_gate(theta, lambda, phi) q { 4 | U(-pi, theta, -lambda) q; 5 | } 6 | 7 | double theta = pi * 4; 8 | 9 | def function(int sigma, double theta, angle[64] phi) -> int { 10 | float[64] lambda = 1.5; 11 | float[64] rho = lambda / pi; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/src/test-identifier.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint m = 64; 4 | uint n = 128; 5 | 6 | array[float, m] af; 7 | 8 | array[float[n], n] fi; 9 | 10 | array[complex[float[128]], 64] jk; 11 | 12 | array[complex[float[n]], 64] ca; 13 | 14 | float[128] k = 15.0; 15 | 16 | complex[float[128]] ck; 17 | 18 | int i = 10; 19 | 20 | extern port p0; 21 | 22 | duration dr = 800dt; 23 | 24 | qubit $0; 25 | 26 | qubit q; 27 | 28 | qubit[8] qq; 29 | 30 | array[qubit, 32] aq; 31 | 32 | array[qubit[8], 32] anq; 33 | 34 | array[bit, m] ba; 35 | 36 | array[bit[m], n] bba; 37 | 38 | frame test_frame = newframe(p0, 5e9, 0.0); 39 | -------------------------------------------------------------------------------- /tests/src/test-idref-scope.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[2] d; 4 | 5 | qubit $0; 6 | 7 | if (d[0] == 1) { 8 | d[1] = d[0]; 9 | } 10 | 11 | d[1] = measure $0; 12 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle k = 12345.6789; 4 | angle j = 54321.9876; 5 | 6 | float a = 31.3; 7 | float b = 62.6; 8 | 9 | float[128] f0; 10 | float[128] f1 = pi; 11 | 12 | // 1. Simple one-line expression test. 13 | if (k == a) { 14 | f0 = cos(f1); 15 | } else { 16 | f0 = sin(f1); 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-10.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate H q { } 4 | 5 | gate X q { } 6 | 7 | gate Z q { } 8 | 9 | bit c0; 10 | bit c1; 11 | 12 | qubit $0; 13 | qubit $1; 14 | 15 | int i = 3; 16 | int j = 4; 17 | 18 | c0 = measure $0; 19 | c1 = measure $1; 20 | 21 | if (c0 == i) { 22 | H $0; 23 | H $0; 24 | H $0; 25 | } else if (c0 > i) { 26 | Z $0; 27 | Z $0; 28 | Z $0; 29 | if (c1 == j) { 30 | H $1; 31 | Z $1; 32 | X $1; 33 | } else if (c1 > j) { 34 | X $1; 35 | Z $1; 36 | H $1; 37 | } else if (c1 == c0) { 38 | Z $0; 39 | X $0; 40 | Z $0; 41 | } else { 42 | Z $0; 43 | Z $1; 44 | } 45 | } else { 46 | X $0; 47 | X $0; 48 | X $0; 49 | } 50 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-11.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int a; 4 | int b; 5 | int c; 6 | int d; 7 | 8 | int i; 9 | int j; 10 | int k; 11 | 12 | qubit $0; 13 | qubit $1; 14 | qubit $2; 15 | 16 | gate H q { } 17 | 18 | gate Z q { } 19 | 20 | if (a == 3) { 21 | b = 9; 22 | H $0; 23 | H $0; 24 | H $0; 25 | } else if (a > 3) { 26 | Z $1; 27 | Z $1; 28 | 29 | if (b == 2) { 30 | if (c > a) { 31 | H $2; 32 | Z $2; 33 | d *= 4; 34 | } else if (c < a) { 35 | d = c; 36 | } else { 37 | Z $0; 38 | Z $0; 39 | Z $0; 40 | Z $0; 41 | } 42 | } else { 43 | i = 1; 44 | j = 2; 45 | k = 3; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-12.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 3-parameter 2-pulse single qubit gate 4 | gate u3(theta,phi,lambda) q { U(theta,phi,lambda) q; } 5 | 6 | // 2-parameter 1-pulse single qubit gate 7 | gate u2(phi,lambda) q { U(pi/2,phi,lambda) q; } 8 | 9 | // 1-parameter 0-pulse single qubit gate 10 | gate u1(lambda) q { U(0,0,lambda) q; } 11 | 12 | int i = 35; 13 | int j = 40; 14 | int k = 45; 15 | 16 | // 1. Dangling else-if (no closing else) expression test. 17 | if (i == j || i > k) { 18 | u1(-pi / 4) a; 19 | u1(-pi / 4) a; 20 | u1(-pi / 4) a; 21 | } else { 22 | if (k > j && j > i) { 23 | u2(-pi / 2, 0) b; 24 | u2(-pi / 2, 0) b; 25 | u2(-pi / 2, 0) b; 26 | } else { 27 | u3(pi, 0, pi) c; 28 | u3(pi, 0, pi) c; 29 | u3(pi, 0, pi) c; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-13.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 15; 4 | int j = 30; 5 | int k = 45; 6 | 7 | if (i < 30 && j > 25) { 8 | uint k = 30 * 2; 9 | k -= j; 10 | } else { 11 | uint k = 30 / 2; 12 | k += i; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle k = 12345.6789; 4 | angle j = 54321.9876; 5 | 6 | float a = 31.3; 7 | float b = 62.6; 8 | 9 | float[128] f0; 10 | float[128] f1 = pi; 11 | 12 | // 1. Simple one-line expression test. 13 | if (k == a) { 14 | f0 = cos(f1); 15 | } else if (j == b) { 16 | f0 = sin(f1) + k; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle k = 12345.6789; 4 | angle j = 54321.9876; 5 | 6 | float a = 31.3; 7 | float b = 62.6; 8 | 9 | float[128] f0; 10 | float[128] f1 = pi; 11 | 12 | // 1. Simple one-line expression test. 13 | if (k == a) { 14 | f0 = cos(f1); 15 | } else if (j == b) { 16 | f0 = sin(f1) + k; 17 | } else { 18 | f0 = sin(f1) - (k + cos(f1)); 19 | } 20 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Test gate expressions - no meaning. 4 | gate tg2(lambda, theta) q, r { } 5 | 6 | gate tg3(lambda, theta, phi) q { } 7 | 8 | angle e; 9 | angle f; 10 | angle g; 11 | 12 | float[64] a; 13 | float[64] b; 14 | 15 | qubit $0; 16 | qubit $1; 17 | 18 | // 1. Dangling else-if (no closing else) expression test. 19 | if (e == a) { 20 | tg3(pi, 0, pi) z; 21 | tg3(-pi, 0, -pi) $1; 22 | } else { 23 | if (f == b) { 24 | tg2(-pi / 2, 0) $0, $1; 25 | tg2(-pi / 2, 0) $0, $1; 26 | tg2(-pi / 2, 0) $0, $1; 27 | } else { 28 | tg3(pi, 0, pi) $1; 29 | tg3(pi, 0, pi) $1; 30 | tg3(pi, 0, pi) $1; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate H a { U(π/2, 0, π) a; } 4 | 5 | gate Z a { U(π/2, 0, π/4) a; } 6 | 7 | bit qc0; 8 | qubit $0; 9 | 10 | int i = 3; 11 | 12 | int j = 4; 13 | 14 | qc0 = measure $0; 15 | 16 | if (qc0 == i) { 17 | H $0; 18 | H $0; 19 | H $0; 20 | H $0; 21 | H $0; 22 | H $0; 23 | } else if (qc0 == j) { 24 | Z $0; 25 | Z $0; 26 | Z $0; 27 | } else { 28 | H $0; 29 | Z $0; 30 | H $0; 31 | Z $0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate H a { U(π/2, 0, π) a; } 4 | 5 | gate Z a { U(π/2, 0, π/4) a; } 6 | 7 | gate X q { } 8 | 9 | bit qc0; 10 | qubit $0; 11 | 12 | int i = 3; 13 | int j = 4; 14 | 15 | qc0 = measure $0; 16 | 17 | if (qc0 == i) { 18 | H $0; 19 | H $0; 20 | H $0; 21 | } else { 22 | if (qc0 == j) { 23 | Z $0; 24 | Z $0; 25 | Z $0; 26 | } else { 27 | X $0; 28 | X $0; 29 | X $0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-7.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate H a { U(π/2, 0, π) a; } 4 | 5 | gate Z a { U(π/2, 0, π/4) a; } 6 | 7 | bit qc0; 8 | 9 | qubit $0; 10 | qubit $1; 11 | 12 | qc0 = measure $0; 13 | 14 | if (qc0) { 15 | H $0; 16 | H $0; 17 | H $0; 18 | H $0; 19 | } else { 20 | Z $0; 21 | Z $1; 22 | Z $0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[20] b; 4 | 5 | qubit $0; 6 | 7 | int c; 8 | int d; 9 | int e; 10 | 11 | b[0] = measure $0; 12 | 13 | if (!b[0]) { 14 | c = 3; 15 | d = c - 1; 16 | e = c + d; 17 | } else { 18 | c = 4; 19 | d = c * 2; 20 | e = c * d; 21 | } 22 | -------------------------------------------------------------------------------- /tests/src/test-ifelse-9.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate H q { } 4 | 5 | gate X q { } 6 | 7 | gate Z q { } 8 | 9 | bit c0; 10 | bit c1; 11 | 12 | qubit $0; 13 | qubit $1; 14 | 15 | int i = 3; 16 | int j = 4; 17 | 18 | c0 = measure $0; 19 | c1 = measure $1; 20 | 21 | if (c0 == i) { 22 | H $0; 23 | H $0; 24 | H $0; 25 | } else if (c0 > i) { 26 | Z $0; 27 | Z $0; 28 | Z $0; 29 | if (c1 == j) { 30 | H $1; 31 | Z $1; 32 | X $1; 33 | } else if (c1 > j) { 34 | X $1; 35 | Z $1; 36 | H $1; 37 | } 38 | } else { 39 | X $0; 40 | X $0; 41 | X $0; 42 | } 43 | -------------------------------------------------------------------------------- /tests/src/test-include-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" ; 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" ; 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" ; 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-c++-comment-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; // 4 | // This is a multi-line C++ comment. 5 | // It continues on this line. 6 | // 7 | 8 | int i = 31; 9 | -------------------------------------------------------------------------------- /tests/src/test-include-c++-comment-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; // This is a multi-line C++ comment. 4 | // It continues on this line. 5 | // 6 | 7 | int i = 31; 8 | -------------------------------------------------------------------------------- /tests/src/test-include-c++-comment-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; // This is a single-line C++ comment. 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-c-comment-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; /* This is a single-line C comment. */ 4 | 5 | int i = 31; 6 | -------------------------------------------------------------------------------- /tests/src/test-include-c-comment-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; /* This is a multi-line C comment. 4 | * It continues on this line. 5 | */ 6 | 7 | int i = 31; 8 | -------------------------------------------------------------------------------- /tests/src/test-include-c-comment-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; /* 4 | * This is a multi-line C comment. 5 | * It continues on this line. 6 | */ 7 | 8 | int i = 31; 9 | -------------------------------------------------------------------------------- /tests/src/test-include-c-comment-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; /* 4 | * This is a multi-line C comment. 5 | * It continues on this line. 6 | */ 7 | 8 | int i = 31; 9 | -------------------------------------------------------------------------------- /tests/src/test-induction-var-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] bs; 4 | 5 | for i in [0 : 4] { 6 | bs |= i; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/test-induction-var-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] bs; 4 | 5 | int x = 3; 6 | 7 | if (x < 4) { 8 | for i in [0 : 4] { 9 | bs |= i; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-induction-var-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[32] bs; 4 | 5 | for uint i in [0 : 4] { 6 | bs |= i; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/test-input.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | input angle[32] a; 4 | 5 | input bit[32] b; 6 | -------------------------------------------------------------------------------- /tests/src/test-int-array.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[int, 16] iia; 4 | 5 | array[uint, 16] uia; 6 | -------------------------------------------------------------------------------- /tests/src/test-int-cast.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 30; 4 | 5 | while (bool(i)) { 6 | if (i > 0) { 7 | i -= 1; 8 | } 9 | } 10 | 11 | i = 45; 12 | -------------------------------------------------------------------------------- /tests/src/test-int-int.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint bar = 12U; 4 | 5 | int uint foo = 3; 6 | -------------------------------------------------------------------------------- /tests/src/test-inverse-trig-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | double d = 3.0; 4 | 5 | double c = cos(d); 6 | 7 | double s = sin(d); 8 | 9 | double t = tan(d); 10 | 11 | double ac = arccos(d); 12 | 13 | double as = arcsin(d); 14 | 15 | double at = arctan(d); 16 | -------------------------------------------------------------------------------- /tests/src/test-inverse-trig-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float f = 3.0; 4 | 5 | float c = cos(f); 6 | 7 | float s = sin(f); 8 | 9 | float t = tan(f); 10 | 11 | float ac = arccos(f); 12 | 13 | float as = arcsin(f); 14 | 15 | float at = arctan(f); 16 | -------------------------------------------------------------------------------- /tests/src/test-isexc-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $1; 4 | 5 | bit is_excited; 6 | 7 | if (is_excited) { 8 | if (is_excited) { 9 | U $1; 10 | U $1; 11 | U $1; 12 | } 13 | 14 | H $1; 15 | H $1; 16 | H $1; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/test-isexc-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $1; 4 | 5 | bit is_excited; 6 | 7 | if (is_excited) { 8 | H $1; 9 | H $1; 10 | H $1; 11 | 12 | if (is_excited) { 13 | U $1; 14 | U $1; 15 | U $1; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/test-isexc-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate X q { } 4 | 5 | qubit $1; 6 | 7 | bit is_excited; 8 | 9 | if (is_excited) { 10 | if (is_excited) { 11 | U $1; 12 | U $1; 13 | U $1; 14 | } else { 15 | X $1; 16 | X $1; 17 | X $1; 18 | } 19 | 20 | H $1; 21 | H $1; 22 | H $1; 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/test-isexc-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate X q { } 4 | 5 | qubit $1; 6 | 7 | bit is_excited; 8 | 9 | if (is_excited) { 10 | H $1; 11 | H $1; 12 | H $1; 13 | 14 | if (is_excited) { 15 | U $1; 16 | U $1; 17 | U $1; 18 | } else { 19 | X $1; 20 | X $1; 21 | X $1; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/test-katakana-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint integer = 15; 8 | uint インテジャー = 15; 9 | 10 | // int one = 1; 11 | int ワン = 1; 12 | 13 | // int two = 2; 14 | int トゥー = 2; 15 | 16 | // int three = 3; 17 | int スリー = 3; 18 | 19 | // int four = 4; 20 | int フォー = 4; 21 | 22 | // int five = 5; 23 | int ファイブ = 5; 24 | 25 | // Using Hiragana characters: 26 | // gate katakana(lambda, theta, phi) unit { 27 | // U(phi, theta, lambda) unit; 28 | // } 29 | gate カタカナ(λ, φ, θ) 単位 { 30 | U(θ, φ, λ) 単位; 31 | } 32 | 33 | // Using Katakana characters: 34 | // gate katakana(lambda, theta, phi) unit { 35 | // U(phi, theta, lambda) unit; 36 | // } 37 | gate 片仮名(λ, φ, θ) ユーニット { 38 | U(θ, φ, λ) ユーニット; 39 | } 40 | -------------------------------------------------------------------------------- /tests/src/test-kernel-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 1. Kernel declaration with no statements. 4 | extern test_kernel_1(qubit[4] d, qubit a) -> bit; 5 | 6 | uint n = 100; 7 | 8 | // 2. Kernel declaration with statements. 9 | extern test_kernel_2(bit[n] cin, qubit a) -> bit { } 10 | 11 | // 3. Kernel declaration with classical arguments. 12 | extern test_kernel_3(int i, float[32] f) -> float[32]; 13 | 14 | // 4. Kernel declaration with no statements and mixed parameter types. 15 | extern test_kernel_4(qubit[4] d, qubit a, int[128] i, float[32] f) -> bit; 16 | 17 | // 5. Kernel declaration with statements and mixed parameter types. 18 | extern test_kernel_5(qubit[4] d, qubit a, int[128] i, float[128] f) -> bit[8] { } 19 | -------------------------------------------------------------------------------- /tests/src/test-kernel-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 1. Kernel declaration with classical arguments. 4 | extern test_kernel_3(int i, float[32] f) -> float[32]; 5 | -------------------------------------------------------------------------------- /tests/src/test-kernel-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint m = 64; 4 | 5 | uint n = 128; 6 | 7 | // 1. Extern declaration with no statements and mixed parameter types. 8 | extern test_kernel_1(qubit[4] d, qubit a, complex[float[n]] c, int i) -> bit; 9 | 10 | // 2. Another extern declaration. 11 | extern test_kernel_2(int a, int[m] b, float c, float[n] d) -> int; 12 | -------------------------------------------------------------------------------- /tests/src/test-kernel-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 128; 4 | 5 | extern gaussian_1(complex[float[n]] amp, duration d, duration sigma) -> int; 6 | 7 | extern gaussian_2(complex[float[n]] amp, duration[15ns] d, duration sigma) -> int; 8 | 9 | extern sine(complex[float[n]] amp, duration d, float[n] freq, angle[n] phs) -> int; 10 | -------------------------------------------------------------------------------- /tests/src/test-korean-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint number = 15; 8 | uint 번호 = 15; 9 | 10 | // int one = 1; 11 | int 하나 = 1; 12 | 13 | // int two = 2; 14 | int 두의 = 2; 15 | 16 | // int three = 3; 17 | int 삼점 = 3; 18 | 19 | // int four = 4; 20 | int 네 = 4; 21 | 22 | // int five = 5; 23 | int 다섯 = 5; 24 | 25 | // gate firstgate(lambda, theta, phi) unit { 26 | // U(phi, theta, lambda) unit; 27 | // } 28 | gate 첫번째게이트(λ, φ, θ) 단위 { 29 | U(θ, φ, λ) 단위; 30 | } 31 | 32 | // gate secondgate(lambda, theta, phi) single { 33 | // U(phi, theta, lambda) single; 34 | // } 35 | gate 두번째게이트(λ, φ, θ) 하나의 { 36 | U(θ, φ, λ) 하나의; 37 | } 38 | 39 | // gate first_gate(lambda, theta, phi) unit { 40 | // U(phi, theta, lambda) unit; 41 | // } 42 | gate 첫번째_게이트(λ, φ, θ) 단위 { 43 | U(θ, φ, λ) 단위; 44 | } 45 | 46 | // gate second_gate(lambda, theta, phi) single { 47 | // U(phi, theta, lambda) single; 48 | // } 49 | gate 두번째_게이트(λ, φ, θ) 하나의 { 50 | U(θ, φ, λ) 하나의; 51 | } 52 | -------------------------------------------------------------------------------- /tests/src/test-length-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" 4 | 5 | // 1. Fixed length, in standard units 6 | length a = 300ns; 7 | 8 | // 2. Fixed length, backend dependent 9 | length b = 800dt; 10 | 11 | // 3. Fixed length, referencing the duration of a calibrated gate 12 | length c = lengthof(h); 13 | 14 | // 4. Dynamic length, referencing a box within its context 15 | qubit[8] q; 16 | 17 | box bx { 18 | cx q[0], q[1]; 19 | reset q; 20 | } 21 | 22 | length d = lengthof(bx); 23 | -------------------------------------------------------------------------------- /tests/src/test-length-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | length a = 300ns; 6 | 7 | length b = lengthof($0); 8 | 9 | stretch c; 10 | 11 | // stretchy length with min=300ns 12 | length d = a + 2 * c; 13 | 14 | // stretchy length with backtracking by up to half b 15 | length e = -0.5 * b + c; 16 | -------------------------------------------------------------------------------- /tests/src/test-length.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc" 4 | 5 | // 1. Fixed length, in standard units 6 | length a = 300ns; 7 | 8 | // 2. Fixed length, backend dependent 9 | length b = 800dt; 10 | 11 | // 3. Fixed length, referencing the duration of a calibrated gate 12 | length c = lengthof(h); 13 | 14 | // 4. Dynamic length, referencing a box within its context 15 | qubit[8] q; 16 | 17 | box bx { 18 | cx q[0], q[1]; 19 | reset q; 20 | } 21 | 22 | length d = lengthof(bx); 23 | 24 | // 5. Length initialization list 25 | length la, lb, lc, ld = 500ns; 26 | -------------------------------------------------------------------------------- /tests/src/test-let-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Qubit declarations 4 | qubit[2] one; 5 | qubit[10] two; 6 | 7 | // Aliased register of twelve qubits 8 | let concatenated = one ++ two; 9 | -------------------------------------------------------------------------------- /tests/src/test-let-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 1. Qubit array declaration. 4 | qubit[10] ten; 5 | 6 | // 2. Another qubit array declaration. 7 | qubit[20] twenty; 8 | 9 | // 3. First qubit in qubit array. 10 | let first = ten[0]; 11 | 12 | // 4. Last qubit in qubit array. 13 | let last = twenty[-1]; 14 | -------------------------------------------------------------------------------- /tests/src/test-let-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Qubit declarations 4 | qubit[2] one; 5 | qubit[10] two; 6 | 7 | // Aliased register of twelve qubits 8 | let concatenated = one ++ two; 9 | 10 | // First qubit in aliased qubit array 11 | let first = concatenated[0]; 12 | 13 | // Last qubit in aliased qubit array 14 | let last = concatenated[-1]; 15 | 16 | // Qubits zero, three and five 17 | let qubit_selection = two[0, 3, 5]; 18 | 19 | // First six qubits in aliased qubit array 20 | let sliced = concatenated[0:6]; 21 | 22 | // Every second qubit 23 | let every_second = concatenated[0:2:11]; 24 | 25 | // Using negative ranges to take the last 3 elements 26 | let last_three = two[-4:-1]; 27 | 28 | // Concatenate two alias in another one 29 | let both = sliced ++ last_three; 30 | -------------------------------------------------------------------------------- /tests/src/test-let-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Qubit declarations 4 | qubit[2] one; 5 | qubit[10] two; 6 | qubit[8] three; 7 | 8 | // Aliased register of twelve qubits 9 | let concatenated = one || two; 10 | 11 | // Another aliased register of eighteen qubits 12 | let glued = two ++ three; 13 | -------------------------------------------------------------------------------- /tests/src/test-let-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[16] q; 4 | 5 | let j = q[4] || q[8]; 6 | 7 | let k = q[7] ++ q[13]; 8 | 9 | let n = q[3] || q[6] || q[9] || q[12]; 10 | 11 | let t = q[3] ++ q[5] ++ q[7] ++ q[11]; 12 | -------------------------------------------------------------------------------- /tests/src/test-let-6.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[16] q; 4 | 5 | qubit[3] z; 6 | 7 | let j = q[4] || q[8] || z[0]; 8 | 9 | let k = q[7] ++ q[13] ++ z[1]; 10 | 11 | let n = q[3] || q[6] || q[9] || z; 12 | 13 | let x = q[3] ++ q[6] ++ z ++ q[9]; 14 | -------------------------------------------------------------------------------- /tests/src/test-let.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // Qubit declarations 4 | qubit[2] one; 5 | qubit[10] two; 6 | 7 | // Aliased register of twelve qubits 8 | let concatenated = one || two; 9 | 10 | // First qubit in aliased qubit array 11 | let first = concatenated[0]; 12 | 13 | // Last qubit in aliased qubit array 14 | let last = concatenated[-1]; 15 | 16 | // Qubits zero, three and five 17 | let qubit_selection = two[0, 3, 5]; 18 | 19 | // First six qubits in aliased qubit array 20 | let sliced = concatenated[0:6]; 21 | 22 | // Every second qubit 23 | let every_second = concatenated[0:2:12]; 24 | 25 | // Using negative ranges to take the last 3 elements 26 | let last_three = two[-4:-1]; 27 | 28 | // Concatenate two alias in another one 29 | let both = sliced || last_three; 30 | -------------------------------------------------------------------------------- /tests/src/test-logical-bang.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 15; 4 | 5 | int j = 0; 6 | 7 | if (!i) { 8 | j = 10; 9 | } else { 10 | j = 1; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-logical-or.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint a = 3; 4 | uint b = 5; 5 | uint c = 7; 6 | 7 | uint d = a || b || c; 8 | -------------------------------------------------------------------------------- /tests/src/test-mangled-complex.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] R = 87.395; 4 | 5 | float[128] S = 71.873; 6 | 7 | complex[float[64]] C = R + 29.443 im; 8 | 9 | complex[float[128]] D = S + 31.995 im; 10 | 11 | complex[float] F = 1.5f * 2.5f im; 12 | 13 | complex[int[128]] CI = 5 + 10 im; 14 | 15 | complex[uint[128]] CU = 20 + 30 im; 16 | -------------------------------------------------------------------------------- /tests/src/test-mangled-defcal.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | defcalgrammar "openpulse"; 4 | 5 | qubit $0; 6 | qubit $1; 7 | qubit $2; 8 | qubit[8] $3; 9 | 10 | uint n = 64U; 11 | 12 | defcal rz(theta, lambda, phi) $1, $2 { } 13 | 14 | defcal rx(theta) $3[0] { } 15 | -------------------------------------------------------------------------------- /tests/src/test-mangled-gates.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x a { U(π, 0, π) a; } 4 | 5 | gate rx(θ) a { U(θ, -π/2, π/2) a; } 6 | 7 | gate triple(θ, μ, γ) r, s, t { 8 | U(θ, -π/2, π/2) r; 9 | U(-π/2, μ, π/2) s; 10 | U(-π/2, π/2, γ) t; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-measure-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | bit c; 6 | 7 | measure $0 -> c; 8 | -------------------------------------------------------------------------------- /tests/src/test-measure.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[16] q; 4 | bit[16] c; 5 | 6 | c[0] = measure q[2]; 7 | c[1] = measure q[1]; 8 | c[2] = measure q[0]; 9 | 10 | c[4:7] = measure q[8:11]; 11 | c[10:8] = measure q[3:5]; 12 | -------------------------------------------------------------------------------- /tests/src/test-modulo.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float q = 13.5; 4 | 5 | uint j; 6 | 7 | int k; 8 | 9 | uint n; 10 | 11 | int u; 12 | 13 | j = q % 3; 14 | 15 | k = 17 % 4; 16 | 17 | n = 32 % j; 18 | 19 | u = q % n; 20 | 21 | qubit %0; 22 | qubit %1; 23 | 24 | reset %0; 25 | reset %1; 26 | -------------------------------------------------------------------------------- /tests/src/test-mpd-binaryop.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[128] f0 = 15.30; 4 | 5 | f0 = pi / 2; 6 | -------------------------------------------------------------------------------- /tests/src/test-mpdecimal-array.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[float[128], 16] ffa; 4 | -------------------------------------------------------------------------------- /tests/src/test-mpdecimal.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[128] fa = "1234567890.0987654321"; 4 | 5 | float[128] fb = "908978675645342312.213243546576879809"; 6 | 7 | float[128] nfa = "-1234567890.0987654321"; 8 | 9 | float[128] nfb = "-908978675645342312.213243546576879809"; 10 | -------------------------------------------------------------------------------- /tests/src/test-mpfloat.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[64] f = 0.5432112345; 4 | -------------------------------------------------------------------------------- /tests/src/test-mpinteger-array.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[int[128], 16] iia; 4 | 5 | array[uint[128], 16] uia; 6 | -------------------------------------------------------------------------------- /tests/src/test-mpinteger.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int[128] i = "-12345678900987654321123456789009876543210"; 4 | 5 | uint[128] u = "12345678900987654321123456789009876543210"; 6 | 7 | int[128] ib = "-0b01010101010101010101010101010101010101010101"; 8 | 9 | uint[128] ub = "0b01010101010101010101010101010101010101010101"; 10 | 11 | int[128] ix = "-0x1234567890abcdef09876543210fedcba"; 12 | 13 | uint[128] ux = "0x1234567890abcdef09876543210fedcba"; 14 | 15 | int[128] io = "-0o0123456776543210123456776543210"; 16 | 17 | uint[128] uo = "0o0123456776543210123456776543210"; 18 | -------------------------------------------------------------------------------- /tests/src/test-multi-else.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate j q { } 4 | 5 | gate k q { } 6 | 7 | gate l q { } 8 | 9 | gate m q { } 10 | 11 | gate n q { } 12 | 13 | gate a q { } 14 | 15 | gate b q { } 16 | 17 | gate c q { } 18 | 19 | gate d q { } 20 | 21 | gate e q { } 22 | 23 | 24 | bit[5] x; 25 | bit[5] y; 26 | 27 | qubit $0; 28 | qubit $1; 29 | qubit $2; 30 | qubit $3; 31 | qubit $4; 32 | 33 | if (x[0] == 0) { 34 | j $0; 35 | k $1; 36 | l $2; 37 | m $3; 38 | n $4; 39 | } else { 40 | if (y[0] == 0) { 41 | a $0; 42 | if (y[1] == 0) { 43 | b $1; 44 | if (y[2] == 0) { 45 | c $2; 46 | if (y[3] == 0) { 47 | d $3; 48 | if (y[4] == 0) { 49 | e $4; 50 | } else { 51 | n $4; 52 | } 53 | } else { 54 | m $3; 55 | } 56 | } else { 57 | l $2; 58 | } 59 | } else { 60 | k $1; 61 | } 62 | } else { 63 | j $0; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/src/test-multi-elseif-no-braces.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i; 4 | 5 | gate x q { } 6 | 7 | gate y q { } 8 | 9 | qubit $0; 10 | qubit $1; 11 | qubit $2; 12 | qubit $3; 13 | qubit $4; 14 | qubit $5; 15 | qubit $6; 16 | qubit $7; 17 | 18 | if (i == 1) 19 | x $0; 20 | else if (i == 2) 21 | x $1; 22 | else if (i == 3) 23 | x $2; 24 | else if (i == 4) 25 | x $3; 26 | else if (i == 5) 27 | x $4; 28 | else if (i == 6) 29 | x $5; 30 | else if (i == 7) 31 | x $6; 32 | else if (i == 8) 33 | x $7; 34 | else 35 | y $1; 36 | -------------------------------------------------------------------------------- /tests/src/test-multi-if.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate j q { } 4 | 5 | gate k q { } 6 | 7 | gate l q { } 8 | 9 | gate m q { } 10 | 11 | gate n q { } 12 | 13 | gate a q { } 14 | 15 | gate b q { } 16 | 17 | gate c q { } 18 | 19 | gate d q { } 20 | 21 | gate e q { } 22 | 23 | 24 | bit[5] x; 25 | bit[5] y; 26 | 27 | qubit $0; 28 | qubit $1; 29 | qubit $2; 30 | qubit $3; 31 | qubit $4; 32 | 33 | if (x[0] == 0) { 34 | j $0; 35 | if (x[1] == 0) { 36 | k $1; 37 | if (x[2] == 0) { 38 | l $2; 39 | if (x[3] == 0) { 40 | m $3; 41 | if (x[4] == 0) { 42 | n $4; 43 | } else { 44 | e $4; 45 | } 46 | } else { 47 | d $3; 48 | } 49 | } else { 50 | c $2; 51 | } 52 | } else { 53 | b $1; 54 | } 55 | } else { 56 | a $0; 57 | b $1; 58 | c $2; 59 | d $3; 60 | e $4; 61 | } 62 | -------------------------------------------------------------------------------- /tests/src/test-neg-trig.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float f = -sin(3.0); 4 | 5 | float df = f - sin(5.0); 6 | 7 | bool b = !cos(3.0); 8 | 9 | b = !sin(5.0); 10 | -------------------------------------------------------------------------------- /tests/src/test-negative-angle.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle[64] nega = -12; 4 | -------------------------------------------------------------------------------- /tests/src/test-negative-expression.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int p = 35; 4 | 5 | int q = -p; 6 | -------------------------------------------------------------------------------- /tests/src/test-negative-pi.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | double d = -pi * 2; 4 | -------------------------------------------------------------------------------- /tests/src/test-nested-elseif.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x q { } 4 | 5 | gate y q { } 6 | 7 | qubit $0; 8 | qubit $1; 9 | qubit $2; 10 | qubit $3; 11 | qubit $4; 12 | qubit $5; 13 | 14 | int i; 15 | int j; 16 | int k; 17 | 18 | if (i == 0) { 19 | x $0; 20 | y $0; 21 | } else if (i == 1) { 22 | x $1; 23 | y $1; 24 | if (j == 2) { 25 | x $2; 26 | y $2; 27 | } else if (j == 3) { 28 | x $3; 29 | y $3; 30 | } else if (j == 5) { 31 | x $5; 32 | y $5; 33 | } 34 | } else if (i == 2) { 35 | x $2; 36 | y $2; 37 | } else if (i == 3) { 38 | x $3; 39 | y $3; 40 | if (k == 5) { 41 | x $1; 42 | y $1; 43 | } else if (k == 6) { 44 | x $2; 45 | y $2; 46 | } else if (k == 7) { 47 | x $3; 48 | y $3; 49 | } else if (k == 8) { 50 | x $4; 51 | y $4; 52 | } else { 53 | x $5; 54 | y $5; 55 | } 56 | } else if (i == 4) { 57 | x $4; 58 | y $4; 59 | } else { 60 | x $5; 61 | y $5; 62 | } 63 | -------------------------------------------------------------------------------- /tests/src/test-nested-for-loop-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 15; 4 | int j = 25; 5 | int k = 35; 6 | 7 | float f1 = pi; 8 | float f2 = pi; 9 | float f3 = pi; 10 | 11 | for x in [0 : 100] { 12 | f1 += i; 13 | i += x; 14 | 15 | for y in [0 : 100] { 16 | f2 += j; 17 | j += y; 18 | 19 | for z in [0 : 100] { 20 | f3 += k; 21 | k += z; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test-nested-if.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $2; 4 | qubit $3; 5 | 6 | bit is_excited; 7 | bit other; 8 | bit result; 9 | 10 | gate x q { 11 | U(pi, 0, pi) q; 12 | } 13 | 14 | x $2; 15 | x $3; 16 | 17 | is_excited = measure $2; 18 | 19 | if (is_excited == 1) { 20 | other = measure $3; 21 | if (other == 1){ 22 | x $2; 23 | } 24 | } 25 | 26 | result = measure $2; 27 | -------------------------------------------------------------------------------- /tests/src/test-nested-loop.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int[32] a = 0; 4 | 5 | for ii in [-12:2:0] { 6 | for jj in [0:11] { 7 | a += 1; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-nested-redeclarations.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 1; 4 | 5 | int j = 10; 6 | 7 | int k = 20; 8 | 9 | if (j > i) { 10 | int i = 5; 11 | int k = 25; 12 | 13 | if (k > i) { 14 | int i = 10; 15 | int k = 35; 16 | 17 | if (k > i) { 18 | int i = 15; 19 | int k = 45; 20 | } else { 21 | int i = -15; 22 | int k = -45; 23 | } 24 | } else { 25 | int i = -10; 26 | int k = -35; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/src/test-nested-while-loop-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 15; 4 | int j = 25; 5 | int k = 35; 6 | 7 | float f1 = pi; 8 | float f2 = pi; 9 | float f3 = pi; 10 | 11 | while (i != 0) { 12 | f1 += i; 13 | --i; 14 | 15 | while (j != 0) { 16 | f2 += j; 17 | --j; 18 | 19 | while (k != 0) { 20 | f3 += k; 21 | --k; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test-no-openqasm-line-1.qasm: -------------------------------------------------------------------------------- 1 | int i = 3; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | gate foo q { } 7 | 8 | switch (i) { 9 | case 0: 10 | foo $0; 11 | break; 12 | case 1: 13 | foo $1; 14 | break; 15 | default: 16 | break; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/test-no-openqasm-line-2.qasm: -------------------------------------------------------------------------------- 1 | uint j = 64; 2 | 3 | cal { 4 | waveform waveform0 = [1 + j im, j + 3 im, 1 / sqrt(2) + 1 / sqrt(2) * j im]; 5 | 6 | complex[float[128]] a = 5.25 * 1 im; 7 | 8 | complex[float[128]] b = 15.25 * 1 im; 9 | 10 | complex[float[128]] c = 25.25 * 1 im; 11 | 12 | waveform waveform1 = [a, b, c]; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test-no-openqasm-line-3.qasm: -------------------------------------------------------------------------------- 1 | /* This is a C comment. */ 2 | 3 | // This is a C++ comment. 4 | 5 | /* 6 | * This is a multi-line C comment. 7 | * This is the second line. 8 | * This is the third line. 9 | */ 10 | 11 | uint j = 64; 12 | 13 | cal { 14 | waveform wf0 = [1 + j im, j + 3 im, 1 / sqrt(2) + 1 / sqrt(2) * j im]; 15 | 16 | complex[float[128]] a = 5.25 * 1 im; 17 | 18 | complex[float[128]] b = 15.25 * 1 im; 19 | 20 | complex[float[128]] c = 25.25 * 1 im; 21 | 22 | waveform wf1 = [a, b, c]; 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/test-not-logical.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint k = 3; 4 | 5 | int j = 0; 6 | 7 | if (!k) { 8 | j = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-not.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int j = 0; 4 | 5 | int k = 4; 6 | 7 | if (!j) { 8 | k = 5; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-opaque.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | opaque Opq1 j, k; 6 | 7 | opaque Opq2(theta) j, k; 8 | -------------------------------------------------------------------------------- /tests/src/test-operators-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 3; 4 | 5 | int j = --i; 6 | -------------------------------------------------------------------------------- /tests/src/test-output.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | output angle[32] a; 4 | 5 | output bit[32] b; 6 | -------------------------------------------------------------------------------- /tests/src/test-parity.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 32; 4 | 5 | def parity(bit[n] cin) -> bit { 6 | bit c; 7 | for i in [0:2:100] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | -------------------------------------------------------------------------------- /tests/src/test-phase.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // phase gate (Z-rotation by lambda) 4 | gate phase(lambda) q { 5 | U(0, 0, lambda) q; 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test-pi.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[32] my_pi = π; 4 | 5 | float[32] your_pi = pi; 6 | -------------------------------------------------------------------------------- /tests/src/test-play-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | float[128] j = 1234567890.0987654321; 7 | 8 | cal { 9 | extern port p0; 10 | waveform test_waveform = [1 + j im, 1 * j im, 1 / sqrt(2) + 1 / sqrt(2) * j im]; 11 | frame test_frame = newframe(p0, 5e9, 0.0); 12 | } 13 | 14 | extern gaussian(complex[float[128]] a, duration d, duration s) -> waveform; 15 | 16 | defcal xy(theta) $0 { 17 | play(test_waveform, test_frame); 18 | } 19 | 20 | complex[float[128]] ampl; 21 | 22 | duration dur = 150ns; 23 | 24 | duration sigma = 300ns; 25 | 26 | defcal xz(phi) $1 { 27 | frame f1 = newframe(p0, 15e10, 1.0); 28 | play(gaussian(ampl, dur, sigma), f1); 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/test-play-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | float[128] j = 1234567890.0987654321; 7 | 8 | cal { 9 | extern port p0; 10 | waveform test_waveform = [1 + j im, 1 * j im, 1 / sqrt(2) + 1 / sqrt(2) * j im]; 11 | frame test_frame = newframe(p0, 5e9, 0.0); 12 | } 13 | 14 | extern gaussian(complex[float[128]] a, duration d, duration s) -> waveform; 15 | 16 | defcal xy(theta) $0 { 17 | play(test_waveform, test_frame); 18 | } 19 | 20 | complex[float[128]] ampl; 21 | 22 | duration dur = 150ns; 23 | 24 | duration sigma = 300ns; 25 | 26 | defcal xz(phi) $1 { 27 | frame f1 = newframe(p0, 15e10, 1.0); 28 | play(gaussian(ampl, dur, sigma), f1); 29 | } 30 | 31 | bit[2] c; 32 | 33 | measure $0 -> c[0]; 34 | measure $1 -> c[1]; 35 | -------------------------------------------------------------------------------- /tests/src/test-popcount-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint u = 15; 4 | 5 | int i = 31; 6 | 7 | uint[128] mpu = "1234567890987654321"; 8 | 9 | int[128] mpi = "9876543210123456789"; 10 | 11 | bit[32] b = "01010101010101010101010101010101"; 12 | 13 | uint p = popcount(u); 14 | 15 | p = popcount(i); 16 | 17 | p = popcount(mpu); 18 | 19 | p = popcount(mpi); 20 | 21 | p = popcount(b); 22 | -------------------------------------------------------------------------------- /tests/src/test-popcount.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint u = 15; 4 | 5 | int i = 31; 6 | 7 | uint[128] mpu = "1234567890987654321"; 8 | 9 | int[128] mpi = "9876543210123456789"; 10 | 11 | bit[32] b = "01010101010101010101010101010101"; 12 | 13 | popcount(u); 14 | 15 | popcount(i); 16 | 17 | popcount(mpu); 18 | 19 | popcount(mpi); 20 | 21 | popcount(b); 22 | -------------------------------------------------------------------------------- /tests/src/test-port-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | cal { 4 | array[port, 16] xpa; 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/test-pow-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 3 ** 5; 4 | 5 | float[32] f0 = 6.0; 6 | 7 | float[32] f1 = 3.0; 8 | 9 | float[64] f2 = f0 ** f1; 10 | -------------------------------------------------------------------------------- /tests/src/test-pow-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[32]] cf0 = 7.95 * 1 im; 4 | 5 | complex[float[32]] cf1 = 2.95 + 1 im; 6 | 7 | float[32] f0 = 6.0; 8 | 9 | float[32] f1 = 3.0; 10 | 11 | float[64] f2 = f0 ** f1; 12 | 13 | complex[float[64]] rf = cf0 ** cf1; 14 | -------------------------------------------------------------------------------- /tests/src/test-pow-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 3; 4 | 5 | uint u = 7U; 6 | 7 | int[128] xi = 310510710; 8 | 9 | uint[128] xu = 310510710U; 10 | 11 | float f0 = 12345.54321; 12 | 13 | float f1 = 54321.12345; 14 | 15 | float[128] xf0 = 1234512345.5432154321; 16 | 17 | float[128] xf1 = 5432154321.1234512345; 18 | 19 | float[128] x0 = pow(i, 2); 20 | 21 | float[128] x1 = pow(u, 8); 22 | 23 | float[128] x2 = pow(xi, i); 24 | 25 | float[128] x3 = pow(xu, u); 26 | 27 | float[128] x4 = pow(xu, u); 28 | 29 | float[128] x5 = pow(f0, i); 30 | 31 | float[128] x6 = pow(f1, u); 32 | 33 | float[128] x7 = pow(xf0, f0); 34 | 35 | float[128] x8 = pow(xf1, f1); 36 | 37 | float[128] x9 = pow(xf0, xi); 38 | 39 | float[128] x10 = pow(xf1, xu); 40 | 41 | float[128] x11 = pow(xf0, cos(f0)); 42 | 43 | float[128] x12 = pow(xf0, sin(xf1)); 44 | 45 | float[128] x13 = pow(xf0 * 2, xf1 / 2); 46 | 47 | float[128] x14 = pow(xi, xf1); 48 | 49 | float[128] x15 = pow(xf0, xu); 50 | -------------------------------------------------------------------------------- /tests/src/test-pow-int.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 3; 4 | 5 | float[128] f = pow(i, 2); 6 | -------------------------------------------------------------------------------- /tests/src/test-pragma-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | pragma align 16 4 | 5 | pragma foo 12345.67890 6 | 7 | pragma inline "always" 8 | 9 | pragma inline sometimes 10 | -------------------------------------------------------------------------------- /tests/src/test-pragma-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | pragma simulator noise model "qpu1.noise" 4 | 5 | pragma user alice account 12345678 6 | 7 | pragma max_temp qpu 0.4 8 | -------------------------------------------------------------------------------- /tests/src/test-pragma-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | pragma foo bar \ 4 | newline baz \ 5 | second newline 6 | -------------------------------------------------------------------------------- /tests/src/test-qreg-v2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | qreg qubits[16]; 4 | -------------------------------------------------------------------------------- /tests/src/test-qreg-v3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qreg qubits[16]; 4 | -------------------------------------------------------------------------------- /tests/src/test-qregs.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | 3 | gate xz q { U(pi, 0.0, pi) q; } 4 | 5 | gate cx c, t { CX c, t; } 6 | 7 | qreg qubits[8]; 8 | 9 | xz qubits[0]; 10 | 11 | cx qubits[0], qubits[1]; 12 | -------------------------------------------------------------------------------- /tests/src/test-qubit-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[20] q = 3 * 5; 4 | -------------------------------------------------------------------------------- /tests/src/test-qubit-array-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | array[qubit, 16] xqa; 4 | 5 | array[qubit[32], 16] xqb; 6 | -------------------------------------------------------------------------------- /tests/src/test-qubit-concat.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[16] q; 4 | 5 | let j = q[4] || q[8]; 6 | 7 | let k = q[7] ++ q[13]; 8 | 9 | let n = q[3] || q[6] || q[9] || q[12]; 10 | 11 | let t = q[3] ++ q[5] ++ q[7] ++ q[11]; 12 | -------------------------------------------------------------------------------- /tests/src/test-qubit.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit[8] q; 4 | 5 | qubit $0; 6 | qubit $1; 7 | 8 | qubit $q1; 9 | qubit $q2; 10 | qubit $q3; 11 | 12 | // Simple Qubit identifiers. 13 | // 0. $[a-zA-Z_][0-9]+ 14 | measure $0 -> q[0]; 15 | measure $1 -> q[1]; 16 | 17 | // More complex Qubit identifiers. 18 | // 1. $[a-zA-Z_][0-9]+ 19 | measure $q1 -> q[2]; 20 | 21 | // 2. $[a-zA-Z_][0-9]+ 22 | measure $q2 -> q[3]; 23 | 24 | // 3. $[0-9]+ 25 | measure $q3 -> q[4]; 26 | 27 | // 4. cb[N] = measure qubit[N]. 28 | qubit[8] qb; 29 | bit[8] cb; 30 | 31 | cb = measure qb; 32 | 33 | // 5. measure qubit[N] -> cb[N]. 34 | qubit[4] qbc; 35 | bit[4] cbc; 36 | 37 | measure qbc[0] -> cbc[0]; 38 | measure qbc[2] -> cbc[2]; 39 | measure qbc[3] -> cbc[1]; 40 | -------------------------------------------------------------------------------- /tests/src/test-reset-defcal.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | qubit $1; 5 | 6 | gate foo(theta, phi) q, r { 7 | U(0.0, theta, phi) q; 8 | U(0.0, theta, phi) r; 9 | } 10 | 11 | defcal foo(theta, phi) $0, $1 { 12 | U(0.0, theta, phi) $0; 13 | U(0.0, theta, phi) $1; 14 | 15 | measure $0; 16 | measure $1; 17 | 18 | reset $0; 19 | reset $1; 20 | } 21 | -------------------------------------------------------------------------------- /tests/src/test-reset-gate.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate foo(theta, phi) q, r { 4 | U(0.0, theta, phi) q; 5 | U(0.0, theta, phi) r; 6 | reset q; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/test-reset.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit one; 4 | 5 | qubit[10] ten; 6 | 7 | reset one; 8 | 9 | reset ten; 10 | -------------------------------------------------------------------------------- /tests/src/test-return-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int a = 5; 4 | 5 | int b = 7; 6 | 7 | return a + b; 8 | -------------------------------------------------------------------------------- /tests/src/test-return-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit a; 4 | 5 | return measure a; 6 | -------------------------------------------------------------------------------- /tests/src/test-return-xor.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint i = 8; 4 | 5 | uint j = 32; 6 | 7 | return i ^= j; 8 | -------------------------------------------------------------------------------- /tests/src/test-return.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int b = 12; 4 | 5 | uint c = 3; 6 | 7 | return c; 8 | 9 | uint[128] d = 1; 10 | 11 | return d ^= c; 12 | 13 | int a = 16; 14 | 15 | qubit $0; 16 | 17 | return measure $0; 18 | 19 | return a + b; 20 | 21 | return -(a + b); 22 | 23 | return -a + b; 24 | 25 | return c += b; 26 | 27 | return d++; 28 | 29 | return --a; 30 | 31 | return d << 1; 32 | -------------------------------------------------------------------------------- /tests/src/test-rotl.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint i = 128U; 4 | 5 | rotl(i, 8); 6 | 7 | int s = 8; 8 | 9 | rotl(i, s); 10 | 11 | uint[128] mpi = 128U; 12 | 13 | rotl(mpi, 8); 14 | 15 | rotl(mpi, s); 16 | 17 | bit[32] b = "01010101010101010101010101010101"; 18 | 19 | rotl(b, 8); 20 | 21 | int r = rotl(i, s); 22 | 23 | uint u = rotl(mpi, 8); 24 | 25 | r = rotl(mpi, s); 26 | 27 | r = rotl(b, 8); 28 | -------------------------------------------------------------------------------- /tests/src/test-rotr.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint i = 128U; 4 | 5 | rotr(i, 8); 6 | 7 | int s = 8; 8 | 9 | rotr(i, s); 10 | 11 | uint[128] mpi = 128U; 12 | 13 | rotr(mpi, 8); 14 | 15 | rotr(mpi, s); 16 | 17 | bit[32] b = "10101010101010101010101010101010"; 18 | 19 | rotr(b, 8); 20 | 21 | int r = rotr(i, s); 22 | 23 | uint u = rotr(mpi, 8); 24 | 25 | r = rotr(mpi, s); 26 | 27 | r = rotr(b, 8); 28 | -------------------------------------------------------------------------------- /tests/src/test-run-defcal-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | defcalgrammar "openpulse"; 4 | 5 | extern gaussian(complex[float[128]] a, duration d, duration s) -> waveform; 6 | 7 | float gfreq = 5.9e9; 8 | 9 | cal { 10 | // Defined within `cal`, so it may not leak back out to the enclosing blocks scope 11 | float nfreq = 5.2e9; 12 | 13 | // declare global port 14 | extern port d0; 15 | 16 | // reference `freq` variable from enclosing blocks scope 17 | frame d0f = newframe(d0, nfreq, 0.0); 18 | } 19 | 20 | defcal x $0 { 21 | waveform xp = gaussian(1.0, 160dt, 40dt); 22 | 23 | // References frame and `nfreq` declared in top-level cal block 24 | play(xp, d0f); 25 | 26 | d0f.frequency = nfreq; 27 | play(xp, d0f); 28 | } 29 | 30 | qubit $1; 31 | qubit $2; 32 | 33 | x $1; 34 | x $2; 35 | -------------------------------------------------------------------------------- /tests/src/test-run-defcal-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | defcalgrammar "openpulse"; 4 | 5 | extern gaussian(complex[float[128]] a, duration d, duration s) -> waveform; 6 | 7 | float gfreq = 5.9e9; 8 | 9 | cal { 10 | // Defined within `cal`, so it may not leak back out to the enclosing blocks scope 11 | float nfreq = 5.2e9; 12 | 13 | // declare global port 14 | extern port d0; 15 | 16 | // reference `freq` variable from enclosing blocks scope 17 | frame d0f = newframe(d0, nfreq, 0.0); 18 | } 19 | 20 | defcal rx(π / 2) $0 { 21 | waveform xp = gaussian(1.0, 160dt, 40dt); 22 | 23 | // References frame and `nfreq` declared in top-level cal block 24 | play(xp, d0f); 25 | 26 | d0f.frequency = nfreq; 27 | play(xp, d0f); 28 | } 29 | 30 | qubit $1; 31 | qubit $2; 32 | 33 | rx $1; 34 | rx $2; 35 | -------------------------------------------------------------------------------- /tests/src/test-russian-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint number = 15; 8 | uint количество = 15; 9 | 10 | // int odin (one) = 1; 11 | int один = 1; 12 | 13 | // int dva (two) = 2; 14 | int два = 2; 15 | 16 | // int три (three) = 3; 17 | int три = 3; 18 | 19 | // int chetyre (four) = 4; 20 | int четыре = 4; 21 | 22 | // int pyat (five) = 5; 23 | int пять = 5; 24 | 25 | // gate rachmaninov(lambda, theta, phi) unit { 26 | // U(phi, theta, lambda) unit; 27 | // } 28 | gate рахманинов(λ, φ, θ) единица { 29 | U(θ, φ, λ) единица; 30 | } 31 | 32 | // gate shostakovich(lambda, theta, phi) unit { 33 | // U(phi, theta, lambda) unit; 34 | // } 35 | gate шостакович(λ, φ, θ) единица { 36 | U(θ, φ, λ) единица; 37 | } 38 | -------------------------------------------------------------------------------- /tests/src/test-rz-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | gate rz(theta) q { } 6 | 7 | rz(1.5707963267949) $0; 8 | 9 | rz(7.03508951031555) $0; 10 | -------------------------------------------------------------------------------- /tests/src/test-rz-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | gate rz(theta) q { } 6 | 7 | float[128] f1 = 1.5707963267949; 8 | 9 | float[128] f2 = 7.03508951031555; 10 | 11 | rz(f1) $0; 12 | 13 | rz(f2) $0; 14 | -------------------------------------------------------------------------------- /tests/src/test-sci-gate.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x a { U(π, 0, π) a; } 4 | 5 | gate y a { U(π, 0.0, π) a; } 6 | -------------------------------------------------------------------------------- /tests/src/test-scope-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 3; 4 | 5 | if (i == 3) { 6 | int j = 4; 7 | } 8 | 9 | int[j] k; 10 | -------------------------------------------------------------------------------- /tests/src/test-scope-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 100; 4 | 5 | def parity(bit[n] cin) -> bit { 6 | bit c; 7 | for i in [0:2:100] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | 14 | n = 10; 15 | -------------------------------------------------------------------------------- /tests/src/test-sequence-elseif.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x q { } 4 | 5 | gate y q { } 6 | 7 | qubit $0; 8 | qubit $1; 9 | qubit $2; 10 | qubit $3; 11 | qubit $4; 12 | qubit $5; 13 | 14 | int i = 17; 15 | 16 | if (i == 0) { 17 | x $0; 18 | y $0; 19 | } else if (i == 1) { 20 | x $1; 21 | y $1; 22 | } else if (i == 2) { 23 | x $2; 24 | y $2; 25 | } else if (i == 3) { 26 | x $3; 27 | y $3; 28 | } else if (i == 4) { 29 | x $4; 30 | y $4; 31 | } else { 32 | x $5; 33 | y $5; 34 | } 35 | -------------------------------------------------------------------------------- /tests/src/test-shadow.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate x(theta, phi) q, t { 4 | U(theta, 0.0, phi) q; 5 | U(theta, 0.0, phi) t; 6 | } 7 | 8 | def xfunction(int x) -> int { 9 | return x + 5; 10 | } 11 | 12 | def yfunction(int y) -> int { 13 | int x = 3; 14 | return y + x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/src/test-shift-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // 1. Angle declaration + assignment. 4 | angle[3] c = 0; 5 | 6 | // 2. Left-shift assign. 7 | c <<= 1; 8 | 9 | // 3. uint declaration + assignment. 10 | uint zx = 3; 11 | 12 | // 4. Left-shift assign. 13 | uint jx = zx <<= 1; 14 | 15 | // 5. Simple integer assignment. 16 | zx = 7; 17 | 18 | // 6. Simple floating-point declaration + assignment. 19 | float fx = -3.14159; 20 | -------------------------------------------------------------------------------- /tests/src/test-shift-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle[3] c = 0; 4 | 5 | // 1. Right-shift assign. 6 | c >>= 1; 7 | 8 | uint zx = 3; 9 | 10 | // 2. Right-shift assign uint. 11 | uint zy = zx >>= 1; 12 | -------------------------------------------------------------------------------- /tests/src/test-shift-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint q = 14; 4 | 5 | uint r = q << 1; 6 | uint s = q + r; 7 | 8 | r = s >> 1; 9 | s = q & r; 10 | -------------------------------------------------------------------------------- /tests/src/test-sign-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int[32] x = 55; 4 | -------------------------------------------------------------------------------- /tests/src/test-sign-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint[32] x = 55; 4 | -------------------------------------------------------------------------------- /tests/src/test-sin.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int za = -123; 4 | 5 | uint zb = 301; 6 | 7 | za &= sin(zb); 8 | -------------------------------------------------------------------------------- /tests/src/test-stretch.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | stretch s; 4 | 5 | stretch[128] t; 6 | 7 | stretch c; 8 | stretch d; 9 | stretch e; 10 | 11 | stretch[100] m; 12 | 13 | stretch[0] n; 14 | stretch[1] r; 15 | 16 | stretch[254] o; 17 | stretch[255] p; 18 | stretch[252] q; 19 | 20 | stretch x = 3.1415692 * 17 / 2.5; 21 | 22 | stretch y = cos(1.0) + sin(1.0); 23 | -------------------------------------------------------------------------------- /tests/src/test-sub.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint c = 4; 4 | c -= 3; 5 | -------------------------------------------------------------------------------- /tests/src/test-subscript-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 16; 4 | 5 | bit[32] c = 1; 6 | 7 | bit d = c[0]; 8 | 9 | bit e = c[n]; 10 | -------------------------------------------------------------------------------- /tests/src/test-swedish-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // uint count = 15; 8 | uint räkna = 15; 9 | 10 | // int one = 1; 11 | int ett = 1; 12 | 13 | // int two = 2; 14 | int två = 2; 15 | 16 | // int three = 3; 17 | int tre = 3; 18 | 19 | // int four = 4; 20 | int fyra = 4; 21 | 22 | // int five = 5; 23 | int fem = 5; 24 | 25 | // gate resilient(lambda, theta, phi) bear { 26 | // U(phi, theta, lambda) bear; 27 | // } 28 | gate uthållig(λ, φ, θ) björn { 29 | U(θ, φ, λ) björn; 30 | } 31 | 32 | // gate ferocious(lambda, theta, phi) fox { 33 | // U(phi, theta, lambda) fox; 34 | // } 35 | gate våldsam(λ, φ, θ) räv { 36 | U(θ, φ, λ) räv; 37 | } 38 | -------------------------------------------------------------------------------- /tests/src/test-switch-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 15; 4 | 5 | switch (i) { 6 | case 1: { 7 | } 8 | break; 9 | case 2: { 10 | } 11 | break; 12 | case 3: { 13 | } 14 | break; 15 | case 5: { 16 | } 17 | break; 18 | case 12: { 19 | } 20 | break; 21 | default: { 22 | } 23 | break; 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test-switch-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | 4 | def foo(int i, qubit[8] d) -> bit { 5 | return measure d[i]; 6 | } 7 | 8 | int i = 15; 9 | 10 | int j = 1; 11 | int k = 2; 12 | 13 | bit c1; 14 | 15 | qubit[8] $0; 16 | qubit $1; 17 | 18 | switch (i) { 19 | case 1: { 20 | j = k + foo(k, $0); 21 | } 22 | break; 23 | case 2: { 24 | float[64] d = j / k; 25 | } 26 | break; 27 | case 3: { 28 | } 29 | break; 30 | default: { 31 | } 32 | break; 33 | } 34 | -------------------------------------------------------------------------------- /tests/src/test-switch-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | 4 | def foo(int i, qubit[8] d) -> bit { 5 | return measure d[i]; 6 | } 7 | 8 | int i = 15; 9 | 10 | int j = 1; 11 | int k = 2; 12 | 13 | float[64] d = 0.0; 14 | 15 | bit c1; 16 | 17 | qubit[8] $0; 18 | qubit $1; 19 | 20 | switch (i) { 21 | case 1: { 22 | j = k + foo(k, $0); 23 | } 24 | break; 25 | case 2: 26 | d = j / k; 27 | break; 28 | case 3: 29 | case 5: 30 | c1 = foo(k, $0); 31 | break; 32 | default: 33 | break; 34 | } 35 | -------------------------------------------------------------------------------- /tests/src/test-switch-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int i = 15; 4 | 5 | int j = 30; 6 | 7 | switch (i) { 8 | case 1: { 9 | } 10 | break; 11 | case 2: { 12 | } 13 | break; 14 | case 3: { 15 | switch (j) { 16 | case 10: { 17 | } 18 | break; 19 | case 15: { 20 | } 21 | break; 22 | case 20: { 23 | } 24 | break; 25 | default: { 26 | } 27 | break; 28 | } 29 | } 30 | break; 31 | case 5: { 32 | } 33 | break; 34 | case 12: { 35 | } 36 | break; 37 | default: { 38 | } 39 | break; 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/test-tau.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float[32] my_tau = τ; 4 | 5 | float[32] your_tau = tau; 6 | -------------------------------------------------------------------------------- /tests/src/test-u-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | U(1.0, 2.0, 1.5) $0; 6 | 7 | U(1.0, 1.25, 1.50) $0; 8 | 9 | U(1.25, 1.50, 1.75) $0; 10 | -------------------------------------------------------------------------------- /tests/src/test-ugate-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | U(3.14, 0, 3.14) $0; 6 | 7 | gate h q { 8 | U(1.57079632679, 0.0, 3.14159265359) q; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-ugate-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | gate h q { 6 | U(1.57079632679, 0.0, 3.14159265359) q; 7 | } 8 | 9 | U(3.14, 0, 3.14) $0; 10 | -------------------------------------------------------------------------------- /tests/src/test-ugate-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit $0; 4 | 5 | gate test(lambda) q, r, s { 6 | U(lambda, 0.0, 3.14159265359) q; 7 | U(lambda, 0.0, 3.14159265359) r; 8 | U(lambda, 0.0, 3.14159265359) s; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-uint.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int[32] test_int = 1; 4 | 5 | uint[32] test_uint = 1; 6 | -------------------------------------------------------------------------------- /tests/src/test-umlaut-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // int ü = 10; 8 | int ü = 10; 9 | 10 | // int bü = 10; 11 | int bü = 15; 12 | 13 | // int büa = 10; 14 | int büa = 15; 15 | 16 | // int ä = 20; 17 | int ä = 20; 18 | 19 | // int å = 30; 20 | int å = 30; 21 | -------------------------------------------------------------------------------- /tests/src/test-unary-ops.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | float fa = 3.14; 4 | float fb = -5.16; 5 | float fc = 47.33; 6 | 7 | // 1. sin. 8 | float fx = sin(fa); 9 | 10 | // 2. cos. 11 | float fy = cos(fx); 12 | 13 | // 3. tan. 14 | float fz = tan(sin(fy)); 15 | 16 | // 4. asin. 17 | float fx = asin(fa); 18 | 19 | // 5. acos. 20 | float fy = acos(fx); 21 | 22 | // 6. atan. 23 | float fz = atan(asin(fy)); 24 | -------------------------------------------------------------------------------- /tests/src/test-unary-pi.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | angle foo = -pi * 2; 4 | -------------------------------------------------------------------------------- /tests/src/test-underscore-1-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // int _ü = 10; 8 | int _ü = 10; 9 | 10 | // int ü_ = 10; 11 | int ü_ = 10; 12 | 13 | // int _ü_ = 10; 14 | int _ü_ = 10; 15 | 16 | // int _bü = 10; 17 | int _bü = 15; 18 | 19 | // int bü_ = 10; 20 | int bü_ = 15; 21 | 22 | // int _bü_ = 10; 23 | int _bü_ = 15; 24 | 25 | // int _büa = 10; 26 | int _büa = 15; 27 | 28 | // int büa_ = 10; 29 | int büa_ = 15; 30 | 31 | // int _büa_ = 10; 32 | int _büa_ = 15; 33 | -------------------------------------------------------------------------------- /tests/src/test-underscore-2-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // int __ü = 10; 8 | int __ü = 10; 9 | 10 | // int ü__ = 10; 11 | int ü__ = 10; 12 | 13 | // int __ü__ = 10; 14 | int __ü__ = 10; 15 | 16 | // int __bü = 10; 17 | int __bü = 15; 18 | 19 | // int bü__ = 10; 20 | int bü__ = 15; 21 | 22 | // int __bü__ = 10; 23 | int __bü__ = 15; 24 | 25 | // int __büa = 10; 26 | int __büa = 15; 27 | 28 | // int büa__ = 10; 29 | int büa__ = 15; 30 | 31 | // int __büa__ = 10; 32 | int __büa__ = 15; 33 | -------------------------------------------------------------------------------- /tests/src/test-underscore-3-utf8.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | // This is a test of UTF8 character encoding in 4 | // OpenQASM3 programs. It has no programmatic 5 | // meaning. 6 | 7 | // int ___ü = 10; 8 | int ___ü = 10; 9 | 10 | // int ü___ = 10; 11 | int ü___ = 10; 12 | 13 | // int ___ü___ = 10; 14 | int ___ü___ = 10; 15 | 16 | // int ___bü = 10; 17 | int ___b_ü = 10; 18 | 19 | // int b_ü___ = 10; 20 | int b_ü___ = 10; 21 | 22 | // int ___b_ü___ = 10; 23 | int ___b_ü___ = 10; 24 | 25 | // int ___b_ü_a = 10; 26 | int ___b_ü_a = 10; 27 | 28 | // int b_ü_a___ = 10; 29 | int b_ü_a___ = 10; 30 | 31 | // int ___b_ü_a___ = 10; 32 | int ___b_ü_a___ = 10; 33 | 34 | // int ___b__ü__a___ = 10; 35 | int ___b__ü__a___ = 10; 36 | 37 | // int ____b___ü___a____ = 10; 38 | int ___b___ü___a___ = 10; 39 | -------------------------------------------------------------------------------- /tests/src/test-unicode-epislon-gate.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | // RUN: qss-compiler -X=qasm --emit=ast %s 3 | // 4 | // This test case validates OpenQASM 3's builtin constants pi, tau, and euler. 5 | 6 | qubit $0; 7 | 8 | U(pi, pi / 2, euler) $0; 9 | 10 | angle[3] a = euler; 11 | 12 | U(π, τ, ε) $0; 13 | 14 | U(1.5 * π, τ / 2, 1.5 * ε) $0; 15 | 16 | 17 | // gate declarations 18 | gate phase(lambda) q { 19 | U(0, 0, lambda) q; 20 | } 21 | 22 | phase(1.8125 * pi) $0; 23 | phase(1.8125 * π) $0; 24 | 25 | phase(0.4 * tau) $0; 26 | phase(0.4 * τ) $0; 27 | 28 | phase(1.5 * euler) $0; 29 | phase(1.5 * ε) $0; 30 | 31 | angle phi = 1.5 * π + τ / 2 - 1.5 * ε; 32 | -------------------------------------------------------------------------------- /tests/src/test-unicode.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | bit Γ; 4 | 5 | bit Φ; 6 | 7 | int δ = 3; 8 | 9 | uint ζ = 4U; 10 | 11 | angle[32] Σ = 3.141592; 12 | 13 | angle[32] ω = 151.3; 14 | 15 | gate unicode(λ, θ) β { 16 | U(π, λ, θ) β; 17 | } 18 | 19 | gate Z q { 20 | U(π, π / 2, π / 4) q; 21 | } 22 | 23 | gate noangles β, υ { 24 | Z β; 25 | Z υ; 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test-void-measure.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | qubit[10] q; 4 | 5 | measure q; 6 | -------------------------------------------------------------------------------- /tests/src/test-waveform-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 64; 4 | 5 | cal { 6 | waveform waveform0 = [1 + j im, j + 3 im, 1 / sqrt(2) + 1 / sqrt(2) * j im]; 7 | 8 | complex[float[128]] a = 5.25 * 1 im; 9 | 10 | complex[float[128]] b = 15.25 * 1 im; 11 | 12 | complex[float[128]] c = 25.25 * 1 im; 13 | 14 | waveform waveform1 = [a, b, c]; 15 | } 16 | -------------------------------------------------------------------------------- /tests/src/test-waveform-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[128]] cxa = 5.25 * 1 im; 4 | 5 | complex[float[128]] cxb = 15.25 * 1 im; 6 | 7 | complex[float[128]] cxc = 25.25 * 1 im; 8 | 9 | cal { 10 | waveform waveform1 = [cxa, cxb, cxc]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-waveform-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | extern gaussian_square(complex[float[128]] amp, duration d, duration sqw, 4 | duration sigma) -> waveform; 5 | 6 | cal { 7 | waveform wf = gaussian_square(1.0, 16000ms, 262ns, 13952μs); 8 | } 9 | -------------------------------------------------------------------------------- /tests/src/test-waveform-4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint j = 64; 4 | 5 | cal { 6 | waveform waveform0 = { 1 + j im, j + 3 im, 1 / sqrt(2) + 1 / sqrt(2) * j im }; 7 | 8 | complex[float[128]] a = 5.25 * 1 im; 9 | 10 | complex[float[128]] b = 15.25 * 1 im; 11 | 12 | complex[float[128]] c = 25.25 * 1 im; 13 | 14 | waveform waveform1 = { a, b, c }; 15 | } 16 | -------------------------------------------------------------------------------- /tests/src/test-waveform-5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | complex[float[128]] cxa = 5.25 * 1 im; 4 | 5 | complex[float[128]] cxb = 15.25 * 1 im; 6 | 7 | complex[float[128]] cxc = 25.25 * 1 im; 8 | 9 | cal { 10 | waveform waveform1 = { cxa, cxb, cxc }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-while-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | uint n = 125; 17 | 18 | // While loop. 19 | while (n >= 0) { 20 | reset q; 21 | h q; 22 | cphase(power*3*pi/8) q, r; 23 | phase(-c) q; 24 | h q; 25 | measure q -> c[0]; 26 | c <<= 1; 27 | power <<= 1; 28 | --n; 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/test-while-2.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "stdgates.inc"; 4 | 5 | qubit q; 6 | qubit r; 7 | 8 | angle[3] c = 0; 9 | 10 | reset q; 11 | reset r; 12 | h r; 13 | 14 | uint[3] power = 1; 15 | 16 | uint n = 125; 17 | 18 | // While loop. 19 | while (n >= 0) { 20 | reset q; 21 | h q; 22 | cphase(power*3*pi/8) q, r; 23 | phase(-c) q; 24 | h q; 25 | measure q -> c[0]; 26 | c <<= 1; 27 | 28 | if (c == 32) { 29 | break; 30 | } else { 31 | continue; 32 | } 33 | 34 | power <<= 1; 35 | --n; 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/test-while-3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | int bs = 0; 4 | 5 | int i = 10; 6 | 7 | while (i > 3) { 8 | bs |= i--; 9 | } 10 | -------------------------------------------------------------------------------- /tests/src/test-xcheck.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | gate cx a, b { } 4 | 5 | def xcheck(qubit[4] d, qubit a) -> bit { 6 | reset a; 7 | for i in [0:3] 8 | cx d[i], a; 9 | 10 | return measure a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test-xor-1.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint[64] c; 4 | 5 | // 1. XOr assign. 6 | c ^= 1; 7 | 8 | uint zx = 3; 9 | 10 | // 2. Xor assign uint. 11 | uint zy = zx ^= 1; 12 | 13 | uint n = 3; 14 | 15 | uint q = zx + n; 16 | 17 | // 3. Xor assign identifier. 18 | c ^= zx; 19 | -------------------------------------------------------------------------------- /tests/src/test.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | include "test.inc"; 4 | 5 | gate foo a { 6 | phase(-pi / 2) a; 7 | } 8 | 9 | gate bar q { 10 | phase(pi / 2) q; 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/tf5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 3.0; 2 | 3 | uint n = 8; 4 | 5 | def parity(bit[n]:cin) -> bit { 6 | bit c; 7 | for i in [0:2:100] { 8 | c ^= cin[i]; 9 | } 10 | 11 | return c; 12 | } 13 | 14 | def both(bit[n]:cin, angle[22]:ain, float:fin) qubit[4]:d, qubit:a -> bit { 15 | bit c; 16 | for i in [0:2:100] { 17 | c ^= cin[i]; 18 | } 19 | 20 | return c; 21 | } 22 | -------------------------------------------------------------------------------- /tests/src/tof_10.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[19]; 5 | ccx qubits[0],qubits[1],qubits[10]; 6 | ccx qubits[2],qubits[10],qubits[11]; 7 | ccx qubits[3],qubits[11],qubits[12]; 8 | ccx qubits[4],qubits[12],qubits[13]; 9 | ccx qubits[5],qubits[13],qubits[14]; 10 | ccx qubits[6],qubits[14],qubits[15]; 11 | ccx qubits[7],qubits[15],qubits[16]; 12 | ccx qubits[8],qubits[16],qubits[17]; 13 | ccx qubits[9],qubits[17],qubits[18]; 14 | ccx qubits[8],qubits[16],qubits[17]; 15 | ccx qubits[7],qubits[15],qubits[16]; 16 | ccx qubits[6],qubits[14],qubits[15]; 17 | ccx qubits[5],qubits[13],qubits[14]; 18 | ccx qubits[4],qubits[12],qubits[13]; 19 | ccx qubits[3],qubits[11],qubits[12]; 20 | ccx qubits[2],qubits[10],qubits[11]; 21 | ccx qubits[0],qubits[1],qubits[10]; 22 | -------------------------------------------------------------------------------- /tests/src/tof_3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[5]; 5 | ccx qubits[0],qubits[1],qubits[4]; 6 | ccx qubits[2],qubits[4],qubits[3]; 7 | ccx qubits[0],qubits[1],qubits[4]; 8 | -------------------------------------------------------------------------------- /tests/src/tof_4.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[7]; 5 | ccx qubits[0],qubits[1],qubits[4]; 6 | ccx qubits[2],qubits[4],qubits[5]; 7 | ccx qubits[3],qubits[5],qubits[6]; 8 | ccx qubits[2],qubits[4],qubits[5]; 9 | ccx qubits[0],qubits[1],qubits[4]; 10 | -------------------------------------------------------------------------------- /tests/src/tof_5.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[9]; 5 | ccx qubits[0],qubits[1],qubits[5]; 6 | ccx qubits[2],qubits[5],qubits[6]; 7 | ccx qubits[3],qubits[6],qubits[7]; 8 | ccx qubits[4],qubits[7],qubits[8]; 9 | ccx qubits[3],qubits[6],qubits[7]; 10 | ccx qubits[2],qubits[5],qubits[6]; 11 | ccx qubits[0],qubits[1],qubits[5]; 12 | -------------------------------------------------------------------------------- /tests/src/vbe_adder_3.qasm: -------------------------------------------------------------------------------- 1 | OPENQASM 2.0; 2 | include "qelib1.inc"; 3 | 4 | qreg qubits[10]; 5 | ccx qubits[1],qubits[2],qubits[3]; 6 | cx qubits[1],qubits[2]; 7 | ccx qubits[0],qubits[2],qubits[3]; 8 | ccx qubits[4],qubits[5],qubits[6]; 9 | cx qubits[4],qubits[5]; 10 | ccx qubits[3],qubits[5],qubits[6]; 11 | ccx qubits[7],qubits[8],qubits[9]; 12 | cx qubits[7],qubits[8]; 13 | ccx qubits[6],qubits[8],qubits[9]; 14 | cx qubits[6],qubits[8]; 15 | ccx qubits[3],qubits[5],qubits[6]; 16 | cx qubits[4],qubits[5]; 17 | ccx qubits[4],qubits[5],qubits[6]; 18 | cx qubits[3],qubits[5]; 19 | cx qubits[4],qubits[5]; 20 | ccx qubits[0],qubits[2],qubits[3]; 21 | cx qubits[1],qubits[2]; 22 | ccx qubits[1],qubits[2],qubits[3]; 23 | cx qubits[0],qubits[2]; 24 | cx qubits[1],qubits[2]; 25 | -------------------------------------------------------------------------------- /tests/teleport-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export HERE="`pwd`" 4 | export RED='\033[0;31m' 5 | export GREEN='\033[0;32m' 6 | export NC='\033[0m' 7 | 8 | # Set the following two paths to the ${TOP_SRCDIR}/tests directory: 9 | export TESTDIR="${HERE}/../../qasm/tests/src" 10 | export TESTINC="${HERE}/../../qasm/tests/include" 11 | export TESTLOG="${HERE}/tests.run.out" 12 | cat /dev/null > ${TESTLOG} 13 | 14 | # Set this path to the QasmParser example program: 15 | export QASMPARSER="${HERE}/QasmParser" 16 | export TESTLIST="/tmp/qasm-tests.$$" 17 | ls -1 teleportation-*.qasm > ${TESTLIST} 18 | 19 | cd ${HERE} 20 | 21 | while read -r file 22 | do 23 | printf "Testing ${file} ... " 24 | echo "${file}.out" >> ${TESTLOG} 2>&1 25 | ${QASMPARSER} -I${TESTINC} ${TESTDIR}/${file} > "${file}.out" 2>&1 26 | 27 | if [ $? -ne 0 ] ; then 28 | printf "${RED}FAILED!${NC}\n" 29 | else 30 | printf "${GREEN}OK.${NC}\n" 31 | fi 32 | done < ${TESTLIST} 33 | 34 | rm -f ${TESTLIST} 35 | -------------------------------------------------------------------------------- /utils/sed-bison-output.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -ne 1 ] ; then 4 | echo "Usage: `basename $0` " 5 | exit 1 6 | fi 7 | 8 | export SED="/usr/bin/sed" 9 | export DIR="${1}" 10 | export REALLY="false" 11 | 12 | if [ ! -d ${DIR} ] ; then 13 | echo "Directory ${DIR} does not exist!" 14 | exit 1 15 | fi 16 | 17 | if [ -f ${DIR}/QasmParser.tab.cpp ] ; then 18 | if [ "${REALLY}" = "true" ] ; then 19 | ${SED} -i 's#yy_flex_debug = 0#yy_flex_debug = 1#g' ${DIR}/QasmParser.tab.cpp 20 | ${SED} -i 's#if {yydebug_}#if {true}#g' ${DIR}/QasmParser.tab.cpp 21 | else 22 | echo "Set \${REALLY} above to 'true' if you want Bison debugging." 23 | fi 24 | fi 25 | 26 | if [ -f ${DIR}/QasmParser.tab.h ] ; then 27 | if [ "${REALLY}" = "true" ] ; then 28 | ${SED} -i 's#int yydebug_#int yydebug_ = 3#g' ${DIR}/QasmParser.tab.h 29 | else 30 | echo "Set \${REALLY} above to 'true' if you want Bison debugging." 31 | fi 32 | fi 33 | -------------------------------------------------------------------------------- /utils/sed-flex-output.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -ne 1 ] ; then 4 | echo "Usage: `basename $0` " 5 | exit 1 6 | fi 7 | 8 | export SED="/usr/bin/sed" 9 | export DIR="${1}" 10 | export REALLY="false" 11 | 12 | if [ ! -d ${DIR} ] ; then 13 | echo "Directory ${DIR} does not exist!" 14 | exit 1 15 | fi 16 | 17 | if [ -f ${DIR}/QasmScanner.yy.cpp ] ; then 18 | if [ "${REALLY}" = "true" ] ; then 19 | ${SED} -i 's#yy_flex_debug = 0#yy_flex_debug = 1#g' ${DIR}/QasmScanner.yy.cpp 20 | else 21 | echo "Set \${REALLY} above to 'true' if you want Flex debugging." 22 | fi 23 | fi 24 | --------------------------------------------------------------------------------