From 2da92c37e539e6d30853163dab0e8aaabef9fb02 Mon Sep 17 00:00:00 2001 From: Mark Fingerhuth Date: Fri, 30 Mar 2018 00:48:46 -0400 Subject: [PATCH 1/2] removing unnecessary identity operation from exponential_map() the hardcoded implementation of the identity operation on the 0th qubit unnecessarily inflates circuits (even if it gets removed later in the compiler) and leads to problems when using the new ``embedding`` argument in the QAOA instance --- pyquil/paulis.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pyquil/paulis.py b/pyquil/paulis.py index bb44bb4f1..6276e3433 100644 --- a/pyquil/paulis.py +++ b/pyquil/paulis.py @@ -688,12 +688,7 @@ def exponential_map(term): def exp_wrap(param): prog = Program() - if is_identity(term): - prog.inst(X(0)) - prog.inst(PHASE(-param * coeff)(0)) - prog.inst(X(0)) - prog.inst(PHASE(-param * coeff)(0)) - else: + if not is_identity(term): prog += _exponentiate_general_case(term, param) return prog From aec87e94090f8f7a47f75c62efe321a9d8f5beca Mon Sep 17 00:00:00 2001 From: Mark Fingerhuth Date: Fri, 30 Mar 2018 15:31:58 -0400 Subject: [PATCH 2/2] fixed test_exponentiate_identity tests appropriately --- pyquil/tests/test_paulis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyquil/tests/test_paulis.py b/pyquil/tests/test_paulis.py index f0c37e3d5..33bb5cfcb 100644 --- a/pyquil/tests/test_paulis.py +++ b/pyquil/tests/test_paulis.py @@ -349,19 +349,19 @@ def test_exponentiate_identity(): generator = PauliTerm("I", 1, 0.0) para_prog = exponential_map(generator) prog = para_prog(1) - result_prog = Program().inst([X(0), PHASE(-0.0)(0), X(0), PHASE(-0.0)(0)]) + result_prog = Program() assert prog == result_prog generator = PauliTerm("I", 1, 1.0) para_prog = exponential_map(generator) prog = para_prog(1) - result_prog = Program().inst([X(0), PHASE(-1.0)(0), X(0), PHASE(-1.0)(0)]) + result_prog = Program() assert prog == result_prog generator = PauliTerm("I", 10, 0.08) para_prog = exponential_map(generator) prog = para_prog(1) - result_prog = Program().inst([X(0), PHASE(-0.08)(0), X(0), PHASE(-0.08)(0)]) + result_prog = Program() assert prog == result_prog