From 4a4d36b65c5a407f9770e561ec30f166f5cc61f5 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 29 Jul 2020 06:27:43 -0400 Subject: [PATCH 1/2] Add global phase to qobj in assembly This commit adds the global phase circuit property to the experiment headers in the assembled qobj. Currently we do not pass the global phase to backends so simulators can not take it into account. The experiment header is used since it's a free form field for properties of the circuit that a backend can use if they want, but there are no requirements on it. With this in place it should enable #4805 and Qiskit/qiskit-aer#847 to be fixed. Related to #4805 --- qiskit/assembler/assemble_circuits.py | 3 ++- test/python/compiler/test_assembler.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/qiskit/assembler/assemble_circuits.py b/qiskit/assembler/assemble_circuits.py index 931f86aa99c5..ca5aa5d2087e 100644 --- a/qiskit/assembler/assemble_circuits.py +++ b/qiskit/assembler/assemble_circuits.py @@ -47,7 +47,8 @@ def _assemble_circuit(circuit): clbit_labels=clbit_labels, memory_slots=memory_slots, creg_sizes=creg_sizes, - name=circuit.name) + name=circuit.name, + global_phase=circuit.global_phase) # TODO: why do we need n_qubits and memory_slots in both the header and the config config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots) diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index e2e537f602c0..29c577628f70 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -342,6 +342,19 @@ def test_init_qubits_false(self): qobj = assemble(self.circ, init_qubits=False) self.assertEqual(qobj.config.init_qubits, False) + def test_circuit_with_global_phase(self): + """Test that global phase for a circuit is handled correctly.""" + circ = QuantumCircuit(2) + circ.h(0) + circ.cx(0, 1) + circ.measure_all + circ.global_phase = .3 * np.pi + qobj = assemble([circ, self.circ]) + self.assertEqual(getattr(qobj.experiments[1].header, 'global_phase'), + 0) + self.assertEqual(getattr(qobj.experiments[0].header, 'global_phase'), + .3 * np.pi) + class TestPulseAssembler(QiskitTestCase): """Tests for assembling schedules to qobj.""" From 2846a1f9f06195180d46912b8d5e006da02e4328 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 29 Jul 2020 06:49:18 -0400 Subject: [PATCH 2/2] Fix lint --- test/python/compiler/test_assembler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/python/compiler/test_assembler.py b/test/python/compiler/test_assembler.py index 29c577628f70..ab20ce700e6d 100644 --- a/test/python/compiler/test_assembler.py +++ b/test/python/compiler/test_assembler.py @@ -347,7 +347,7 @@ def test_circuit_with_global_phase(self): circ = QuantumCircuit(2) circ.h(0) circ.cx(0, 1) - circ.measure_all + circ.measure_all() circ.global_phase = .3 * np.pi qobj = assemble([circ, self.circ]) self.assertEqual(getattr(qobj.experiments[1].header, 'global_phase'),