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

Remove parametric calibration workaround #915

Draft
wants to merge 66 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
59f71d2
add duration type to FreeParameterExpression
jcjaskula-aws Sep 8, 2023
ed3adce
consider FreeParameter as float
jcjaskula-aws Sep 8, 2023
9c4293c
move to_ast to FreeParameterExprsesion
jcjaskula-aws Sep 9, 2023
fc6aa3d
change back FPEIdentifier's parent to Identifier
jcjaskula-aws Sep 11, 2023
f7da115
clean up syntax
jcjaskula-aws Sep 11, 2023
6fb5bc2
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
speller26 Sep 11, 2023
a93090d
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Sep 14, 2023
ddeed36
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
math411 Sep 14, 2023
ede6a67
add precision about the expression type
jcjaskula-aws Sep 15, 2023
9bbf382
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
math411 Sep 15, 2023
cc5cdf3
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
math411 Sep 19, 2023
cebf58e
add __repr__ to waveforms
jcjaskula-aws Sep 28, 2023
c75ddd6
do not simplify constants with defcals
jcjaskula-aws Sep 29, 2023
0681956
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Sep 29, 2023
68afef4
add type validation
jcjaskula-aws Oct 4, 2023
06c451a
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Oct 5, 2023
b7313c0
update oqpy to 0.3.2
jcjaskula-aws Oct 5, 2023
ce30fee
fix linters
jcjaskula-aws Oct 5, 2023
a64971a
increase test coverage
jcjaskula-aws Oct 6, 2023
4c1103a
update to oqpy 0.3.3
jcjaskula-aws Oct 16, 2023
6f4e1be
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Oct 16, 2023
bba404e
fix last merge commit
jcjaskula-aws Oct 16, 2023
5093176
fix type hints
jcjaskula-aws Oct 16, 2023
1171069
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Nov 6, 2023
423a97c
update to oqpy 0.3.4
jcjaskula-aws Nov 6, 2023
8e53571
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Dec 11, 2023
9da40a6
fix oqpy to 0.3.3
jcjaskula-aws Dec 11, 2023
004de4a
declare FreeParameter as oqpy var
jcjaskula-aws Dec 6, 2023
3ae122e
declare free params before playing the waveform
jcjaskula-aws Dec 11, 2023
64c2187
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
kshitijc Dec 13, 2023
5c557a8
remove FreeParameterExpressionIdentitifer
jcjaskula-aws Dec 14, 2023
c6b6f40
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
ajberdy Dec 18, 2023
ec2a559
declare input parameters with pulse sequences
jcjaskula-aws Dec 19, 2023
7d7b24f
use machine-size types
jcjaskula-aws Dec 19, 2023
c21768e
create _InputVarSplitter
jcjaskula-aws Dec 19, 2023
e536d9f
remove never visited branch
jcjaskula-aws Dec 19, 2023
4c9710a
fix partial coverage
jcjaskula-aws Dec 19, 2023
d5c600f
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Dec 19, 2023
1bc972b
hacking test because the set order changes with python version
jcjaskula-aws Dec 19, 2023
ab492d9
pass inputs with PulseSequence
jcjaskula-aws Dec 19, 2023
e7bdac8
pass empty dict to OpenQasmProgram
jcjaskula-aws Dec 19, 2023
7dd824a
Merge branch 'main' into jcjaskula-aws/fix_oqpy_upgrade
jcjaskula-aws Dec 20, 2023
3b47b43
prepare release v1.65.0
Dec 21, 2023
3cf9a08
update development version to v1.65.1.dev0
Dec 21, 2023
d856996
fix: validate out circuits that contain only non-zero-qubit gates (#842)
jcjaskula-aws Dec 22, 2023
e96fad8
prepare release v1.65.1
Dec 25, 2023
eb4d1be
update development version to v1.65.2.dev0
Dec 25, 2023
6874b40
remove workaround
jcjaskula-aws Jan 6, 2024
020d6c1
Merge branch 'jcjaskula-aws/fix_parametric_pulse_sequence_ir' into jc…
jcjaskula-aws Jan 8, 2024
ea106d9
fix tests
jcjaskula-aws Jan 9, 2024
612f0db
Merge branch 'jcjaskula-aws/fix_oqpy_upgrade' into jcjaskula-aws/clea…
jcjaskula-aws Jan 27, 2024
9badd0c
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Feb 7, 2024
d0ba60d
fix merge
jcjaskula-aws Feb 7, 2024
3fc6296
do not declare FreeParameterExpression by default
jcjaskula-aws Feb 8, 2024
6047c86
add tests
jcjaskula-aws Feb 8, 2024
7592338
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Feb 8, 2024
9239685
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Feb 13, 2024
640f748
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Feb 26, 2024
1491e7e
fix merge
jcjaskula-aws Feb 26, 2024
a4a1e53
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Mar 18, 2024
3537955
fix tests
jcjaskula-aws Mar 18, 2024
8d286b2
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Mar 18, 2024
eeb87c3
create more robust test
jcjaskula-aws Mar 18, 2024
0bf9b22
fix docstring
jcjaskula-aws Mar 18, 2024
2900d67
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Mar 19, 2024
9ea4a07
Merge branch 'main' into jcjaskula-aws/clean_parametric_defcal_code
jcjaskula-aws Mar 24, 2024
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
89 changes: 4 additions & 85 deletions src/braket/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ def _validate_gate_calibrations_uniqueness(
frames: dict[str, Frame],
waveforms: dict[str, Waveform],
) -> None:
for _key, calibration in gate_definitions.items():
for calibration in gate_definitions.values():
for frame in calibration._frames.values():
_validate_uniqueness(frames, frame)
frames[frame.id] = frame
Expand All @@ -1264,7 +1264,7 @@ def _generate_frame_wf_defcal_declarations(
) -> str | None:
"""Generates the header where frames, waveforms and defcals are declared.

It also adds any FreeParameter of the calibrations to the circuit parameter set.
It also adds any FreeParameter that is not a gate argument to the circuit parameter set.

Args:
gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence] | None): The
Expand All @@ -1289,21 +1289,12 @@ def _generate_frame_wf_defcal_declarations(

for key, calibration in gate_definitions.items():
gate, qubits = key

# Ignoring parametric gates
# Corresponding defcals with fixed arguments have been added
# in _get_frames_waveforms_from_instrs
if isinstance(gate, Parameterizable) and any(
not isinstance(parameter, (float, int, complex))
for parameter in gate.parameters
):
continue

gate_name = gate._qasm_name
arguments = gate.parameters if isinstance(gate, Parameterizable) else []

for param in calibration.parameters:
self._parameters.add(param)
if param not in arguments:
self._parameters.add(param)
arguments = [
param._to_oqpy_expression() if isinstance(param, FreeParameter) else param
for param in arguments
Expand Down Expand Up @@ -1334,80 +1325,8 @@ def _get_frames_waveforms_from_instrs(
for waveform in instruction.operator.pulse_sequence._waveforms.values():
_validate_uniqueness(waveforms, waveform)
waveforms[waveform.id] = waveform
# this will change with full parametric calibration support
elif isinstance(instruction.operator, Parameterizable):
fixed_argument_calibrations = self._add_fixed_argument_calibrations(
gate_definitions, instruction
)
gate_definitions.update(fixed_argument_calibrations)
return frames, waveforms

def _add_fixed_argument_calibrations(
self,
gate_definitions: dict[tuple[Gate, QubitSet], PulseSequence],
instruction: Instruction,
) -> dict[tuple[Gate, QubitSet], PulseSequence]:
"""Adds calibrations with arguments set to the instruction parameter values

Given the collection of parameters in instruction.operator, this function looks for matching
parametric calibrations that have free parameters. If such a calibration is found and the
number N of its free parameters equals the number of instruction parameters, we can bind
the arguments of the calibration and add it to the calibration dictionary.

If N is smaller, it is probably impossible to assign the instruction parameter values to the
corresponding calibration parameters so we raise an error.
If N=0, we ignore it as it will not be removed by _generate_frame_wf_defcal_declarations.

Args:
gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence]): a dictionary of
calibrations
instruction (Instruction): a Circuit instruction

Returns:
dict[tuple[Gate, QubitSet], PulseSequence]: additional calibrations

Raises:
NotImplementedError: in two cases: (i) if the instruction contains unbound parameters
and the calibration dictionary contains a parametric calibration applicable to this
instructions; (ii) if the calibration is defined with a partial number of unbound
parameters.
"""
additional_calibrations = {}
for key, calibration in gate_definitions.items():
gate = key[0]
target = key[1]
if target != instruction.target:
continue
if isinstance(gate, type(instruction.operator)) and len(
instruction.operator.parameters
) == len(gate.parameters):
free_parameter_number = sum(
[isinstance(p, FreeParameterExpression) for p in gate.parameters]
)
if free_parameter_number == 0:
continue
elif free_parameter_number < len(gate.parameters):
raise NotImplementedError(
"Calibrations with a partial number of fixed parameters are not supported."
)
elif any(
isinstance(p, FreeParameterExpression) for p in instruction.operator.parameters
):
raise NotImplementedError(
"Parametric calibrations cannot be attached with parametric circuits."
)
bound_key = (
type(instruction.operator)(*instruction.operator.parameters),
instruction.target,
)
additional_calibrations[bound_key] = calibration(
**{
p.name if isinstance(p, FreeParameterExpression) else p: v
for p, v in zip(gate.parameters, instruction.operator.parameters)
}
)
return additional_calibrations

def to_unitary(self) -> np.ndarray:
"""Returns the unitary matrix representation of the entire circuit.

Expand Down
Loading