Skip to content

Commit

Permalink
Backward compatibility with simple quantum arch (#117)
Browse files Browse the repository at this point in the history
* backward compatibility with simple quantum arch
* change log update
  • Loading branch information
kukushechkin authored Mar 8, 2024
1 parent 193e0f3 commit 689fbb3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 17.1
============

* Support both extended and simple quantum architecture specification. `#117 <https://github.com/iqm-finland/iqm-client/pull/117>`_

Version 17.0
============

Expand Down
12 changes: 12 additions & 0 deletions src/iqm/iqm_client/quantum_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ class QuantumArchitectureSpecification(BaseModel):
"""Qubit connectivity of this quantum architecture."""

def __init__(self, **data):
# Convert a simplified quantum architecture to full quantum architecture
raw_operations = data.get("operations")
raw_qubits = data.get("qubits")
raw_qubit_connectivity = data.get("qubit_connectivity")
if isinstance(raw_operations, list):
data["operations"] = {
get_current_instruction_name(op): raw_qubit_connectivity
if is_multi_qubit_instruction(get_current_instruction_name(op))
else [[qb] for qb in raw_qubits]
for op in raw_operations
}

super().__init__(**data)
self.operations = {get_current_instruction_name(k): v for k, v in self.operations.items()}

Expand Down
13 changes: 13 additions & 0 deletions tests/test_quantum_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,16 @@ def to_arch(operations):
qubit_connectivity=[['QB1', 'QB2'], ['QB2', 'QB3']],
operations=operations,
)


def test_simplified_quantum_architecture():
simplified_architecture = QuantumArchitectureSpecification(
name='hercules',
qubits=['QB1', 'QB2', 'QB3'],
qubit_connectivity=[['QB1', 'QB2'], ['QB2', 'QB3']],
operations=['prx', 'cz'],
)
assert simplified_architecture.operations == {
'prx': [['QB1'], ['QB2'], ['QB3']],
'cz': [['QB1', 'QB2'], ['QB2', 'QB3']],
}

0 comments on commit 689fbb3

Please sign in to comment.