Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter: update target construction #64

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions qiskit_braket_provider/providers/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def local_simulator_to_target(simulator: LocalSimulator) -> Target:
target for Qiskit backend
"""
target = Target()
target.add_instruction(Measure())

instructions = [
inst
Expand All @@ -192,17 +191,26 @@ def local_simulator_to_target(simulator: LocalSimulator) -> Target:
]
properties = simulator.properties
paradigm: GateModelSimulatorParadigmProperties = properties.paradigm

# add measurement instruction
target.add_instruction(Measure(), {(i,): None for i in range(paradigm.qubitCount)})

for instruction in instructions:
instruction_props: Optional[
Dict[Union[Tuple[int], Tuple[int, int]], Optional[InstructionProperties]]
] = {}

for src in range(paradigm.qubitCount):
for dst in range(paradigm.qubitCount):
if src != dst:
instruction_props[(src, dst)] = None
instruction_props[(dst, src)] = None
target.add_instruction(instruction, instruction_props)
if instruction.num_qubits == 1:
for i in range(paradigm.qubitCount):
instruction_props[(i,)] = None
target.add_instruction(instruction, instruction_props)
elif instruction.num_qubits == 2:
for src in range(paradigm.qubitCount):
for dst in range(paradigm.qubitCount):
if src != dst:
instruction_props[(src, dst)] = None
instruction_props[(dst, src)] = None
target.add_instruction(instruction, instruction_props)

return target

Expand All @@ -218,7 +226,6 @@ def aws_device_to_target(device: AwsDevice) -> Target:
"""
# building target
target = Target(description=f"Target for AWS Device: {device.name}")
target.add_instruction(Measure())

properties = device.properties
# gate model devices
Expand All @@ -232,13 +239,19 @@ def aws_device_to_target(device: AwsDevice) -> Target:
paradigm: GateModelQpuParadigmProperties = properties.paradigm
connectivity = paradigm.connectivity
instructions: List[QiskitInstruction] = []

for operation in action_properties.supportedOperations:
instruction = _op_to_instruction(operation)
if instruction is not None:
# TODO: remove when target will be supporting > 2 qubit gates # pylint:disable=fixme
if instruction.num_qubits <= 2:
instructions.append(instruction)

# add measurement instructions
target.add_instruction(
Measure(), {(i,): None for i in range(paradigm.qubitCount)}
)

for instruction in instructions:
instruction_props: Optional[
Dict[
Expand Down Expand Up @@ -276,12 +289,19 @@ def aws_device_to_target(device: AwsDevice) -> Target:
)
simulator_paradigm: GateModelSimulatorParadigmProperties = properties.paradigm
instructions = []

for operation in simulator_action_properties.supportedOperations:
instruction = _op_to_instruction(operation)
if instruction is not None:
# TODO: remove when target will be supporting > 2 qubit gates # pylint:disable=fixme
if instruction.num_qubits <= 2:
instructions.append(instruction)

# add measurement instructions
target.add_instruction(
Measure(), {(i,): None for i in range(simulator_paradigm.qubitCount)}
)

for instruction in instructions:
simulator_instruction_props: Optional[
Dict[
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/test_braket_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ def test_target(self):
target = aws_device_to_target(mock_device)
self.assertEqual(target.num_qubits, 30)
self.assertEqual(len(target.operations), 2)
self.assertEqual(len(target.instructions), 31)
self.assertEqual(len(target.instructions), 60)
self.assertIn("Target for AWS Device", target.description)