From 678bb9ee6cacaf8fc778b2bcd11014d60957f12a Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Wed, 21 Aug 2024 21:32:48 +0200 Subject: [PATCH 01/11] 20240821.1 added the eblock entanglmer and the digital ALT functions --- qadence/constructors/ansatze.py | 117 ++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index b156c66e9..d2eae3ab3 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -320,3 +320,120 @@ def hea_bDAQC(*args: Any, **kwargs: Any) -> Any: def hea_analog(*args: Any, **kwargs: Any) -> Any: raise NotImplementedError + + + +################# +## DIGITAL ALT ## +################# + + + + +def _entanglers_block_digital( + n_qubits: int, + m_block_qubits:int, + depth: int, + param_prefix: str = "theta", + support: tuple[int, ...] = None, + periodic: bool = False, + entangler: Type[DigitalEntanglers] = CNOT, +) -> list[AbstractBlock]: + if support is None: + support = tuple(range(n_qubits)) + iterator = itertools.count() + ent_list: list[AbstractBlock] = [] + + for d in range(depth): + ents=[] + if not d%2: + ents.append( + kron( + _entangler(control=support[i+j],target=support[i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + + for i in range(0,n_qubits,m_block_qubits) + for j in range(0,m_block_qubits,2) + if i+j+1 2: + ents.append( + kron( + _entangler(control=support[i+j],target=support[i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + + for i in range(0,n_qubits,m_block_qubits) + for j in range(1,m_block_qubits,2) + if i+j+1=0 + ) + + ) + if m_block_qubits > 2: + ents.append( + kron( + _entangler(control=support[ i+j],target=support[ i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + + for i in range(-m_block_qubits//2,n_qubits,m_block_qubits) + for j in range(1,m_block_qubits,2) + if i+j+1=0 + ) + + ) + + + + ent_list.append(chain(*ents)) + return ent_list + + +def alt_digital( + n_qubits:int, + m_qubits_block:int, + depth:int=1, + support:tuple[int,...]=None, + + param_prefix:str='theta', + + operations : list[Type(AbstractBlock)]=[RX,RY,RZ], + entangler: Type[DigitalEntanglers]=CNOT, + + +)->AbstractBlock: + print(depth) + rot_list = _rotations_digital( + n_qubits=n_qubits, + + depth=depth, + support=support, + param_prefix=param_prefix, + operations=operations + ) + + ent_list = _entanglers_block_digital( + n_qubits, + m_qubits_block, + param_prefix=param_prefix+'_ent', + depth=depth, + support=support, + entangler=entangler + ) + + layers = [] + for d in range(depth): + layers.append(rot_list[d]) + layers.append(ent_list[d]) + + return chain(*layers) + From 5bb29e94da721fc9bf92f9329fee2f98f7cc0f97 Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Fri, 23 Aug 2024 16:57:49 +0200 Subject: [PATCH 02/11] 20240823.1 delete unecessary display --- qadence/constructors/ansatze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index d2eae3ab3..a85bae751 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -411,7 +411,7 @@ def alt_digital( )->AbstractBlock: - print(depth) + rot_list = _rotations_digital( n_qubits=n_qubits, From 9fa438f452b621eea2aacf9ae9c7bd2c165f815a Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Sun, 25 Aug 2024 18:18:51 +0200 Subject: [PATCH 03/11] 20240825.1 first implementation of precommit suggestion --- qadence/constructors/ansatze.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index a85bae751..e01c29f4a 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -349,7 +349,12 @@ def _entanglers_block_digital( if not d%2: ents.append( kron( - _entangler(control=support[i+j],target=support[i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + _entangler( + control=support[i+j], + target=support[i+j+1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler + ) for i in range(0,n_qubits,m_block_qubits) for j in range(0,m_block_qubits,2) @@ -360,7 +365,12 @@ def _entanglers_block_digital( if m_block_qubits > 2: ents.append( kron( - _entangler(control=support[i+j],target=support[i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + _entangler( + control=support[i+j], + target=support[i+j+1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler + ) for i in range(0,n_qubits,m_block_qubits) for j in range(1,m_block_qubits,2) @@ -372,7 +382,12 @@ def _entanglers_block_digital( elif d%2: ents.append( kron( - _entangler(control=support[ i +j],target=support[i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + _entangler( + control=support[ i +j], + target=support[i+j+1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler + ) for i in range(-m_block_qubits//2,n_qubits,m_block_qubits) for j in range(0,m_block_qubits,2) @@ -383,7 +398,12 @@ def _entanglers_block_digital( if m_block_qubits > 2: ents.append( kron( - _entangler(control=support[ i+j],target=support[ i+j+1],param_str=param_prefix + f"_ent_{next(iterator)}",op=entangler) + _entangler( + control=support[ i+j], + target=support[ i+j+1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler + ) for i in range(-m_block_qubits//2,n_qubits,m_block_qubits) for j in range(1,m_block_qubits,2) @@ -406,7 +426,7 @@ def alt_digital( param_prefix:str='theta', - operations : list[Type(AbstractBlock)]=[RX,RY,RZ], + operations : list[type[AbstractBlock]]=[RX,RY], entangler: Type[DigitalEntanglers]=CNOT, From 0d2fc7926d0b35077a8c20c7986c369f49d60f03 Mon Sep 17 00:00:00 2001 From: ducthanh_tran <96840542+ducthanh1991@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:56:34 +0000 Subject: [PATCH 04/11] 20240827.1 added code documentation --- qadence/constructors/ansatze.py | 162 ++++++++++++++++---------------- 1 file changed, 83 insertions(+), 79 deletions(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index e01c29f4a..efb4d8e40 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -322,17 +322,14 @@ def hea_analog(*args: Any, **kwargs: Any) -> Any: raise NotImplementedError - ################# ## DIGITAL ALT ## ################# - - def _entanglers_block_digital( n_qubits: int, - m_block_qubits:int, + m_block_qubits: int, depth: int, param_prefix: str = "theta", support: tuple[int, ...] = None, @@ -345,115 +342,122 @@ def _entanglers_block_digital( ent_list: list[AbstractBlock] = [] for d in range(depth): - ents=[] - if not d%2: - ents.append( - kron( - _entangler( - control=support[i+j], - target=support[i+j+1], - param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler - ) - - for i in range(0,n_qubits,m_block_qubits) - for j in range(0,m_block_qubits,2) - if i+j+1 2: - ents.append( + ents = [] + if not d % 2: + ents.append( kron( _entangler( - control=support[i+j], - target=support[i+j+1], + control=support[i + j], + target=support[i + j + 1], param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler + op=entangler, + ) + for i in range(0, n_qubits, m_block_qubits) + for j in range(0, m_block_qubits, 2) + if i + j + 1 < n_qubits and j + 1 < m_block_qubits + ) + ) + if m_block_qubits > 2: + ents.append( + kron( + _entangler( + control=support[i + j], + target=support[i + j + 1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler, ) - - for i in range(0,n_qubits,m_block_qubits) - for j in range(1,m_block_qubits,2) - if i+j+1=0 - ) - + kron( + _entangler( + control=support[i + j], + target=support[i + j + 1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler, + ) + for i in range(-m_block_qubits // 2, n_qubits, m_block_qubits) + for j in range(0, m_block_qubits, 2) + if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 ) + ) if m_block_qubits > 2: ents.append( kron( _entangler( - control=support[ i+j], - target=support[ i+j+1], + control=support[i + j], + target=support[i + j + 1], param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler - ) - - for i in range(-m_block_qubits//2,n_qubits,m_block_qubits) - for j in range(1,m_block_qubits,2) - if i+j+1=0 + op=entangler, ) - + for i in range(-m_block_qubits // 2, n_qubits, m_block_qubits) + for j in range(1, m_block_qubits, 2) + if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 ) + ) - - ent_list.append(chain(*ents)) return ent_list def alt_digital( - n_qubits:int, - m_qubits_block:int, - depth:int=1, - support:tuple[int,...]=None, - - param_prefix:str='theta', - - operations : list[type[AbstractBlock]]=[RX,RY], - entangler: Type[DigitalEntanglers]=CNOT, - - -)->AbstractBlock: - + n_qubits: int, + m_qubits_block: int, + depth: int = 1, + support: tuple[int, ...] = None, + param_prefix: str = "theta", + operations: list[type[AbstractBlock]] = [RX, RY], + entangler: Type[DigitalEntanglers] = CNOT, +) -> AbstractBlock: + """ + Construct the digital alternating layer ansatz (ALT). + + Args: + n_qubits (int): number of qubits in the ansatz. + m_qubits_block (int): number of qubits in the local entangling block. + depth (int): number of layers of the ALT. + param_prefix (str): the base name of the variational parameters + operations (list): list of operations to cycle through in the + digital single-qubit rotations of each layer. + support (tuple): qubit indexes where the ALT is applied. + entangler (AbstractBlock): 2-qubit entangling operation. + Supports CNOT, CZ, CRX, CRY, CRZ. Controlld rotations + will have variational parameters on the rotation angles. + """ + + try: + if entangler not in [CNOT, CZ, CRX, CRY, CRZ, CPHASE]: + raise ValueError( + "Please provide a valid two-qubit entangler operation for digital ALT." + ) + except TypeError: + raise ValueError("Please provide a valid two-qubit entangler operation for digital ALT.") + rot_list = _rotations_digital( n_qubits=n_qubits, - depth=depth, support=support, param_prefix=param_prefix, - operations=operations - ) - + operations=operations, + ) + ent_list = _entanglers_block_digital( n_qubits, m_qubits_block, - param_prefix=param_prefix+'_ent', + param_prefix=param_prefix + "_ent", depth=depth, support=support, - entangler=entangler - ) + entangler=entangler, + ) layers = [] for d in range(depth): layers.append(rot_list[d]) layers.append(ent_list[d]) - - return chain(*layers) + return tag(chain(*layers), "ALT") From 06d96c9017a2885e79e0772b46a8a88047197855 Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Tue, 27 Aug 2024 21:46:40 +0200 Subject: [PATCH 05/11] 200827.2 added the factory function for ALT --- qadence/constructors/ansatze.py | 79 ++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index efb4d8e40..bc017bcba 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -322,6 +322,63 @@ def hea_analog(*args: Any, **kwargs: Any) -> Any: raise NotImplementedError +def alt( + n_qubits: int, + m_block_qubits: int, + depth: int = 1, + param_prefix: str = "theta", + support: tuple[int, ...] = None, + strategy: Strategy = Strategy.DIGITAL, + **strategy_args: Any, +) -> AbstractBlock: + """ + Factory function for the Alternating Layer Ansatz (ALT). + + Args: + n_qubits: number of qubits in the block + depth: number of layers of the ALT + param_prefix: the base name of the variational parameters + support: qubit indexes where the ALT is applied + strategy: Strategy.Digital or Strategy.DigitalAnalog + **strategy_args: see below + + Keyword Arguments: + operations (list): list of operations to cycle through in the + digital single-qubit rotations of each layer. Valid for + Digital . + entangler (AbstractBlock): + - Digital: 2-qubit entangling operation. Supports CNOT, CZ, + CRX, CRY, CRZ, CPHASE. Controlled rotations will have variational + parameters on the rotation angles. + """ + + if support is None: + support = tuple(range(n_qubits)) + + alt_func_dict = { + Strategy.DIGITAL: alt_digital, + Strategy.SDAQC: alt_sDAQC, + Strategy.BDAQC: alt_bDAQC, + Strategy.ANALOG: alt_analog, + } + + try: + alt_func = alt_func_dict[strategy] + except KeyError: + raise KeyError(f"Strategy {strategy} not recognized.") + + hea_block: AbstractBlock = alt_func( + n_qubits=n_qubits, + m_block_qubits=m_block_qubits, + depth=depth, + param_prefix=param_prefix, + support=support, + **strategy_args, + ) # type: ignore + + return hea_block + + ################# ## DIGITAL ALT ## ################# @@ -333,7 +390,6 @@ def _entanglers_block_digital( depth: int, param_prefix: str = "theta", support: tuple[int, ...] = None, - periodic: bool = False, entangler: Type[DigitalEntanglers] = CNOT, ) -> list[AbstractBlock]: if support is None: @@ -461,3 +517,24 @@ def alt_digital( layers.append(ent_list[d]) return tag(chain(*layers), "ALT") + + +################# +## sdaqc ALT ## +################# +def alt_sDAQC(*args: Any, **kwargs: Any) -> Any: + raise NotImplementedError + + +################# +## bdaqc ALT ## +################# +def alt_bDAQC(*args: Any, **kwargs: Any) -> Any: + raise NotImplementedError + + +################# +## analog ALT ## +################# +def alt_analog(*args: Any, **kwargs: Any) -> Any: + raise NotImplementedError From 799a37c979068ee6c2675d2135f6858819c76bb9 Mon Sep 17 00:00:00 2001 From: ducthanh_tran <96840542+ducthanh1991@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:58:01 +0000 Subject: [PATCH 06/11] 20240828.2 corrected alt function typo --- qadence/constructors/ansatze.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index bc017bcba..b7a4ed4b1 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -463,7 +463,7 @@ def _entanglers_block_digital( def alt_digital( n_qubits: int, - m_qubits_block: int, + m_block_qubits: int, depth: int = 1, support: tuple[int, ...] = None, param_prefix: str = "theta", @@ -504,7 +504,7 @@ def alt_digital( ent_list = _entanglers_block_digital( n_qubits, - m_qubits_block, + m_block_qubits, param_prefix=param_prefix + "_ent", depth=depth, support=support, From 076ffc05d30a782952f9dbf8efa1d29c7e2b2fa1 Mon Sep 17 00:00:00 2001 From: ducthanh_tran <96840542+ducthanh1991@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:42:41 +0000 Subject: [PATCH 07/11] added test --- qadence/constructors/__init__.py | 3 +- tests/constructors/test_ansatz.py | 70 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/qadence/constructors/__init__.py b/qadence/constructors/__init__.py index c1110a7dc..fb24a7f65 100644 --- a/qadence/constructors/__init__.py +++ b/qadence/constructors/__init__.py @@ -5,7 +5,7 @@ exp_fourier_feature_map, ) -from .ansatze import hea +from .ansatze import hea, alt from .iia import identity_initialized_ansatz @@ -29,6 +29,7 @@ "feature_map", "exp_fourier_feature_map", "hea", + "alt", "identity_initialized_ansatz", "hamiltonian_factory", "ising_hamiltonian", diff --git a/tests/constructors/test_ansatz.py b/tests/constructors/test_ansatz.py index 698357c13..ba3ed421c 100644 --- a/tests/constructors/test_ansatz.py +++ b/tests/constructors/test_ansatz.py @@ -14,6 +14,7 @@ QuantumModel, VariationalParameter, Z, + alt, chain, hamiltonian_factory, hea, @@ -169,3 +170,72 @@ def test_iia_sDAQC(n_qubits: int, depth: int, hamiltonian: str) -> None: assert not has_duplicate_vparams(iia) if hamiltonian == "parametric_local": assert has_duplicate_vparams(iia) + + +@pytest.mark.parametrize("n_qubits", [10, 11]) +@pytest.mark.parametrize("m_block_qubits", [2, 3, 4]) +@pytest.mark.parametrize("depth", [2, 3]) +@pytest.mark.parametrize("entangler", [CNOT, CRX]) +def test_alt_duplicate_params( + n_qubits: int, m_block_qubits: int, depth: int, entangler: AbstractBlock +) -> None: + """Tests that ALTs are initialized with correct parameter namings.""" + common_params = { + "n_qubits": n_qubits, + "m_block_qubits": m_block_qubits, + "depth": depth, + "operations": [RZ, RX, RZ], + "entangler": entangler, + } + alt1 = alt( + n_qubits=n_qubits, + m_block_qubits=m_block_qubits, + depth=depth, + operations=[RZ, RX, RZ], + entangler=entangler, + ) + alt2 = alt( + n_qubits=n_qubits, + m_block_qubits=m_block_qubits, + depth=depth, + operations=[RZ, RX, RZ], + entangler=entangler, + ) + block1 = chain(alt1, alt2) + assert has_duplicate_vparams(block1) + alt1 = alt( + n_qubits=n_qubits, + m_block_qubits=m_block_qubits, + depth=depth, + operations=[RZ, RX, RZ], + entangler=entangler, + param_prefix="0", + ) + alt2 = alt( + n_qubits=n_qubits, + m_block_qubits=m_block_qubits, + depth=depth, + operations=[RZ, RX, RZ], + entangler=entangler, + param_prefix="1", + ) + block2 = chain(alt1, alt2) + assert not has_duplicate_vparams(block2) + + +@pytest.mark.parametrize("n_qubits", [10, 11]) +@pytest.mark.parametrize("m_block_qubits", [2, 3, 4]) +@pytest.mark.parametrize("depth", [2, 3]) +def test_alt_forward(n_qubits: int, m_block_qubits: int, depth: int) -> None: + alt1 = alt( + n_qubits=n_qubits, + m_block_qubits=m_block_qubits, + depth=depth, + operations=[RZ, RX, RZ], + param_prefix="0", + ) + circuit = QuantumCircuit(n_qubits, alt1) + model = QuantumModel(circuit) + + wf = model.run({}) + assert wf.shape == Size([1, 2**n_qubits]) From 1284210cb9dc5fb2ba2c7f9e02b6fcd84a7f86a5 Mon Sep 17 00:00:00 2001 From: ducthanh_tran <96840542+ducthanh1991@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:18:31 +0200 Subject: [PATCH 08/11] corrected typo in docstrings of alt function --- qadence/constructors/ansatze.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index b7a4ed4b1..3063d871c 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -336,6 +336,7 @@ def alt( Args: n_qubits: number of qubits in the block + m_block_qubits: number of qubits in the local entangling block depth: number of layers of the ALT param_prefix: the base name of the variational parameters support: qubit indexes where the ALT is applied @@ -475,7 +476,7 @@ def alt_digital( Args: n_qubits (int): number of qubits in the ansatz. - m_qubits_block (int): number of qubits in the local entangling block. + m_block_qubits (int): number of qubits in the local entangling block. depth (int): number of layers of the ALT. param_prefix (str): the base name of the variational parameters operations (list): list of operations to cycle through in the From a6ce1314ef89d10e34139c0520a6588b4d0c7c55 Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Wed, 18 Sep 2024 19:54:30 +0000 Subject: [PATCH 09/11] 20240918.1 removed repeating piece of code in the entangle_block_digital function --- qadence/constructors/ansatze.py | 75 +++++++-------------------------- 1 file changed, 16 insertions(+), 59 deletions(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index 3063d871c..07dd644ab 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -332,14 +332,14 @@ def alt( **strategy_args: Any, ) -> AbstractBlock: """ - Factory function for the Alternating Layer Ansatz (ALT). + Factory function for the alternating layer ansatz (alt). Args: n_qubits: number of qubits in the block m_block_qubits: number of qubits in the local entangling block - depth: number of layers of the ALT + depth: number of layers of the alt param_prefix: the base name of the variational parameters - support: qubit indexes where the ALT is applied + support: qubit indexes where the alt is applied strategy: Strategy.Digital or Strategy.DigitalAnalog **strategy_args: see below @@ -399,64 +399,21 @@ def _entanglers_block_digital( ent_list: list[AbstractBlock] = [] for d in range(depth): - ents = [] - if not d % 2: - ents.append( - kron( - _entangler( - control=support[i + j], - target=support[i + j + 1], - param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler, - ) - for i in range(0, n_qubits, m_block_qubits) - for j in range(0, m_block_qubits, 2) - if i + j + 1 < n_qubits and j + 1 < m_block_qubits - ) - ) - if m_block_qubits > 2: - ents.append( - kron( - _entangler( - control=support[i + j], - target=support[i + j + 1], - param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler, - ) - for i in range(0, n_qubits, m_block_qubits) - for j in range(1, m_block_qubits, 2) - if i + j + 1 < n_qubits and j + 1 < m_block_qubits - ) - ) - - elif d % 2: - ents.append( - kron( - _entangler( - control=support[i + j], - target=support[i + j + 1], - param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler, - ) - for i in range(-m_block_qubits // 2, n_qubits, m_block_qubits) - for j in range(0, m_block_qubits, 2) - if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 + start_i = 0 if not d % 2 else -m_block_qubits // 2 + ents = [ + kron( + _entangler( + control=support[i + j], + target=support[i + j + 1], + param_str=param_prefix + f"_ent_{next(iterator)}", + op=entangler, ) + for j in range(start_j, m_block_qubits, 2) + for i in range(start_i, n_qubits, m_block_qubits) + if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 ) - if m_block_qubits > 2: - ents.append( - kron( - _entangler( - control=support[i + j], - target=support[i + j + 1], - param_str=param_prefix + f"_ent_{next(iterator)}", - op=entangler, - ) - for i in range(-m_block_qubits // 2, n_qubits, m_block_qubits) - for j in range(1, m_block_qubits, 2) - if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 - ) - ) + for start_j in [0, 1] + ] ent_list.append(chain(*ents)) return ent_list From 433478b42efb67a05b1f6e99506c3deceb36e4dd Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Thu, 19 Sep 2024 15:18:14 +0000 Subject: [PATCH 10/11] 20240919.1 implemented suggestion of change --- qadence/constructors/ansatze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index 07dd644ab..434cde876 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -412,7 +412,7 @@ def _entanglers_block_digital( for i in range(start_i, n_qubits, m_block_qubits) if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 ) - for start_j in [0, 1] + for start_j in [i for i in range(2) if m_block_qubits>2 or i == 0] ] ent_list.append(chain(*ents)) From 370f616cff169eabb01394a6c50a6503c384e066 Mon Sep 17 00:00:00 2001 From: ducthanh1991 Date: Thu, 19 Sep 2024 15:20:27 +0000 Subject: [PATCH 11/11] forgot linting --- qadence/constructors/ansatze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qadence/constructors/ansatze.py b/qadence/constructors/ansatze.py index 434cde876..95cf6779f 100644 --- a/qadence/constructors/ansatze.py +++ b/qadence/constructors/ansatze.py @@ -412,7 +412,7 @@ def _entanglers_block_digital( for i in range(start_i, n_qubits, m_block_qubits) if i + j + 1 < n_qubits and j + 1 < m_block_qubits and i + j >= 0 ) - for start_j in [i for i in range(2) if m_block_qubits>2 or i == 0] + for start_j in [i for i in range(2) if m_block_qubits > 2 or i == 0] ] ent_list.append(chain(*ents))