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

Format broadbean with ruff #811

Merged
merged 7 commits into from
Mar 6, 2024
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
17 changes: 0 additions & 17 deletions .github/workflows/darker.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.2.2'
rev: 'v0.3.0'
hooks:
# Run the linter
- id: ruff
types_or: [python, pyi, jupyter, toml]
args: [ --fix, --exit-non-zero-on-fix ]
# Run the formatter
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -18,7 +22,3 @@ repos:
- id: debug-statements
- id: mixed-line-ending
args: ['--fix=no']
- repo: https://github.com/akaihola/darker
rev: 1.7.2
hooks:
- id: darker
73 changes: 43 additions & 30 deletions docs/examples/Example_Write_Read_JSON.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"import broadbean as bb\n",
"from broadbean.plotting import plotter\n",
"\n",
"mpl.rcParams['figure.figsize'] = (8, 3)\n",
"mpl.rcParams['figure.subplot.bottom'] = 0.15 "
"mpl.rcParams[\"figure.figsize\"] = (8, 3)\n",
"mpl.rcParams[\"figure.subplot.bottom\"] = 0.15"
]
},
{
Expand Down Expand Up @@ -997,7 +997,7 @@
"bp_square = bb.BluePrint()\n",
"bp_square.setSR(1e9)\n",
"bp_square.insertSegment(0, ramp, (0, 0), dur=100e-9)\n",
"bp_square.insertSegment(1, ramp, (1e-3, 1e-3), name='top', dur=100e-9)\n",
"bp_square.insertSegment(1, ramp, (1e-3, 1e-3), name=\"top\", dur=100e-9)\n",
"bp_square.insertSegment(2, ramp, (0, 0), dur=100e-9)\n",
"bp_boxes = bp_square + bp_square\n",
"plotter(bp_boxes)"
Expand All @@ -1016,7 +1016,7 @@
"metadata": {},
"outputs": [],
"source": [
"bp_boxes.write_to_json('blue.json')"
"bp_boxes.write_to_json(\"blue.json\")"
]
},
{
Expand Down Expand Up @@ -1976,8 +1976,10 @@
}
],
"source": [
"bp_boxes_read = bb.BluePrint.init_from_json('blue.json')\n",
"bp_boxes_read.setSR(1e9) # note the blueprint readback do not have a sample rate attached\n",
"bp_boxes_read = bb.BluePrint.init_from_json(\"blue.json\")\n",
"bp_boxes_read.setSR(\n",
" 1e9\n",
") # note the blueprint readback do not have a sample rate attached\n",
"plotter(bp_boxes_read)"
]
},
Expand Down Expand Up @@ -2969,7 +2971,7 @@
"sine = bb.PulseAtoms.sine # args: freq, ampl, off, phase\n",
"seq1 = bb.Sequence()\n",
"\n",
"# We fill up the sequence by adding elements at different sequence positions. \n",
"# We fill up the sequence by adding elements at different sequence positions.\n",
"# A valid sequence is filled from 1 to N with NO HOLES, i.e. if position 4 is filled, so must be position 1, 2, and 3\n",
"\n",
"#\n",
Expand All @@ -2979,7 +2981,7 @@
"bp_square = bb.BluePrint()\n",
"bp_square.setSR(1e9)\n",
"bp_square.insertSegment(0, ramp, (0, 0), dur=100e-9)\n",
"bp_square.insertSegment(1, ramp, (1e-3, 1e-3), name='top', dur=100e-9)\n",
"bp_square.insertSegment(1, ramp, (1e-3, 1e-3), name=\"top\", dur=100e-9)\n",
"bp_square.insertSegment(2, ramp, (0, 0), dur=100e-9)\n",
"bp_boxes = bp_square + bp_square\n",
"#\n",
Expand All @@ -2988,10 +2990,14 @@
"bp_sine.insertSegment(0, sine, (3.333e6, 1.5e-3, 0, 0), dur=300e-9)\n",
"bp_sineandboxes = bp_sine + bp_square\n",
"\n",
"bp_sineandboxes.setSegmentMarker('ramp', (-0.0, 100e-9), 1) # segment name, (delay, duration), markerID\n",
"bp_sineandboxes.setSegmentMarker('sine', (-0.0, 100e-9), 2) # segment name, (delay, duration), markerID\n",
"bp_sineandboxes.setSegmentMarker(\n",
" \"ramp\", (-0.0, 100e-9), 1\n",
") # segment name, (delay, duration), markerID\n",
"bp_sineandboxes.setSegmentMarker(\n",
" \"sine\", (-0.0, 100e-9), 2\n",
") # segment name, (delay, duration), markerID\n",
"# make marker 2 go ON halfway through the sine\n",
"#bp_rtm.setSegmentMarker('mysine', (0.75, 0.1), 2)\n",
"# bp_rtm.setSegmentMarker('mysine', (0.75, 0.1), 2)\n",
"\n",
"\n",
"# create elements\n",
Expand Down Expand Up @@ -3958,7 +3964,7 @@
}
],
"source": [
"elem1.write_to_json('elem.json')\n",
"elem1.write_to_json(\"elem.json\")\n",
"plotter(elem1)"
]
},
Expand All @@ -3975,7 +3981,7 @@
"metadata": {},
"outputs": [],
"source": [
"elem_read = bb.Element.init_from_json('elem.json')"
"elem_read = bb.Element.init_from_json(\"elem.json\")"
]
},
{
Expand All @@ -3999,7 +4005,9 @@
}
],
"source": [
"print(elem1.description == elem_read.description) ## note that the elements are not identical only the discription"
"print(\n",
" elem1.description == elem_read.description\n",
") ## note that the elements are not identical only the discription"
]
},
{
Expand Down Expand Up @@ -4966,7 +4974,7 @@
"sine = bb.PulseAtoms.sine # args: freq, ampl, off, phase\n",
"seq1 = bb.Sequence()\n",
"\n",
"# We fill up the sequence by adding elements at different sequence positions. \n",
"# We fill up the sequence by adding elements at different sequence positions.\n",
"# A valid sequence is filled from 1 to N with NO HOLES, i.e. if position 4 is filled, so must be position 1, 2, and 3\n",
"\n",
"#\n",
Expand All @@ -4976,7 +4984,7 @@
"bp_square = bb.BluePrint()\n",
"bp_square.setSR(1e9)\n",
"bp_square.insertSegment(0, ramp, (0, 0), dur=100e-9)\n",
"bp_square.insertSegment(1, ramp, (1e-3, 1e-3), name='top', dur=100e-9)\n",
"bp_square.insertSegment(1, ramp, (1e-3, 1e-3), name=\"top\", dur=100e-9)\n",
"bp_square.insertSegment(2, ramp, (0, 0), dur=100e-9)\n",
"bp_boxes = bp_square + bp_square\n",
"#\n",
Expand All @@ -4985,10 +4993,14 @@
"bp_sine.insertSegment(0, sine, (3.333e6, 1.5e-3, 0, 0), dur=300e-9)\n",
"bp_sineandboxes = bp_sine + bp_square\n",
"\n",
"bp_sineandboxes.setSegmentMarker('ramp', (-0.0, 100e-9), 1) # segment name, (delay, duration), markerID\n",
"bp_sineandboxes.setSegmentMarker('sine', (-0.0, 100e-9), 2) # segment name, (delay, duration), markerID\n",
"bp_sineandboxes.setSegmentMarker(\n",
" \"ramp\", (-0.0, 100e-9), 1\n",
") # segment name, (delay, duration), markerID\n",
"bp_sineandboxes.setSegmentMarker(\n",
" \"sine\", (-0.0, 100e-9), 2\n",
") # segment name, (delay, duration), markerID\n",
"# make marker 2 go ON halfway through the sine\n",
"#bp_rtm.setSegmentMarker('mysine', (0.75, 0.1), 2)\n",
"# bp_rtm.setSegmentMarker('mysine', (0.75, 0.1), 2)\n",
"\n",
"\n",
"# create elements\n",
Expand All @@ -5011,7 +5023,7 @@
"seq1.setChannelAmplitude(1, 10e-3) # Call signature: channel, amplitude (peak-to-peak)\n",
"seq1.setChannelOffset(1, 0)\n",
"seq1.setChannelAmplitude(3, 10e-3)\n",
"seq1.setChannelOffset(3, 0) \n",
"seq1.setChannelOffset(3, 0)\n",
"\n",
"# Here we repeat each element twice and then proceed to the next, wrapping over at the end\n",
"seq1.setSequencingTriggerWait(1, 0)\n",
Expand Down Expand Up @@ -5044,8 +5056,7 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"seq1.write_to_json('testdata.json')"
"seq1.write_to_json(\"testdata.json\")"
]
},
{
Expand All @@ -5054,7 +5065,7 @@
"metadata": {},
"outputs": [],
"source": [
"bp_boxes.write_to_json('blue.json')"
"bp_boxes.write_to_json(\"blue.json\")"
]
},
{
Expand All @@ -5070,7 +5081,7 @@
"metadata": {},
"outputs": [],
"source": [
"seq = bb.Sequence.init_from_json('testdata.json')"
"seq = bb.Sequence.init_from_json(\"testdata.json\")"
]
},
{
Expand Down Expand Up @@ -6064,9 +6075,9 @@
"metadata": {},
"outputs": [],
"source": [
"def readblueprint(path:str,element:int = 1,channel:int = 1):\n",
" tempseq = bb.Sequence.init_from_json(path)\n",
" return tempseq.element(element)._data[channel]['blueprint']"
"def readblueprint(path: str, element: int = 1, channel: int = 1):\n",
" tempseq = bb.Sequence.init_from_json(path)\n",
" return tempseq.element(element)._data[channel][\"blueprint\"]"
]
},
{
Expand All @@ -6075,7 +6086,9 @@
"metadata": {},
"outputs": [],
"source": [
"def writeblueprint(blueprint, path:str,SR:float = 1e9,SeqAmp:float = 10e-3,SeqOffset:float = 0):# -> None\n",
"def writeblueprint(\n",
" blueprint, path: str, SR: float = 1e9, SeqAmp: float = 10e-3, SeqOffset: float = 0\n",
"): # -> None\n",
" if blueprint.SR is None:\n",
" blueprint.setSR(SR)\n",
" elemtmp = bb.Element()\n",
Expand All @@ -6094,7 +6107,7 @@
"metadata": {},
"outputs": [],
"source": [
"writeblueprint(bp_boxes,'boxes.json')"
"writeblueprint(bp_boxes, \"boxes.json\")"
]
},
{
Expand Down Expand Up @@ -7047,7 +7060,7 @@
}
],
"source": [
"bp_one_two = readblueprint('testdata.json',element=2,channel=1)\n",
"bp_one_two = readblueprint(\"testdata.json\", element=2, channel=1)\n",
"plotter(bp_one_two)"
]
},
Expand Down
Loading