Skip to content

Commit

Permalink
add test for diagonal fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Jan 27, 2021
1 parent 224fa91 commit 88aa34f
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions test/terra/backends/qasm_simulator/qasm_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def test_fusion_parallelization(self):
msg="parallelized fusion was failed")

def test_fusion_two_qubits(self):
"""Test Fusion parallelization option"""
"""Test 2-qubit fusion"""
shots = 100
num_qubits = 8
reps = 3
Expand Down Expand Up @@ -501,4 +501,39 @@ def test_fusion_two_qubits(self):
self.assertTrue(getattr(result_enabled, 'success', 'False'))

self.assertTrue(len(meta_enabled['output_ops']) if 'output_ops' in meta_enabled else len(circuit.ops) <
len(meta_disabled['output_ops']) if 'output_ops' in meta_disabled else len(circuit.ops))
len(meta_disabled['output_ops']) if 'output_ops' in meta_disabled else len(circuit.ops))

def test_fusion_diagonal(self):
"""Test diagonal fusion"""
shots = 100
num_qubits = 8

circuit = QuantumCircuit(num_qubits)
for i in range(num_qubits):
circuit.p(0.1, i)

for i in range(num_qubits - 1):
circuit.cp(0.1, i, i + 1)

circuit = transpile(circuit,
backend=self.SIMULATOR,
optimization_level=0)
circuit.measure_all()

qobj = assemble([circuit],
self.SIMULATOR,
shots=shots,
seed_simulator=1)

backend_options = self.fusion_options(enabled=True, threshold=1)
backend_options['fusion_verbose'] = True

backend_options['fusion_enable.cost_base'] = False
result = self.SIMULATOR.run(qobj, **backend_options).result()
meta = self.fusion_metadata(result)

for op in meta['output_ops']:
op_name = op['name']
if op_name == 'measure':
break
self.assertEqual(op_name, 'diagonal')

0 comments on commit 88aa34f

Please sign in to comment.