Skip to content

Commit

Permalink
Version 0.5.1
Browse files Browse the repository at this point in the history
Features:
* Use Void by default
* Update API due to multi-body support
  * Update DeltaGraph srting representation
  * Refactor TemplateNode

Tests:
* Extensive testing of wiring

Bugs:
* Makefile fix

Co-authored-by: Alex Moylett <alex.moylett@riverlane.com>
Co-authored-by: Kenton Barnes <72206848+KentonRL@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 15, 2021
1 parent 4dfb84c commit 0188433
Show file tree
Hide file tree
Showing 57 changed files with 3,228 additions and 1,485 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pycodestyle: container ## Run PEP8 checker


.PHONY: build-package
build-package: clean-package container ## Make the package
build-package: dev-clean container ## Make the package
${DEXEC} ${MAKEPACKAGE}
${DEXEC} ${CHECKPACKAGE}

Expand Down Expand Up @@ -273,7 +273,7 @@ dev-pycodestyle: ## See non-dev version
${PYCODESTYLE}

.PHONY: dev-build-package
dev-build-package: clean-package ## See non-dev version
dev-build-package: dev-clean ## See non-dev version
${MAKEPACKAGE}
${CHECKPACKAGE}

Expand All @@ -290,4 +290,4 @@ dev-test-package: ## See non-dev version
${TESTPACKAGE}

.PHONY: dev-clean
dev-clean: clean-cache clean-artifacts clean-docs## See non-dev version
dev-clean: clean-cache clean-artifacts clean-docs ## See non-dev version
2 changes: 1 addition & 1 deletion deltalanguage/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
__contributors_lines__ = "\n".join(contributors)
__email__ = "deltaflow@riverlane.com"

version_info = (0, 5, 0)
version_info = (0, 5, 1)
"""Tuple[int, int, int] : version information
The three components of the version:
``major``, ``minor`` and ``micro``: Module level variable documented inline.
Expand Down
6 changes: 6 additions & 0 deletions deltalanguage/data_types/_delta_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,12 @@ class DOptional:
def __init__(self, t: Union[Type, BaseDeltaType]):
self.type = as_delta_type(t)

def __eq__(self, other):
return isinstance(other, DOptional) and self.type == other.type

def __hash__(self):
return self.type.__hash__() + 1

@staticmethod
def as_python_type():
raise DeltaTypeError('DOptional is not a data type')
Expand Down
3 changes: 2 additions & 1 deletion deltalanguage/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
Opcode,
Shifts,
command_creator,
measurement_unpacker)
measurement_unpacker,
hal_template)
from deltalanguage.lib.primitives import (make_generator,
make_splitter,
StateSaver)
Expand Down
3 changes: 2 additions & 1 deletion deltalanguage/lib/hal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
measurement_unpacker,
Opcode,
Shifts)
from ._hardware_abstraction_layer_node import HardwareAbstractionLayerNode
from ._hardware_abstraction_layer_node import (HardwareAbstractionLayerNode,
hal_template)
11 changes: 8 additions & 3 deletions deltalanguage/lib/hal/_hardware_abstraction_layer_node.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from deltalanguage.data_types import DUInt, DSize
from deltalanguage.wiring import DeltaMethodBlock
from deltalanguage.wiring import DeltaMethodBlock, NodeTemplate

from ..quantum_simulators import IQuantumSimulator

hal_template = NodeTemplate(
name="QSim",
in_params={'hal_command': DUInt(DSize(32))},
out_type=DUInt(DSize(32))
)

class HardwareAbstractionLayerNode:
"""Encapsulates a node which receives HAL commands and uses them to
Expand All @@ -22,7 +27,7 @@ def __init__(
self._quantum_simulator = quantum_simulator

@DeltaMethodBlock(name="accept_command")
def accept_command(self, command: DUInt(DSize(32))) -> DUInt(DSize(32)):
def accept_command(self, hal_command: DUInt(DSize(32))) -> DUInt(DSize(32)):
"""Interface for ``quantum_simulator.accept_command`` that is used
to create a graph node.
Expand All @@ -36,6 +41,6 @@ def accept_command(self, command: DUInt(DSize(32))) -> DUInt(DSize(32)):
DUInt(DSize(32))
Result of a measurement command.
"""
result = self._quantum_simulator.accept_command(command)
result = self._quantum_simulator.accept_command(hal_command)

return result
4 changes: 2 additions & 2 deletions deltalanguage/lib/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
DeltaMethodBlock,
Interactive,
PythonNode,
InteractiveProcess)
InteractiveBodyTemplate)


def make_generator(val: Union[object, Iterable],
reps: int = None,
verbose: bool = False) -> InteractiveProcess:
verbose: bool = False) -> InteractiveBodyTemplate:
"""Used to create a generator node that
produces a series of messages of the same data type.
Expand Down
18 changes: 4 additions & 14 deletions deltalanguage/runtime/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
PyInteractiveBody,
PyMethodBody,
PythonNode,
RealNode,
TemplateBody)
RealNode)
from deltalanguage.logging import MessageLog, clear_loggers, make_logger

from ._queues import ConstQueue, DeltaQueue
Expand Down Expand Up @@ -310,14 +309,7 @@ def start(self):

try:
for node in self.graph.nodes:
if isinstance(node.body, TemplateBody):
if node.body.inner_body is None:
raise RuntimeError(
f"Must specify template body on node {node.name}"
)

if isinstance(node.body, self.run_once_body_cls) \
or (isinstance(node.body, TemplateBody) and node.is_const()):
if isinstance(node.body, self.run_once_body_cls):
node.run_once(self)

except DeltaRuntimeExit:
Expand All @@ -329,12 +321,10 @@ def start(self):
+ "Exiting simulator.") from exc

for node in self.graph.nodes:
if isinstance(node.body, self.run_once_body_cls) \
or (isinstance(node.body, TemplateBody) and node.is_const()):
if isinstance(node.body, self.run_once_body_cls):
continue

elif isinstance(node.body, self.running_body_cls) \
or (isinstance(node.body, TemplateBody) and not node.is_const()):
elif isinstance(node.body, self.running_body_cls):
self.log.info(f"Starting node {node.name}")
self.threads[node.name] = DeltaThread(
target=node.thread_worker,
Expand Down
15 changes: 6 additions & 9 deletions deltalanguage/wiring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
- Wiring routines:
:py:func:`placeholder_node_factory`
:py:func:`template_node_factory`
- Node classes
:py:class:`RealNode`
Expand All @@ -37,19 +36,18 @@
PyFuncBody,
PyInteractiveBody,
PyMethodBody,
PythonBody,
TemplateBody)
PyMigenBody,
PythonBody)
from ._node_classes.placeholder_node import PlaceholderNode
from ._node_classes.port_classes import InPort, OutPort
from ._node_classes.real_nodes import PythonNode, RealNode, as_node
from ._body_templates import InteractiveBodyTemplate
from ._node_templates import NodeTemplate
from ._decorators import (DeltaBlock,
DeltaMethodBlock,
Interactive,
InteractiveProcess)
Interactive)
from ._delta_graph import DeltaGraph
from ._node_factories import py_method_node_factory, py_node_factory
from ._placeholder_factory import placeholder_node_factory
from ._template_factory import template_node_factory


# user-facing classes
Expand All @@ -59,7 +57,6 @@
"DeltaGraph",
"RealNode",
"PythonNode",
"TemplateBody",
"MigenNodeTemplate",
"placeholder_node_factory",
"template_node_factory"]
"NodeTemplate"]

0 comments on commit 0188433

Please sign in to comment.