From 7a0d5d58e676737bc8b76e9bf81cb313f9d6bc56 Mon Sep 17 00:00:00 2001 From: Rajib Chakravorty Date: Mon, 20 May 2019 10:39:39 +1000 Subject: [PATCH 1/3] pre_post_gate_parameters=None changes behaviour - omits pre_post_gates altogether --- qctrlopencontrols/qiskit/__init__.py | 3 +- qctrlopencontrols/qiskit/constants.py | 6 +++ qctrlopencontrols/qiskit/quantum_circuit.py | 53 +++++++++++---------- tests/test_qiskit_sequence.py | 14 +++--- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/qctrlopencontrols/qiskit/__init__.py b/qctrlopencontrols/qiskit/__init__.py index 062224f0..5c968758 100644 --- a/qctrlopencontrols/qiskit/__init__.py +++ b/qctrlopencontrols/qiskit/__init__.py @@ -18,5 +18,6 @@ ============= """ -from .constants import (FIX_DURATION_UNITARY, INSTANT_UNITARY) +from .constants import (FIX_DURATION_UNITARY, INSTANT_UNITARY, + DEFAULT_PRE_POST_GATE_PARAMETERS) from .quantum_circuit import convert_dds_to_quantum_circuit diff --git a/qctrlopencontrols/qiskit/constants.py b/qctrlopencontrols/qiskit/constants.py index ee1cb269..91618fcd 100644 --- a/qctrlopencontrols/qiskit/constants.py +++ b/qctrlopencontrols/qiskit/constants.py @@ -18,6 +18,8 @@ ================ """ +import numpy as np + FIX_DURATION_UNITARY = 'fixed duration unitary' """Algorithm to convert a DDS to Quantum circuit where the unitaries are considered as gates with finite duration @@ -27,3 +29,7 @@ """Algorithm to convert a DDS to Quantum circuit where the unitaties are considered as instantaneous operation. """ + +DEFAULT_PRE_POST_GATE_PARAMETERS = (np.pi / 2, -np.pi / 2, np.pi / 2) +"""Parameters of a default U3 gate for pre-post rotation for circuits. +""" diff --git a/qctrlopencontrols/qiskit/quantum_circuit.py b/qctrlopencontrols/qiskit/quantum_circuit.py index 548b12c1..06cc0e25 100644 --- a/qctrlopencontrols/qiskit/quantum_circuit.py +++ b/qctrlopencontrols/qiskit/quantum_circuit.py @@ -27,7 +27,8 @@ from qctrlopencontrols.dynamic_decoupling_sequences import DynamicDecouplingSequence from qctrlopencontrols.exceptions import ArgumentsValueError -from .constants import (FIX_DURATION_UNITARY, INSTANT_UNITARY) +from .constants import (FIX_DURATION_UNITARY, INSTANT_UNITARY, + DEFAULT_PRE_POST_GATE_PARAMETERS) def _get_circuit_gate_list(dynamic_decoupling_sequence, @@ -131,7 +132,7 @@ def convert_dds_to_quantum_circuit( dynamic_decoupling_sequence, target_qubits=None, gate_time=0.1, - pre_post_gate_parameters=None, + pre_post_gate_parameters=DEFAULT_PRE_POST_GATE_PARAMETERS, add_measurement=True, algorithm=FIX_DURATION_UNITARY, quantum_registers=None, @@ -148,13 +149,14 @@ def convert_dds_to_quantum_circuit( defaults to None gate_time : float, optional Time (in seconds) delay introduced by a gate; defaults to 0.1 - pre_post_gate_parameters : list, optional - List of (length 3) floating point numbers; These numbers correspond to :math:`\\theta, - \\phi, \\lambda` parameters in `U3` gate defined in Qiskit as `U3Gate(theta, phi, lamda)`. - Qiskit documentation suggests this to be the most generalized definition of unitary - gates. Defaults to None; if None, the parameters are assumed to be - :math:`[pi/2, -pi/2, pi/2]` that corresponds to `pi/2` rotation around X-axis. - See `IBM-Q Documentation + pre_post_gate_parameters : tuple or None, optional + Tuple of (length 3) floating point numbers that correspond to :math:`\\theta, + \\phi, \\lambda` parameters respectively in `U3` gate defined in Qiskit + as `U3Gate(theta, phi, lamda)`. Qiskit documentation suggests this to be + the most generalized definition of unitary gates. Defaults to + (pi/2, -pi/2, pi/2) that corresponds to a :math:`pi/2` + rotation around X-axis; if None, the resulting circuit will have no `pre` or `post` + gater. See `IBM-Q Documentation Date: Mon, 20 May 2019 12:14:26 +1000 Subject: [PATCH 2/3] removed some comments --- qctrlopencontrols/qiskit/quantum_circuit.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/qctrlopencontrols/qiskit/quantum_circuit.py b/qctrlopencontrols/qiskit/quantum_circuit.py index 06cc0e25..04207456 100644 --- a/qctrlopencontrols/qiskit/quantum_circuit.py +++ b/qctrlopencontrols/qiskit/quantum_circuit.py @@ -219,9 +219,6 @@ def convert_dds_to_quantum_circuit( if target_qubits is None: target_qubits = [0] - #if pre_post_gate_parameters is None: - # pre_post_gate_parameters = - if (pre_post_gate_parameters is not None and len(pre_post_gate_parameters) != 3): raise ArgumentsValueError('Pre-Post gate parameters must be a list of 3 ' From 6f4438a35c6bd5a35c77b5e025d1b6b7ce1962cf Mon Sep 17 00:00:00 2001 From: Rajib Chakravorty Date: Mon, 20 May 2019 12:19:33 +1000 Subject: [PATCH 3/3] correction in docstring --- qctrlopencontrols/qiskit/quantum_circuit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qctrlopencontrols/qiskit/quantum_circuit.py b/qctrlopencontrols/qiskit/quantum_circuit.py index 04207456..0b0c6e32 100644 --- a/qctrlopencontrols/qiskit/quantum_circuit.py +++ b/qctrlopencontrols/qiskit/quantum_circuit.py @@ -152,11 +152,11 @@ def convert_dds_to_quantum_circuit( pre_post_gate_parameters : tuple or None, optional Tuple of (length 3) floating point numbers that correspond to :math:`\\theta, \\phi, \\lambda` parameters respectively in `U3` gate defined in Qiskit - as `U3Gate(theta, phi, lamda)`. Qiskit documentation suggests this to be + as `U3Gate(theta, phi, lambda)`. Qiskit documentation suggests this to be the most generalized definition of unitary gates. Defaults to (pi/2, -pi/2, pi/2) that corresponds to a :math:`pi/2` rotation around X-axis; if None, the resulting circuit will have no `pre` or `post` - gater. See `IBM-Q Documentation + gates. See `IBM-Q Documentation