Skip to content

Commit

Permalink
Add global phase to qobj in assembly (#4822)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mtreinish authored Jul 29, 2020
1 parent b84590b commit 3c039db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion qiskit/assembler/assemble_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions test/python/compiler/test_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 3c039db

Please sign in to comment.