Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import sys \n",
- "sys.path.append(r\"D:\\Code\\broadbean\")\n",
- "import broadbean as bb\n",
- "import numpy as np\n",
- "import re \n",
- "import functools\n",
- "import matplotlib.pyplot as plt\n",
- "import matplotlib as mpl\n",
- "mpl.rcParams['figure.figsize'] = (8, 3)\n",
- "mpl.rcParams['figure.subplot.bottom'] = 0.15 \n",
- "\n",
- "sys.path.append(r\"D:\\Code\\Qcodes\")\n",
- "import qcodes.instrument_drivers.tektronix.AWG5014 as awg \n",
- "from qcodes.instrument_drivers.tektronix.AWGFileParser import parse_awg_file \n",
- "\n",
- "from qcodes.instrument_drivers.AlazarTech.ATS9373 import AlazarTech_ATS9373\n",
- "from qcodes.instrument_drivers.AlazarTech.ATS import AcquisitionController"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Connected to: TEKTRONIX AWG5014C (serial:B051389, firmware:SCPI:99.0 FW:4.6.0.7) in 0.17s\n"
- ]
- }
- ],
- "source": [
- "awg = awg.Tektronix_AWG5014('AWG1', 'TCPIP0::145.94.39.154::inst0::INSTR', timeout=40)\n",
- "alazar = AlazarTech_ATS9373(\"alazar\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "```python\n",
- "player1 = sine(freq, ampl, phase, offset)\n",
- "player2 = sine(freq, ampl, phase + np.pi/2, offset)\n",
- "\n",
- "awg_controller.ch1 = player1\n",
- "awg_controller.ch2 = player2\n",
- "\n",
- "awg_controller.play()\n",
- "```"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "class AWGController:\n",
- " def __init__(self, awg): \n",
- " self._awg = awg \n",
- " self._channel_blueprints = {k: [] for k in range(awg.num_channels)}\n",
- " \n",
- " def __getattr__(self, att): \n",
- " match = re.match(\"ch(\\d)$\", att)\n",
- " if match is not None: \n",
- " chnum = int(match.groups()[0])\n",
- " return functools.partial(self._set_channel_blueprint, chnum)\n",
- " else:\n",
- " raise AttributeError(f\"AWGController has no attribute {att}\")\n",
- " \n",
- " def _set_channel_blueprint(self, chnum, blue_prints):\n",
- " self._channel_blueprints[chnum] = blue_prints\n",
- " \n",
- " def _compile_package(self): \n",
- " element = bb.Element()\n",
- " \n",
- " for chnum, blueprints in self._channel_blueprints.items():\n",
- " for blueprint in blueprints:\n",
- " element.addBluePrint(chnum, blueprint)\n",
- " \n",
- " sequence = bb.Sequence()\n",
- " sequence.addElement(1, element) \n",
- " sequence.setSR(element.SR)\n",
- " sequence.checkConsistency() \n",
- " \n",
- " for chnum in self._channel_blueprints.keys():\n",
- " sequence.setChannelAmplitude(chnum, 1) # We work in volts!\n",
- " sequence.setChannelOffset (chnum, 0)\n",
- " \n",
- " sequence.setSequenceSettings(1, 0, 1, 0, 1) # We want to loop the sequence\n",
- " package = sequence.outputForAWGFile()\n",
- " \n",
- " return package\n",
- " \n",
- " def _set_channel_states(self, value): \n",
- " \n",
- " for chnum, blueprints in self._channel_blueprints.items():\n",
- " if len(blueprints): \n",
- " ch_state = getattr(self._awg, f\"ch{chnum}_state\")\n",
- " ch_state(1)\n",
- " \n",
- " def play(self): \n",
- " package = self._compile_package()\n",
- " self._awg.delete_all_waveforms_from_list()\n",
- " self._awg.make_send_and_load_awg_file(*package[:])\n",
- " \n",
- " #self._set_channel_states(1)\n",
- " #awg.run()\n",
- " \n",
- " def stop(self):\n",
- " awg.stop()\n",
- " self._set_channel_states(0)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "def sine(freq, ampl, off, phase): \n",
- " \"\"\"\n",
- " Args: \n",
- " freq: in Hz \n",
- " ampl: In volt\n",
- " off: In Volt\n",
- " phase: In radians \n",
- " \"\"\"\n",
- " \n",
- " def sine_function(freq, ampl, off, phase, SR, npts):\n",
- " time = np.linspace(0, npts/SR, npts)\n",
- " return ampl * np.sin(2 * np.pi * freq * time + phase) + off\n",
- "\n",
- " bp_sine = bb.BluePrint()\n",
- " bp_sine.setSR(1e9)\n",
- " bp_sine.insertSegment(0, sine_function , (freq, ampl, off, phase), dur=300e-9)\n",
- " \n",
- " return [bp_sine]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "awg_controller = AWGController(awg)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "metadata": {},
- "outputs": [],
- "source": [
- "awg_controller.ch1(sine(3.333e6, 0.3, 0, 0))\n",
- "awg_controller.ch2(sine(2*3.333e6, 0.3, 0, np.pi/2))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 23,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "D:\\Code\\broadbean\\broadbean\\broadbean.py:1323: UserWarning: Deprecation warning. This function is only compatible with AWG5014 output and will be removed. Please use the specific setSequencingXXX methods.\n",
- " warnings.warn('Deprecation warning. This function is only compatible '\n",
- "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:11: DeprecationWarning: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.\n",
- " # This is added back by InteractiveShellApp.init_path()\n"
- ]
- }
- ],
- "source": [
- "awg_controller.play()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 48,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "AttributeError"
- ]
- },
- "execution_count": 48,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "AttributeError"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment