@@ -62,6 +62,23 @@ def circuit(omega):
62
62
assert np .allclose (np .sum (prob ), 1.0 )
63
63
assert prob [index ] > 0.95
64
64
65
+ @pytest .mark .skipif (not LightningDevice ._new_API , reason = "New API required." )
66
+ @pytest .mark .parametrize ("wires" , [5 , 10 , 13 , 15 ])
67
+ def test_preprocess_grover_operator_decomposition (self , wires ):
68
+ """Test that qml.GroverOperator is not decomposed for less than 10 wires."""
69
+ tape = qml .tape .QuantumScript (
70
+ [qml .GroverOperator (wires = list (range (wires )))], [qml .expval (qml .PauliZ (0 ))]
71
+ )
72
+ dev = LightningDevice (wires = wires )
73
+
74
+ program , _ = dev .preprocess ()
75
+ [new_tape ], _ = program ([tape ])
76
+
77
+ if wires >= 13 :
78
+ assert all (not isinstance (op , qml .GroverOperator ) for op in new_tape .operations )
79
+ else :
80
+ assert tape .operations == [qml .GroverOperator (wires = list (range (wires )))]
81
+
65
82
66
83
class TestAngleEmbedding :
67
84
"""Test the AngleEmbedding algorithm."""
@@ -416,7 +433,6 @@ class TestGateFabric:
416
433
"""Test the GateFabric algorithm."""
417
434
418
435
def test_gatefabric (self ):
419
-
420
436
# Build the electronic Hamiltonian
421
437
symbols = ["H" , "H" ]
422
438
coordinates = np .array ([0.0 , 0.0 , - 0.6614 , 0.0 , 0.0 , 0.6614 ])
@@ -446,7 +462,6 @@ class TestUCCSD:
446
462
"""Test the UCCSD algorithm."""
447
463
448
464
def test_uccsd (self ):
449
-
450
465
# Define the molecule
451
466
symbols = ["H" , "H" , "H" ]
452
467
geometry = np .array (
@@ -490,7 +505,6 @@ class TestkUpCCGSD:
490
505
"""Test the kUpCCGSD algorithm."""
491
506
492
507
def test_kupccgsd (self ):
493
-
494
508
# Define the molecule
495
509
symbols = ["H" , "H" , "H" ]
496
510
geometry = np .array (
@@ -533,7 +547,6 @@ class TestParticleConservingU1:
533
547
"""Test the ParticleConservingU1 algorithm."""
534
548
535
549
def test_particleconservingu1 (self ):
536
-
537
550
# Build the electronic Hamiltonian
538
551
symbols , coordinates = (["H" , "H" ], np .array ([0.0 , 0.0 , - 0.66140414 , 0.0 , 0.0 , 0.66140414 ]))
539
552
_ , n_qubits = qml .qchem .molecular_hamiltonian (symbols , coordinates )
@@ -567,7 +580,6 @@ class TestParticleConservingU2:
567
580
"""Test the ParticleConservingU2 algorithm."""
568
581
569
582
def test_particleconservingu2 (self ):
570
-
571
583
# Build the electronic Hamiltonian
572
584
symbols , coordinates = (["H" , "H" ], np .array ([0.0 , 0.0 , - 0.66140414 , 0.0 , 0.0 , 0.66140414 ]))
573
585
_ , n_qubits = qml .qchem .molecular_hamiltonian (symbols , coordinates )
@@ -668,7 +680,6 @@ class TestQuantumPhaseEstimation:
668
680
669
681
@pytest .mark .parametrize ("n_qubits" , range (2 , 14 , 2 ))
670
682
def test_quantumphaseestimation (self , n_qubits ):
671
-
672
683
phase = 5
673
684
target_wires = [0 ]
674
685
unitary = qml .RX (phase , wires = 0 ).matrix ()
@@ -701,7 +712,6 @@ class TestQFT:
701
712
702
713
@pytest .mark .parametrize ("n_qubits" , range (2 , 14 , 2 ))
703
714
def test_qft (self , n_qubits ):
704
-
705
715
dev = qml .device (device_name , wires = n_qubits )
706
716
dq = qml .device ("default.qubit" )
707
717
@@ -717,13 +727,29 @@ def circuit(basis_state):
717
727
718
728
assert np .allclose (res , ref )
719
729
730
+ @pytest .mark .skipif (not LightningDevice ._new_API , reason = "New API required" )
731
+ @pytest .mark .parametrize ("wires" , [5 , 9 , 10 , 13 ])
732
+ def test_preprocess_qft_decomposition (self , wires ):
733
+ """Test that qml.QFT is not decomposed for less than 10 wires."""
734
+ tape = qml .tape .QuantumScript (
735
+ [qml .QFT (wires = list (range (wires )))], [qml .expval (qml .PauliZ (0 ))]
736
+ )
737
+ dev = LightningDevice (wires = wires )
738
+
739
+ program , _ = dev .preprocess ()
740
+ [new_tape ], _ = program ([tape ])
741
+
742
+ if wires >= 10 :
743
+ assert all (not isinstance (op , qml .QFT ) for op in new_tape .operations )
744
+ else :
745
+ assert tape .operations == [qml .QFT (wires = list (range (wires )))]
746
+
720
747
721
748
class TestAQFT :
722
749
"""Test the AQFT algorithm."""
723
750
724
751
@pytest .mark .parametrize ("n_qubits" , range (4 , 14 , 2 ))
725
752
def test_aqft (self , n_qubits ):
726
-
727
753
dev = qml .device (device_name , wires = n_qubits )
728
754
dq = qml .device ("default.qubit" )
729
755
0 commit comments