@@ -641,111 +641,81 @@ static int test_to_qasm3(void) {
641641 return Ok;
642642}
643643
644- static int test_to_qasm3_multi_regs (void ) {
645- auto qreg1 = QuantumRegister (2 , std::string (" q1" ));
646- auto qreg2 = QuantumRegister (1 , std::string (" q2" ));
647- auto creg1 = ClassicalRegister (2 , std::string (" c1" ));
648- auto creg2 = ClassicalRegister (1 , std::string (" c2" ));
649- QuantumCircuit circ (std::vector<QuantumRegister>({qreg1, qreg2}),
650- std::vector<ClassicalRegister>({creg1, creg2}));
651-
652- circ.measure (qreg2, creg2);
653- circ.measure (qreg1, creg1);
654-
655- const auto actual = circ.to_qasm3 ();
656- const std::string expected = " OPENQASM 3.0;\n "
657- " include \" stdgates.inc\" ;\n "
658- " qubit[3] q;\n "
659- " bit[2] c1;\n "
660- " bit[1] c2;\n "
661- " c2[0] = measure q[2];\n "
662- " c1[0] = measure q[0];\n "
663- " c1[1] = measure q[1];\n " ;
664- if (actual != expected) {
665- std::cerr << " to_qasm3_multi_regs test : \n expected:\n "
666- << expected << " \n actual:\n "
667- << actual << std::endl;
668- return EqualityError;
669- }
670-
671- return Ok;
672- }
673-
674644static int test_to_qasm3_single_param (void ) {
675- auto circ = QuantumCircuit (1 , 0 );
676- Parameter theta (" theta" );
677- circ.rx (theta, 0 );
678-
679- const auto actual = circ.to_qasm3 ();
680- const std::string expected = " OPENQASM 3.0;\n "
681- " include \" stdgates.inc\" ;\n "
682- " input float[64] theta;\n "
683- " qubit[1] q;\n "
684- " rx(theta) q[0];\n " ;
685- if (actual != expected) {
686- std::cerr << " to_qasm3_single_param test : \n expected:\n "
687- << expected << " \n actual:\n "
688- << actual << std::endl;
689- return EqualityError;
690- }
691- return Ok;
645+ auto circ = QuantumCircuit (1 , 0 );
646+ Parameter theta (" theta" );
647+ circ.rx (theta, 0 );
648+
649+ const auto actual = circ.to_qasm3 ();
650+ const std::string expected = " OPENQASM 3.0;\n "
651+ " include \" stdgates.inc\" ;\n "
652+ " input float[64] theta;\n "
653+ " qubit[1] q;\n "
654+ " rx(theta) q[0];\n " ;
655+ if (actual != expected) {
656+ std::cerr << " to_qasm3_single_param test : \n expected:\n "
657+ << expected << " \n actual:\n "
658+ << actual << std::endl;
659+ return EqualityError;
660+ }
661+ return Ok;
692662}
693663
694664static int test_to_qasm3_multiple_params (void ) {
695- auto circ = QuantumCircuit (2 , 0 );
696- Parameter alpha (" alpha" );
697- Parameter beta (" beta" );
698- circ.rx (alpha, 0 );
699- circ.ry (beta, 1 );
700-
701- const auto actual = circ.to_qasm3 ();
702- const std::string expected = " OPENQASM 3.0;\n "
703- " include \" stdgates.inc\" ;\n "
704- " input float[64] alpha;\n "
705- " input float[64] beta;\n "
706- " qubit[2] q;\n "
707- " rx(alpha) q[0];\n "
708- " ry(beta) q[1];\n " ;
709- if (actual != expected) {
710- std::cerr << " to_qasm3_multiple_params test : \n expected:\n "
711- << expected << " \n actual:\n "
712- << actual << std::endl;
713- return EqualityError;
714- }
715- return Ok;
665+ auto circ = QuantumCircuit (2 , 0 );
666+ Parameter alpha (" alpha" );
667+ Parameter beta (" beta" );
668+ circ.rx (alpha, 0 );
669+ circ.ry (beta, 1 );
670+
671+ const auto actual = circ.to_qasm3 ();
672+ const std::string expected = " OPENQASM 3.0;\n "
673+ " include \" stdgates.inc\" ;\n "
674+ " input float[64] alpha;\n "
675+ " input float[64] beta;\n "
676+ " qubit[2] q;\n "
677+ " rx(alpha) q[0];\n "
678+ " ry(beta) q[1];\n " ;
679+ if (actual != expected) {
680+ std::cerr << " to_qasm3_multiple_params test : \n expected:\n "
681+ << expected << " \n actual:\n "
682+ << actual << std::endl;
683+ return EqualityError;
684+ }
685+ return Ok;
716686}
717687
718688static int test_to_qasm3_expression_param (void ) {
719- auto circ = QuantumCircuit (1 , 0 );
720- Parameter t (" t" );
721- Parameter expr = t + Parameter (0.5 );
722- circ.rz (expr, 0 );
723-
724- const auto actual = circ.to_qasm3 ();
725- // The expression "0.5 + t" (or "t + 0.5") should cause only "t" to be
726- // declared as input, not the numeric literal.
727- if (actual.find (" input float[64] t;" ) == std::string::npos) {
728- std::cerr
729- << " to_qasm3_expression_param test : missing 'input float[64] t;'\n "
730- << " actual:\n "
731- << actual << std::endl;
732- return EqualityError;
733- }
734-
735- size_t count = 0 ;
736- size_t pos = 0 ;
737- while ((pos = actual.find (" input float[64]" , pos)) != std::string::npos) {
738- count++;
739- pos += 15 ;
740- }
741- if (count != 1 ) {
742- std::cerr << " to_qasm3_expression_param test : expected 1 input "
743- " declaration, got "
744- << count << " \n actual:\n "
745- << actual << std::endl;
746- return EqualityError;
747- }
748- return Ok;
689+ auto circ = QuantumCircuit (1 , 0 );
690+ Parameter t (" t" );
691+ Parameter expr = t + Parameter (0.5 );
692+ circ.rz (expr, 0 );
693+
694+ const auto actual = circ.to_qasm3 ();
695+ // The expression "0.5 + t" (or "t + 0.5") should cause only "t" to be
696+ // declared as input, not the numeric literal.
697+ if (actual.find (" input float[64] t;" ) == std::string::npos) {
698+ std::cerr
699+ << " to_qasm3_expression_param test : missing 'input float[64] t;'\n "
700+ << " actual:\n "
701+ << actual << std::endl;
702+ return EqualityError;
703+ }
704+
705+ size_t count = 0 ;
706+ size_t pos = 0 ;
707+ while ((pos = actual.find (" input float[64]" , pos)) != std::string::npos) {
708+ count++;
709+ pos += 15 ;
710+ }
711+ if (count != 1 ) {
712+ std::cerr << " to_qasm3_expression_param test : expected 1 input "
713+ " declaration, got "
714+ << count << " \n actual:\n "
715+ << actual << std::endl;
716+ return EqualityError;
717+ }
718+ return Ok;
749719}
750720
751721#if defined(_WIN32)
0 commit comments